Skip to content

Commit df61688

Browse files
committed
1069: Ensure old coverage exists until feature flag removed
1 parent 8172e6e commit df61688

1 file changed

Lines changed: 163 additions & 22 deletions

File tree

spec/services/school_verification_service_spec.rb

Lines changed: 163 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,180 @@
88
let(:school_creator) { create(:user) }
99
let(:service) { described_class.new(school) }
1010

11-
around do |example|
12-
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
13-
example.run
14-
end
15-
end
16-
1711
describe '#verify' do
18-
describe 'when school can be saved' do
19-
it 'saves the school' do
20-
service.verify
21-
expect(school).to be_persisted
12+
describe 'when immediate onboarding is enabled' do
13+
# TODO: Remove this block once the feature flag is retired
14+
around do |example|
15+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: 'true') do
16+
example.run
17+
end
2218
end
2319

24-
it 'sets verified_at to a date' do
25-
service.verify
26-
expect(school.reload.verified_at).to be_a(ActiveSupport::TimeWithZone)
20+
describe 'when school can be saved' do
21+
it 'saves the school' do
22+
service.verify
23+
expect(school).to be_persisted
24+
end
25+
26+
it 'sets verified_at to a date' do
27+
service.verify
28+
expect(school.reload.verified_at).to be_a(ActiveSupport::TimeWithZone)
29+
end
30+
31+
it 'returns true' do
32+
expect(service.verify).to be(true)
33+
end
2734
end
2835

29-
it 'returns true' do
30-
expect(service.verify).to be(true)
36+
describe 'when school cannot be saved' do
37+
let(:website) { 'invalid' }
38+
39+
it 'does not save the school' do
40+
service.verify
41+
expect(school).not_to be_persisted
42+
end
43+
44+
it 'returns false' do
45+
expect(service.verify).to be(false)
46+
end
3147
end
3248
end
3349

34-
describe 'when school cannot be saved' do
35-
let(:website) { 'invalid' }
50+
# TODO: Remove these examples once the feature flag is retired
51+
describe 'when immediate onboarding is disabled' do
52+
let(:token) { 'token' }
3653

37-
it 'does not save the school' do
38-
service.verify
39-
expect(school).not_to be_persisted
54+
around do |example|
55+
ClimateControl.modify(ENABLE_IMMEDIATE_SCHOOL_ONBOARDING: nil) do
56+
example.run
57+
end
4058
end
4159

42-
it 'returns false' do
43-
expect(service.verify).to be(false)
60+
before do
61+
allow(ProfileApiClient).to receive(:create_school)
62+
end
63+
64+
describe 'when school can be saved' do
65+
it 'saves the school' do
66+
service.verify(token:)
67+
expect(school).to be_persisted
68+
end
69+
70+
it 'sets verified_at to a date' do
71+
service.verify(token:)
72+
expect(school.reload.verified_at).to be_a(ActiveSupport::TimeWithZone)
73+
end
74+
75+
it 'generates school code' do
76+
service.verify(token:)
77+
expect(school.reload.code).to be_present
78+
end
79+
80+
it 'grants the creator the owner role for the school' do
81+
service.verify(token:)
82+
expect(school_creator).to be_school_owner(school)
83+
end
84+
85+
it 'grants the creator the teacher role for the school' do
86+
service.verify(token:)
87+
expect(school_creator).to be_school_teacher(school)
88+
end
89+
90+
it 'creates the school in Profile API' do
91+
service.verify(token:)
92+
expect(ProfileApiClient).to have_received(:create_school).with(token:, id: school.id, code: school.code)
93+
end
94+
95+
it 'returns true' do
96+
expect(service.verify(token:)).to be(true)
97+
end
98+
end
99+
100+
describe 'when school cannot be saved' do
101+
let(:website) { 'invalid' }
102+
103+
it 'does not save the school' do
104+
service.verify(token:)
105+
expect(school).not_to be_persisted
106+
end
107+
108+
it 'does not create owner role' do
109+
service.verify(token:)
110+
expect(school_creator).not_to be_school_owner(school)
111+
end
112+
113+
it 'does not create teacher role' do
114+
service.verify(token:)
115+
expect(school_creator).not_to be_school_teacher(school)
116+
end
117+
118+
it 'does not create school in Profile API' do
119+
expect(ProfileApiClient).not_to have_received(:create_school)
120+
end
121+
122+
it 'returns false' do
123+
expect(service.verify(token:)).to be(false)
124+
end
125+
end
126+
127+
describe 'when the school cannot be created in Profile API' do
128+
before do
129+
allow(ProfileApiClient).to receive(:create_school).and_raise(RuntimeError)
130+
end
131+
132+
it 'does not save the school' do
133+
service.verify(token:)
134+
expect { school.reload }.to raise_error(ActiveRecord::RecordNotFound)
135+
end
136+
137+
it 'does not create owner role' do
138+
service.verify(token:)
139+
expect(school_creator).not_to be_school_owner(school)
140+
end
141+
142+
it 'does not create teacher role' do
143+
service.verify(token:)
144+
expect(school_creator).not_to be_school_teacher(school)
145+
end
146+
147+
it 'does not create school in Profile API' do
148+
expect(ProfileApiClient).not_to have_received(:create_school)
149+
end
150+
151+
it 'returns false' do
152+
expect(service.verify(token:)).to be(false)
153+
end
154+
end
155+
156+
describe 'when teacher and owner roles cannot be created because they already have a role in another school' do
157+
let(:another_school) { create(:school) }
158+
159+
before do
160+
create(:role, user_id: school.creator_id, school: another_school)
161+
end
162+
163+
it 'does not save the school' do
164+
service.verify(token:)
165+
expect { school.reload }.to raise_error(ActiveRecord::RecordNotFound)
166+
end
167+
168+
it 'does not create owner role' do
169+
service.verify(token:)
170+
expect(school_creator).not_to be_school_owner(school)
171+
end
172+
173+
it 'does not create teacher role' do
174+
service.verify(token:)
175+
expect(school_creator).not_to be_school_teacher(school)
176+
end
177+
178+
it 'does not create school in Profile API' do
179+
expect(ProfileApiClient).not_to have_received(:create_school)
180+
end
181+
182+
it 'returns false' do
183+
expect(service.verify(token:)).to be(false)
184+
end
44185
end
45186
end
46187
end

0 commit comments

Comments
 (0)