|
8 | 8 | name: 'Test School', |
9 | 9 | website: 'http://www.example.com', |
10 | 10 | address_line_1: 'Address Line 1', |
| 11 | + administrative_area: 'Greater London', |
11 | 12 | municipality: 'Greater London', |
| 13 | + postal_code: 'SW1A 1AA', |
12 | 14 | country_code: 'GB', |
13 | 15 | reference: '100000', |
14 | 16 | creator_agree_authority: true, |
|
21 | 23 | let(:token) { UserProfileMock::TOKEN } |
22 | 24 | let(:creator_id) { SecureRandom.uuid } |
23 | 25 |
|
| 26 | + before do |
| 27 | + allow(ProfileApiClient).to receive(:create_school).and_return(true) |
| 28 | + end |
| 29 | + |
24 | 30 | it 'returns a successful operation response' do |
25 | | - response = described_class.call(school_params:, creator_id:) |
| 31 | + response = described_class.call(school_params:, creator_id:, token:) |
26 | 32 | expect(response.success?).to be(true) |
27 | 33 | end |
28 | 34 |
|
29 | 35 | it 'creates a school' do |
30 | | - expect { described_class.call(school_params:, creator_id:) }.to change(School, :count).by(1) |
| 36 | + expect { described_class.call(school_params:, creator_id:, token:) }.to change(School, :count).by(1) |
31 | 37 | end |
32 | 38 |
|
33 | 39 | it 'returns the school in the operation response' do |
34 | | - response = described_class.call(school_params:, creator_id:) |
| 40 | + response = described_class.call(school_params:, creator_id:, token:) |
35 | 41 | expect(response[:school]).to be_a(School) |
36 | 42 | end |
37 | 43 |
|
38 | 44 | it 'assigns the name' do |
39 | | - response = described_class.call(school_params:, creator_id:) |
| 45 | + response = described_class.call(school_params:, creator_id:, token:) |
40 | 46 | expect(response[:school].name).to eq('Test School') |
41 | 47 | end |
42 | 48 |
|
43 | 49 | it 'assigns the creator_id' do |
44 | | - response = described_class.call(school_params:, creator_id:) |
| 50 | + response = described_class.call(school_params:, creator_id:, token:) |
45 | 51 | expect(response[:school].creator_id).to eq(creator_id) |
46 | 52 | end |
47 | 53 |
|
|
53 | 59 | end |
54 | 60 |
|
55 | 61 | it 'does not create a school' do |
56 | | - expect { described_class.call(school_params:, creator_id:) }.not_to change(School, :count) |
| 62 | + expect { described_class.call(school_params:, creator_id:, token:) }.not_to change(School, :count) |
57 | 63 | end |
58 | 64 |
|
59 | 65 | it 'returns a failed operation response' do |
60 | | - response = described_class.call(school_params:, creator_id:) |
| 66 | + response = described_class.call(school_params:, creator_id:, token:) |
61 | 67 | expect(response.failure?).to be(true) |
62 | 68 | end |
63 | 69 |
|
64 | 70 | it 'returns the correct number of objects in the operation response' do |
65 | | - response = described_class.call(school_params:, creator_id:) |
66 | | - expect(response[:error].count).to eq(9) |
| 71 | + response = described_class.call(school_params:, creator_id:, token:) |
| 72 | + expect(response[:error].count).to eq(11) |
67 | 73 | end |
68 | 74 |
|
69 | 75 | it 'returns the correct type of object in the operation response' do |
70 | | - response = described_class.call(school_params:, creator_id:) |
| 76 | + response = described_class.call(school_params:, creator_id:, token:) |
71 | 77 | expect(response[:error].first).to be_a(ActiveModel::Error) |
72 | 78 | end |
73 | 79 |
|
74 | 80 | it 'sent the exception to Sentry' do |
75 | | - described_class.call(school_params:, creator_id:) |
| 81 | + described_class.call(school_params:, creator_id:, token:) |
76 | 82 | expect(Sentry).to have_received(:capture_exception).with(kind_of(StandardError)) |
77 | 83 | end |
78 | 84 | end |
| 85 | + |
| 86 | + describe 'when immediate onboarding is enabled' do |
| 87 | + # TODO: Remove this block once the feature flag is retired |
| 88 | + around do |example| |
| 89 | + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do |
| 90 | + example.run |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + let(:onboarding_service) { instance_spy(SchoolOnboardingService, onboard: true) } |
| 95 | + |
| 96 | + before do |
| 97 | + allow(SchoolOnboardingService).to receive(:new).and_return(onboarding_service) |
| 98 | + end |
| 99 | + |
| 100 | + it 'calls the onboarding service' do |
| 101 | + described_class.call(school_params:, creator_id:, token:) |
| 102 | + expect(onboarding_service).to have_received(:onboard).with(token:) |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + # TODO: Remove these examples once the feature flag is retired |
| 107 | + describe 'when immediate onboarding is disabled' do |
| 108 | + around do |example| |
| 109 | + ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: nil) do |
| 110 | + example.run |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + let(:onboarding_service) { instance_spy(SchoolOnboardingService) } |
| 115 | + |
| 116 | + before do |
| 117 | + allow(SchoolOnboardingService).to receive(:new).and_return(onboarding_service) |
| 118 | + end |
| 119 | + |
| 120 | + it 'does not call the onboarding service' do |
| 121 | + described_class.call(school_params:, creator_id:, token:) |
| 122 | + expect(onboarding_service).not_to have_received(:onboard) |
| 123 | + end |
| 124 | + end |
79 | 125 | end |
0 commit comments