|
10 | 10 | let(:organisation_id) { SecureRandom.uuid }
|
11 | 11 |
|
12 | 12 | describe '#verify' do
|
13 |
| - before do |
14 |
| - service.verify |
15 |
| - school.reload |
16 |
| - end |
| 13 | + describe 'when school can be saved' do |
| 14 | + it 'sets verified_at to a date' do |
| 15 | + service.verify |
| 16 | + expect(school.reload.verified_at).to be_a(ActiveSupport::TimeWithZone) |
| 17 | + end |
| 18 | + |
| 19 | + it 'grants the creator the owner role for the school' do |
| 20 | + service.verify |
| 21 | + expect(school_creator).to be_school_owner(school) |
| 22 | + end |
| 23 | + |
| 24 | + it 'grants the creator the teacher role for the school' do |
| 25 | + service.verify |
| 26 | + expect(school_creator).to be_school_teacher(school) |
| 27 | + end |
17 | 28 |
|
18 |
| - it 'sets verified_at to a date' do |
19 |
| - expect(school.verified_at).to be_a(ActiveSupport::TimeWithZone) |
| 29 | + it 'returns true' do |
| 30 | + expect(service.verify).to be(true) |
| 31 | + end |
20 | 32 | end
|
21 | 33 |
|
22 |
| - it 'grants the creator the owner role for the school' do |
23 |
| - expect(school_creator).to be_school_owner(school) |
| 34 | + describe 'when school cannot be saved' do |
| 35 | + before do |
| 36 | + school.update_attribute(:website, 'invalid') # rubocop:disable Rails/SkipsModelValidations |
| 37 | + end |
| 38 | + |
| 39 | + it 'does not set verified_at' do |
| 40 | + service.verify |
| 41 | + expect(school.reload.verified_at).to be_nil |
| 42 | + end |
| 43 | + |
| 44 | + it 'does not create owner role' do |
| 45 | + service.verify |
| 46 | + expect(school_creator).not_to be_school_owner(school) |
| 47 | + end |
| 48 | + |
| 49 | + it 'does not create teacher role' do |
| 50 | + service.verify |
| 51 | + expect(school_creator).not_to be_school_teacher(school) |
| 52 | + end |
| 53 | + |
| 54 | + it 'returns false' do |
| 55 | + expect(service.verify).to be(false) |
| 56 | + end |
24 | 57 | end
|
25 | 58 |
|
26 |
| - it 'grants the creator the teacher role for the school' do |
27 |
| - expect(school_creator).to be_school_teacher(school) |
| 59 | + describe 'when the school cannot be found' do |
| 60 | + before do |
| 61 | + allow(Sentry).to receive(:capture_exception) |
| 62 | + allow(School).to receive(:find).with(school.id).and_raise(ActiveRecord::RecordNotFound) |
| 63 | + service.verify |
| 64 | + end |
| 65 | + |
| 66 | + it 'reports the error in Sentry' do |
| 67 | + expect(Sentry).to have_received(:capture_exception) |
| 68 | + end |
28 | 69 | end
|
29 | 70 | end
|
30 | 71 |
|
|
0 commit comments