2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-24 20:20:36 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe WebHookUserSerializer do
|
2018-01-21 18:09:26 -05:00
|
|
|
let(:user) do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
SingleSignOnRecord.create!(user_id: user.id, external_id: '12345', last_payload: '')
|
|
|
|
user
|
|
|
|
end
|
2017-03-24 20:20:36 -04:00
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2017-03-24 20:20:36 -04:00
|
|
|
|
2018-01-21 18:09:26 -05:00
|
|
|
let :serializer do
|
|
|
|
WebHookUserSerializer.new(user, scope: Guardian.new(admin), root: false)
|
|
|
|
end
|
2017-03-24 20:20:36 -04:00
|
|
|
|
2018-01-21 18:09:26 -05:00
|
|
|
it "should include relevant user info" do
|
|
|
|
payload = serializer.as_json
|
2017-03-24 20:20:36 -04:00
|
|
|
expect(payload[:email]).to eq(user.email)
|
2018-01-21 18:09:26 -05:00
|
|
|
expect(payload[:external_id]).to eq('12345')
|
2017-03-24 20:20:36 -04:00
|
|
|
end
|
2018-05-20 23:25:01 -04:00
|
|
|
|
|
|
|
it 'should only include the required keys' do
|
|
|
|
count = serializer.as_json.keys.count
|
2021-01-20 11:31:52 -05:00
|
|
|
difference = count - 51
|
2018-05-20 23:25:01 -04:00
|
|
|
|
|
|
|
expect(difference).to eq(0), lambda {
|
2019-12-09 14:15:47 -05:00
|
|
|
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."
|
2018-05-20 23:25:01 -04:00
|
|
|
}
|
|
|
|
end
|
2017-03-24 20:20:36 -04:00
|
|
|
end
|