|
11 | 11 | [
|
12 | 12 | {
|
13 | 13 | username: 'student-to-create',
|
14 |
| - password: 'at-least-8-characters', |
| 14 | + password: 'SaoXlDBAyiAFoMH3VsddhdA7JWnM8P8by1wOjBUWH2g=', |
15 | 15 | name: 'School Student'
|
16 | 16 | },
|
17 | 17 | {
|
18 | 18 | username: 'second-student-to-create',
|
19 |
| - password: 'at-least-8-characters', |
| 19 | + password: 'SaoXlDBAyiAFoMH3VsddhdA7JWnM8P8by1wOjBUWH2g=', |
20 | 20 | name: 'School Student 2'
|
21 | 21 | }
|
22 | 22 | ]
|
23 | 23 | end
|
24 | 24 |
|
25 | 25 | before do
|
26 |
| - stub_profile_api_create_school_students(user_ids: [SecureRandom.uuid, SecureRandom.uuid]) |
27 |
| - |
28 | 26 | ActiveJob::Base.queue_adapter = :test
|
29 | 27 | end
|
30 | 28 |
|
31 |
| - it 'queues CreateStudentsJob' do |
32 |
| - expect do |
33 |
| - described_class.call(school:, school_students_params:, token:, user_id:) |
34 |
| - end.to have_enqueued_job(CreateStudentsJob).with(school_id: school.id, students: school_students_params, token:) |
| 29 | + context 'when queuing a job' do |
| 30 | + before do |
| 31 | + stub_profile_api_create_school_students(user_ids: [SecureRandom.uuid, SecureRandom.uuid]) |
| 32 | + end |
| 33 | + |
| 34 | + it 'queues CreateStudentsJob' do |
| 35 | + expect do |
| 36 | + described_class.call(school:, school_students_params:, token:, user_id:) |
| 37 | + end.to have_enqueued_job(CreateStudentsJob).with(school_id: school.id, students: school_students_params, token:) |
| 38 | + end |
35 | 39 | end
|
36 | 40 |
|
37 | 41 | context 'when a job has been queued' do
|
38 | 42 | before do
|
| 43 | + stub_profile_api_create_school_students(user_ids: [SecureRandom.uuid, SecureRandom.uuid]) |
39 | 44 | allow(CreateStudentsJob).to receive(:attempt_perform_later).and_return(
|
40 | 45 | instance_double(CreateStudentsJob, job_id: SecureRandom.uuid)
|
41 | 46 | )
|
|
52 | 57 | end
|
53 | 58 | end
|
54 | 59 |
|
55 |
| - context 'when validation fails' do |
| 60 | + context 'when a normal error occurs' do |
56 | 61 | let(:school_students_params) do
|
57 | 62 | [
|
58 | 63 | {
|
59 |
| - username: '', |
60 |
| - password: 'at-least-8-characters', |
| 64 | + username: 'a-student', |
| 65 | + password: 'Password', |
61 | 66 | name: 'School Student'
|
62 | 67 | },
|
63 | 68 | {
|
64 | 69 | username: 'second-student-to-create',
|
65 |
| - password: 'at-least-8-characters', |
| 70 | + password: 'Password', |
66 | 71 | name: 'School Student 2'
|
67 | 72 | }
|
68 | 73 | ]
|
69 | 74 | end
|
70 | 75 |
|
71 | 76 | before do
|
| 77 | + stub_profile_api_create_school_students(user_ids: [SecureRandom.uuid, SecureRandom.uuid]) |
72 | 78 | allow(Sentry).to receive(:capture_exception)
|
73 | 79 | end
|
74 | 80 |
|
|
85 | 91 |
|
86 | 92 | it 'returns the error message in the operation response' do
|
87 | 93 | response = described_class.call(school:, school_students_params:, token:, user_id:)
|
88 |
| - error_message = response[:error].message |
89 |
| - expect(error_message).to match(/Error creating student 1: username '' is invalid/) |
| 94 | + error_message = response[:error] |
| 95 | + expect(error_message).to match(/Error creating school students: Decryption failed: iv must be 16 bytes/) |
90 | 96 | end
|
91 | 97 |
|
92 | 98 | it 'sent the exception to Sentry' do
|
93 | 99 | described_class.call(school:, school_students_params:, token:, user_id:)
|
94 | 100 | expect(Sentry).to have_received(:capture_exception).with(kind_of(StandardError))
|
95 | 101 | end
|
96 | 102 | end
|
| 103 | + |
| 104 | + context 'when a validation error occurs' do |
| 105 | + before do |
| 106 | + stub_profile_api_create_school_students_validation_error |
| 107 | + end |
| 108 | + |
| 109 | + it 'returns the expected formatted errors' do |
| 110 | + response = described_class.call(school:, school_students_params:, token:, user_id:) |
| 111 | + expect(response[:error]).to eq( |
| 112 | + { 'student-to-create' => ['Username must be unique in the batch data', 'Password is too simple (it should not be easily guessable, <a href="https://my.raspberrypi.org/password-help">need password help?</a>)', 'You must supply a name'], 'another-student-to-create-2' => ['Password must be at least 8 characters', 'You must supply a name'] } |
| 113 | + ) |
| 114 | + end |
| 115 | + end |
97 | 116 | end
|
0 commit comments