Allow setting only one date, assumed to be first=last date

pull/9730/head
Oliver Günther 3 years ago
parent 169e9c71c8
commit 42b314bb97
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      lib/api/v3/user_preferences/user_preference_representer.rb
  2. 54
      spec/lib/api/v3/user_preferences/user_preference_representer_parsing_spec.rb

@ -86,6 +86,10 @@ module API
end,
setter: ->(fragment:, **) do
self.pause_reminders = fragment.transform_keys(&:underscore)
if pause_reminders['last_day'].blank? && pause_reminders['first_day']
pause_reminders['last_day'] = pause_reminders['first_day']
end
end
property :workdays

@ -96,4 +96,58 @@ describe ::API::V3::UserPreferences::UserPreferenceRepresenter,
})
end
end
describe 'pause_reminders' do
let(:request_body) do
{
"pauseReminders" => {
"enabled" => true,
"firstDay" => first_day,
"lastDay" => last_day
}
}
end
context 'with all set' do
let(:first_day) { '2021-10-10' }
let(:last_day) { '2021-10-20' }
it 'sets both dates' do
expect(parsed.pause_reminders)
.to eql({
"enabled" => true,
"first_day" => first_day,
"last_day" => last_day
})
end
end
context 'with first only set' do
let(:first_day) { '2021-10-10' }
let(:last_day) { nil }
it 'uses the first day for the last day' do
expect(parsed.pause_reminders)
.to eql({
"enabled" => true,
"first_day" => first_day,
"last_day" => first_day
})
end
end
context 'with last only set' do
let(:first_day) { nil }
let(:last_day) { '2021-10-10' }
it 'uses the first day for the last day' do
expect(parsed.pause_reminders)
.to eql({
"enabled" => true,
"first_day" => nil,
"last_day" => last_day
})
end
end
end
end

Loading…
Cancel
Save