Skip to content

Commit

Permalink
refactor(api): repace controller integration test with unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
er-lim authored Dec 4, 2024
1 parent fa656a0 commit 1e170ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js';
import { userAdminController } from '../../../../../src/identity-access-management/application/user/user.admin.controller.js';
import { QUERY_TYPES } from '../../../../../src/identity-access-management/domain/constants/user-query.js';
import { User } from '../../../../../src/identity-access-management/domain/models/User.js';
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
import { DomainTransaction } from '../../../../../src/shared/domain/DomainTransaction.js';
import { expect, hFake, sinon } from '../../../../test-helper.js';
import { UserNotAuthorizedToRemoveAuthenticationMethod } from '../../../../../src/shared/domain/errors.js';
import { catchErr, expect, hFake, sinon } from '../../../../test-helper.js';

describe('Unit | Identity Access Management | Application | Controller | Admin | User', function () {
describe('#findPaginatedFilteredUsers', function () {
Expand Down Expand Up @@ -238,4 +240,46 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |
expect(response.source).to.deep.equal(anonymizedUserSerialized);
});
});

describe('#removeAuthenticationMethod', function () {
let removeAuthenticationMethodStub, request;

beforeEach(function () {
removeAuthenticationMethodStub = sinon.stub(libUsecases, 'removeAuthenticationMethod');
request = {
params: { id: 123 },
payload: {
data: {
attributes: {
type: 'EMAIL',
},
},
},
};
});

context('Success cases', function () {
it('returns a 204 HTTP status code', async function () {
// given
removeAuthenticationMethodStub.resolves();

// when
const response = await userAdminController.removeAuthenticationMethod(request, hFake);

// then
expect(response.statusCode).to.equal(204);
});
});
context('Error cases', function () {
it('throws a UserNotAuthorizedToRemoveAuthenticationMethod when usecase has thrown this error', async function () {
// given
removeAuthenticationMethodStub.throws(new UserNotAuthorizedToRemoveAuthenticationMethod());
// when
const error = await catchErr(userAdminController.removeAuthenticationMethod)(request, hFake);

// then
expect(error).to.be.instanceOf(UserNotAuthorizedToRemoveAuthenticationMethod);
});
});
});
});
76 changes: 0 additions & 76 deletions api/tests/integration/application/users/user-controller_test.js

This file was deleted.

0 comments on commit 1e170ac

Please sign in to comment.