|
98 | 98 | end
|
99 | 99 | end
|
100 | 100 |
|
101 |
| - context 'when user already has teacher role for the same school' do |
102 |
| - before do |
103 |
| - Role.teacher.create!(user_id: user.id, school:) |
104 |
| - end |
105 |
| - |
106 |
| - it 'responds 422 Unprocessable entity' do |
107 |
| - put("/api/teacher_invitations/#{token}/accept", headers:) |
108 |
| - |
109 |
| - expect(response).to have_http_status(:unprocessable_entity) |
110 |
| - end |
111 |
| - |
112 |
| - it 'leaves the user with the teacher role for that school' do |
113 |
| - put("/api/teacher_invitations/#{token}/accept", headers:) |
114 |
| - |
115 |
| - expect(user).to be_school_teacher(school) |
116 |
| - end |
117 |
| - |
118 |
| - it 'includes validation errors in response' do |
119 |
| - put("/api/teacher_invitations/#{token}/accept", headers:) |
120 |
| - |
121 |
| - json = JSON.parse(response.body) |
122 |
| - expect(json['error']).to eq({ 'role' => ['has already been taken'] }) |
123 |
| - end |
124 |
| - |
125 |
| - it 'does not set the accepted_at timestamp on the invitation' do |
126 |
| - freeze_time(with_usec: false) do |
127 |
| - put("/api/teacher_invitations/#{token}/accept", headers:) |
128 |
| - |
129 |
| - expect(invitation.reload.accepted_at).to be_blank |
130 |
| - end |
131 |
| - end |
132 |
| - end |
133 |
| - |
134 | 101 | context 'when user already has a role for another school' do
|
135 | 102 | let(:another_shool) { create(:school) }
|
136 | 103 |
|
|
208 | 175 | end
|
209 | 176 | end
|
210 | 177 |
|
| 178 | + context 'when user already has teacher role for the same school' do |
| 179 | + before do |
| 180 | + Role.teacher.create!(user_id: user.id, school:) |
| 181 | + end |
| 182 | + |
| 183 | + it 'responds 200 OK' do |
| 184 | + put("/api/teacher_invitations/#{token}/accept", headers:) |
| 185 | + |
| 186 | + expect(response).to have_http_status(:ok) |
| 187 | + end |
| 188 | + |
| 189 | + it 'leaves the user with the teacher role for that school' do |
| 190 | + put("/api/teacher_invitations/#{token}/accept", headers:) |
| 191 | + |
| 192 | + expect(user).to be_school_teacher(school) |
| 193 | + end |
| 194 | + |
| 195 | + it 'sets the accepted_at timestamp on the invitation' do |
| 196 | + freeze_time(with_usec: false) do |
| 197 | + put("/api/teacher_invitations/#{token}/accept", headers:) |
| 198 | + |
| 199 | + expect(invitation.reload.accepted_at).to eq(Time.current) |
| 200 | + end |
| 201 | + end |
| 202 | + end |
| 203 | + |
211 | 204 | context 'when user already has owner role for the same school' do
|
212 | 205 | before do
|
213 | 206 | Role.owner.create!(user_id: user.id, school:)
|
|
0 commit comments