|
| 1 | +import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js'; |
1 | 2 | import { userAdminController } from '../../../../../src/identity-access-management/application/user/user.admin.controller.js';
|
2 | 3 | import { QUERY_TYPES } from '../../../../../src/identity-access-management/domain/constants/user-query.js';
|
3 | 4 | import { User } from '../../../../../src/identity-access-management/domain/models/User.js';
|
4 | 5 | import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
|
5 | 6 | import { DomainTransaction } from '../../../../../src/shared/domain/DomainTransaction.js';
|
6 |
| -import { expect, hFake, sinon } from '../../../../test-helper.js'; |
| 7 | +import { UserNotAuthorizedToRemoveAuthenticationMethod } from '../../../../../src/shared/domain/errors.js'; |
| 8 | +import { catchErr, expect, hFake, sinon } from '../../../../test-helper.js'; |
7 | 9 |
|
8 | 10 | describe('Unit | Identity Access Management | Application | Controller | Admin | User', function () {
|
9 | 11 | describe('#findPaginatedFilteredUsers', function () {
|
@@ -238,4 +240,46 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |
|
238 | 240 | expect(response.source).to.deep.equal(anonymizedUserSerialized);
|
239 | 241 | });
|
240 | 242 | });
|
| 243 | + |
| 244 | + describe('#removeAuthenticationMethod', function () { |
| 245 | + let removeAuthenticationMethodStub, request; |
| 246 | + |
| 247 | + beforeEach(function () { |
| 248 | + removeAuthenticationMethodStub = sinon.stub(libUsecases, 'removeAuthenticationMethod'); |
| 249 | + request = { |
| 250 | + params: { id: 123 }, |
| 251 | + payload: { |
| 252 | + data: { |
| 253 | + attributes: { |
| 254 | + type: 'EMAIL', |
| 255 | + }, |
| 256 | + }, |
| 257 | + }, |
| 258 | + }; |
| 259 | + }); |
| 260 | + |
| 261 | + context('Success cases', function () { |
| 262 | + it('returns a 204 HTTP status code', async function () { |
| 263 | + // given |
| 264 | + removeAuthenticationMethodStub.resolves(); |
| 265 | + |
| 266 | + // when |
| 267 | + const response = await userAdminController.removeAuthenticationMethod(request, hFake); |
| 268 | + |
| 269 | + // then |
| 270 | + expect(response.statusCode).to.equal(204); |
| 271 | + }); |
| 272 | + }); |
| 273 | + context('Error cases', function () { |
| 274 | + it('throws a UserNotAuthorizedToRemoveAuthenticationMethod when usecase has thrown this error', async function () { |
| 275 | + // given |
| 276 | + removeAuthenticationMethodStub.throws(new UserNotAuthorizedToRemoveAuthenticationMethod()); |
| 277 | + // when |
| 278 | + const error = await catchErr(userAdminController.removeAuthenticationMethod)(request, hFake); |
| 279 | + |
| 280 | + // then |
| 281 | + expect(error).to.be.instanceOf(UserNotAuthorizedToRemoveAuthenticationMethod); |
| 282 | + }); |
| 283 | + }); |
| 284 | + }); |
241 | 285 | });
|
0 commit comments