-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update specs and remove debugging code
- Loading branch information
1 parent
32eefd2
commit 30d823d
Showing
6 changed files
with
124 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ def ukprn | |
end | ||
|
||
def users | ||
@users ||= response | ||
@users ||= response&.fetch('users', nil) | ||
end | ||
|
||
private | ||
|
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
76 changes: 76 additions & 0 deletions
76
spec/services/schools/dfe_sign_in_api/organisation_users_spec.rb
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require 'rails_helper' | ||
require Rails.root.join("spec", "controllers", "schools", "session_context") | ||
|
||
describe Schools::DFESignInAPI::OrganisationUsers do | ||
let(:user_uuid) { '123456' } | ||
let(:current_school_urn) { '987654' } | ||
let(:ukprn) { 'organisation-ukprn-id' } | ||
let(:response) do | ||
{ | ||
'ukprn' => ukprn, | ||
'users' => [ | ||
{ | ||
'email' => '[email protected]', | ||
'firstName' => 'user1', | ||
'lastName' => 'test', | ||
'userStatus' => 1, | ||
'roles' => ['role1'] | ||
}, | ||
{ | ||
'email' => '[email protected]', | ||
'firstName' => 'user2', | ||
'lastName' => 'test', | ||
'roles' => ['role1', 'role2'] | ||
} | ||
] | ||
} | ||
end | ||
|
||
subject { described_class.new(user_uuid, current_school_urn) } | ||
|
||
before do | ||
allow(subject).to receive(:response).and_return(response) | ||
allow_any_instance_of(Schools::DFESignInAPI::Organisation).to receive(:current_organisation_ukprn).and_return(ukprn) | ||
end | ||
|
||
describe '#initialize' do | ||
it 'sets user_uuid' do | ||
expect(subject.user_uuid).to eq(user_uuid) | ||
end | ||
|
||
it 'sets current_school_urn' do | ||
expect(subject.current_school_urn).to eq(current_school_urn) | ||
end | ||
end | ||
|
||
describe '#ukprn' do | ||
it 'calls current_organisation_ukprn on Organisation' do | ||
expect_any_instance_of(Schools::DFESignInAPI::Organisation).to receive(:current_organisation_ukprn).and_return(ukprn) | ||
expect(subject.ukprn).to eq(ukprn) | ||
end | ||
end | ||
|
||
describe '#users' do | ||
context 'when valid response is received' do | ||
it 'returns the users from the response' do | ||
expect(subject.users).to eq(response['users']) | ||
end | ||
end | ||
|
||
context 'when response is nil' do | ||
let(:response) { nil } | ||
|
||
it 'returns nil' do | ||
expect(subject.users).to be_nil | ||
end | ||
end | ||
|
||
context 'when response does not contain users' do | ||
let(:response) { { 'ukprn' => ukprn } } | ||
|
||
it 'returns an empty array' do | ||
expect(subject.users).to eq(nil) | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'rails_helper' | ||
require Rails.root.join("spec", "controllers", "schools", "session_context") | ||
|
||
describe Schools::DFESignInAPI::UserInvite, type: :model do | ||
let(:user_invite) { described_class.new } | ||
|
||
describe 'attributes' do | ||
it { is_expected.to respond_to(:email) } | ||
it { is_expected.to respond_to(:firstname) } | ||
it { is_expected.to respond_to(:lastname) } | ||
it { is_expected.to respond_to(:organisation_id) } | ||
end | ||
|
||
describe 'validations' do | ||
it { is_expected.to validate_presence_of(:firstname) } | ||
it { is_expected.to validate_presence_of(:lastname) } | ||
it { is_expected.to validate_presence_of(:email) } | ||
it { is_expected.to validate_length_of(:firstname).is_at_most(50) } | ||
it { is_expected.to validate_length_of(:lastname).is_at_most(50) } | ||
it { is_expected.to validate_length_of(:email).is_at_most(100) } | ||
it { is_expected.to allow_value('[email protected]').for(:email) } | ||
it { is_expected.not_to allow_value('invalid_email').for(:email) } | ||
it { is_expected.to validate_presence_of(:organisation_id) } | ||
end | ||
|
||
describe '#create' do | ||
context 'when API is enabled' do | ||
it 'makes a POST request to the API endpoint' do | ||
expect(user_invite).to receive(:response) | ||
user_invite.create | ||
end | ||
end | ||
|
||
context 'when API is disabled' do | ||
before { allow(user_invite).to receive(:enabled?).and_return(false) } | ||
|
||
it 'raises an ApiDisabled error' do | ||
expect { user_invite.create }.to raise_error(Schools::DFESignInAPI::UserInvite::ApiDisabled) | ||
end | ||
end | ||
end | ||
end |