Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alihadimazeh committed Aug 12, 2024
1 parent 51f520d commit ddcc607
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions spec/controllers/external_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,40 +212,52 @@
email: '[email protected]')
end

it 'overwrites the saved values with the values from the authentication provider if true' do
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true)
context 'value is true' do
before do
reg_method = instance_double(SettingGetter)
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method)
allow(reg_method).to receive(:call).and_return(true)
end

request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]
it 'overwrites the saved values with the values from the authentication provider if true' do
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]

get :create_user, params: { provider: 'openid_connect' }
get :create_user, params: { provider: 'openid_connect' }

user.reload
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name'])
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email'])
end
user.reload
expect(user.name).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['name'])
expect(user.email).to eq(OmniAuth.config.mock_auth[:openid_connect]['info']['email'])
end

it 'does not overwrite the saved values with the values from the authentication provider if false' do
allow_any_instance_of(SettingGetter).to receive(:call).and_return(false)
it 'does not overwrite the role even if true' do
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true)
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]

request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]
new_role = create(:role)
user.update(role: new_role)

get :create_user, params: { provider: 'openid_connect' }
get :create_user, params: { provider: 'openid_connect' }

user.reload
expect(user.name).to eq('Example Name')
expect(user.email).to eq('[email protected]')
expect(user.reload.role).to eq(new_role)
end
end

it 'does not overwrite the role even if true' do
allow_any_instance_of(SettingGetter).to receive(:call).and_return(true)
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]
context 'value is false' do
before do
reg_method = instance_double(SettingGetter)
allow(SettingGetter).to receive(:new).with(setting_name: 'ResyncOnLogin', provider: 'greenlight').and_return(reg_method)
allow(reg_method).to receive(:call).and_return(false)
end

new_role = create(:role)
user.update(role: new_role)
it 'does not overwrite the saved values with the values from the authentication provider if false' do
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:openid_connect]

get :create_user, params: { provider: 'openid_connect' }
get :create_user, params: { provider: 'openid_connect' }

expect(user.reload.role).to eq(new_role)
user.reload
expect(user.name).to eq('Example Name')
expect(user.email).to eq('[email protected]')
end
end
end

Expand Down

0 comments on commit ddcc607

Please sign in to comment.