|
205 | 205 | )
|
206 | 206 | end
|
207 | 207 | end
|
| 208 | + |
| 209 | + describe 'DELETE /organizations/:organization_id/users/:id' do |
| 210 | + it 'renders 401 if organization does not exist' do |
| 211 | + set_auth_header(chidi) |
| 212 | + delete :destroy, params: { organization_id: 123, id: chidi.id } |
| 213 | + |
| 214 | + expect(response).to have_http_status(401) |
| 215 | + end |
| 216 | + |
| 217 | + it 'renders 401 if user does not exist' do |
| 218 | + set_auth_header(chidi) |
| 219 | + delete :destroy, params: { organization_id: good_place, id: 123 } |
| 220 | + |
| 221 | + expect(response).to have_http_status(401) |
| 222 | + end |
| 223 | + |
| 224 | + it 'renders 401 if requested user is not member of organization' do |
| 225 | + shawn = User.find_by!(first_name: 'Shawn') |
| 226 | + set_auth_header(chidi) |
| 227 | + delete :destroy, params: { organization_id: good_place, id: shawn.id } |
| 228 | + |
| 229 | + expect(response).to have_http_status(401) |
| 230 | + end |
| 231 | + |
| 232 | + it 'renders 200 with removed organization user' do |
| 233 | + set_auth_header(chidi) |
| 234 | + delete :destroy, params: { organization_id: good_place.id, id: chidi.id } |
| 235 | + |
| 236 | + expect(response).to have_http_status(200) |
| 237 | + expect(JSON.parse(response.body).keys).to contain_exactly(*user_fields) |
| 238 | + expect(JSON.parse(response.body)).to match( |
| 239 | + a_hash_including( |
| 240 | + 'id' => chidi.id, |
| 241 | + 'created_at' => chidi.created_at.iso8601(3), |
| 242 | + 'updated_at' => chidi.updated_at.iso8601(3), |
| 243 | + 'email' => chidi.email, |
| 244 | + 'first_name' => chidi.first_name, |
| 245 | + 'last_name' => chidi.last_name |
| 246 | + ) |
| 247 | + ) |
| 248 | + end |
| 249 | + |
| 250 | + it 'removes user from organization' do |
| 251 | + organization_user = OrganizationUser.find_by!(user_id: chidi.id, organization_id: good_place.id) |
| 252 | + |
| 253 | + set_auth_header(chidi) |
| 254 | + delete :destroy, params: { organization_id: good_place.id, id: chidi.id } |
| 255 | + |
| 256 | + expect do |
| 257 | + OrganizationUser.find(organization_user.id) |
| 258 | + end.to raise_error(ActiveRecord::RecordNotFound) |
| 259 | + end |
| 260 | + end |
208 | 261 | end
|
0 commit comments