-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform extended status group validation for NBP sign-up
For all users signing up through the NBP wallet, we want to validate their role. Only those registrations providing a specific role (learner / educator) should be allowed. Any other registrations should not be affected by this change.
- Loading branch information
Showing
7 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,67 @@ | |
expect(user).to be_valid | ||
end | ||
end | ||
|
||
context 'when creating a new user' do | ||
let(:user_info) { {first_name: 'John', last_name: 'Oliver', email: '[email protected]', status_group:} } | ||
|
||
shared_examples 'a valid user' do |group| | ||
let(:status_group) { group } | ||
|
||
it 'is valid' do | ||
Check failure on line 109 in spec/models/user_spec.rb
|
||
expect(user).to be_valid | ||
end | ||
end | ||
|
||
shared_examples 'an invalid user' do |group| | ||
let(:status_group) { group } | ||
|
||
it 'is not valid' do | ||
Check failure on line 117 in spec/models/user_spec.rb
|
||
expect(user).not_to be_valid | ||
end | ||
|
||
it 'adds an error for status_group' do | ||
Check failure on line 121 in spec/models/user_spec.rb
|
||
user.valid? | ||
expect(user.errors[:status_group]).to include(I18n.t('activerecord.errors.models.user.attributes.status_group.unrecognized_role')) | ||
end | ||
end | ||
|
||
context 'when using #new' do | ||
subject(:user) { described_class.new(user_info.merge(password:)) } | ||
|
||
let(:password) { 'password' } | ||
|
||
it_behaves_like 'a valid user', :unknown | ||
it_behaves_like 'a valid user', :learner | ||
it_behaves_like 'a valid user', :educator | ||
it_behaves_like 'a valid user', :other | ||
end | ||
|
||
context 'when using #new_from_omniauth' do | ||
subject(:user) { described_class.new_from_omniauth(user_info, provider, provider_uid) } | ||
|
||
let(:provider_uid) { '12345' } | ||
|
||
context 'when registered through NBP' do | ||
let(:provider) { 'nbp' } | ||
|
||
it_behaves_like 'a valid user', :learner | ||
it_behaves_like 'a valid user', :educator | ||
|
||
it_behaves_like 'an invalid user', :unknown | ||
it_behaves_like 'an invalid user', :other | ||
end | ||
|
||
context 'when registering through BIRD' do | ||
let(:provider) { 'bird' } | ||
|
||
it_behaves_like 'a valid user', :unknown | ||
it_behaves_like 'a valid user', :learner | ||
it_behaves_like 'a valid user', :educator | ||
it_behaves_like 'a valid user', :other | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#destroy' do | ||
|