Skip to content

Commit 5e0bd56

Browse files
committed
refactor(api): repace controller integration test with unit test
1 parent 7f50d65 commit 5e0bd56

File tree

2 files changed

+45
-77
lines changed

2 files changed

+45
-77
lines changed

api/tests/identity-access-management/unit/application/user/user.admin.controller.test.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js';
12
import { userAdminController } from '../../../../../src/identity-access-management/application/user/user.admin.controller.js';
23
import { QUERY_TYPES } from '../../../../../src/identity-access-management/domain/constants/user-query.js';
34
import { User } from '../../../../../src/identity-access-management/domain/models/User.js';
45
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
56
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';
79

810
describe('Unit | Identity Access Management | Application | Controller | Admin | User', function () {
911
describe('#findPaginatedFilteredUsers', function () {
@@ -238,4 +240,46 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |
238240
expect(response.source).to.deep.equal(anonymizedUserSerialized);
239241
});
240242
});
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+
});
241285
});

api/tests/integration/application/users/user-controller_test.js

-76
This file was deleted.

0 commit comments

Comments
 (0)