discourse/spec/serializers/web_hook_user_serializer_spec.rb
Mark VanLandingham 1a7922bea2
FEATURE: Create notification schedule to automatically set do not disturb time (#11665)
This adds a new table UserNotificationSchedules which stores monday-friday start and ends times that each user would like to receive notifications (with a Boolean enabled to remove the use of the schedule). There is then a background job that runs every day and creates do_not_disturb_timings for each user with an enabled notification schedule. The job schedules timings 2 days in advance. The job is designed so that it can be run at any point in time, and it will not create duplicate records.

When a users saves their notification schedule, the schedule processing service will run and schedule do_not_disturb_timings. If the user should be in DND due to their schedule, the user will immediately be put in DND (message bus publishes this state).

The UI for a user's notification schedule is in user -> preferences -> notifications. By default every day is 8am - 5pm when first enabled.
2021-01-20 10:31:52 -06:00

36 lines
1.0 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe WebHookUserSerializer do
let(:user) do
user = Fabricate(:user)
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
user
end
fab!(:admin) { Fabricate(:admin) }
let :serializer do
WebHookUserSerializer.new(user, scope: Guardian.new(admin), root: false)
end
it "should include relevant user info" do
payload = serializer.as_json
expect(payload[:email]).to eq(user.email)
expect(payload[:external_id]).to eq('12345')
end
it 'should only include the required keys' do
count = serializer.as_json.keys.count
difference = count - 51
expect(difference).to eq(0), lambda {
message = (difference < 0 ?
"#{difference * -1} key(s) have been removed from this serializer." :
"#{difference} key(s) have been added to this serializer.") +
"\nPlease verify if those key(s) are required as part of the web hook's payload."
}
end
end