Skip to content

Commit

Permalink
refactor(api): move get-user-details-for-admin usecase
Browse files Browse the repository at this point in the history
in src/identity-access-management
  • Loading branch information
er-lim authored Nov 6, 2024
1 parent 17350f8 commit 1e47392
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
5 changes: 0 additions & 5 deletions api/lib/domain/usecases/get-user-details-for-admin.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.js';
import { usecases } from '../../domain/usecases/index.js';
import * as userDetailsForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-details-for-admin.serializer.js';
import * as userForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-for-admin.serializer.js';
Expand Down Expand Up @@ -59,7 +58,7 @@ const updateUserDetailsByAdmin = async function (request, h, dependencies = { us
*/
const getUserDetails = async function (request, h, dependencies = { userDetailsForAdminSerializer }) {
const userId = request.params.id;
const userDetailsForAdmin = await libUsecases.getUserDetailsForAdmin({ userId });
const userDetailsForAdmin = await usecases.getUserDetailsForAdmin({ userId });
return dependencies.userDetailsForAdminSerializer.serialize(userDetailsForAdmin);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {Object} params
* @param {string} params.userId
* @param {UserRepository} userRepository
* @throws UserNotFoundError
* @returns {Promise<UserDetailsForAdmin>}
*/
const getUserDetailsForAdmin = async function ({ userId, userRepository }) {
return await userRepository.getUserDetailsForAdmin(userId);
};

export { getUserDetailsForAdmin };
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js';
import { userAdminController } from '../../../../../src/identity-access-management/application/user/user.admin.controller.js';
import { User } from '../../../../../src/identity-access-management/domain/models/User.js';
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
Expand Down Expand Up @@ -168,14 +167,14 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |
beforeEach(function () {
request = { params: { id: 123 } };

sinon.stub(libUsecases, 'getUserDetailsForAdmin');
sinon.stub(usecases, 'getUserDetailsForAdmin');
const userDetailsForAdminSerializer = { serialize: sinon.stub() };
dependencies = { userDetailsForAdminSerializer };
});

it('gets the specified user', async function () {
// given
libUsecases.getUserDetailsForAdmin.withArgs({ userId: 123 }).resolves('userDetail');
usecases.getUserDetailsForAdmin.withArgs({ userId: 123 }).resolves('userDetail');
dependencies.userDetailsForAdminSerializer.serialize.withArgs('userDetail').returns('ok');

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getUserDetailsForAdmin } from '../../../../lib/domain/usecases/get-user-details-for-admin.js';
import { expect, sinon } from '../../../test-helper.js';
import { getUserDetailsForAdmin } from '../../../../../src/identity-access-management/domain/usecases/get-user-details-for-admin.usecase.js';
import { expect, sinon } from '../../../../test-helper.js';

describe('Unit | UseCase | get-user-details-for-admin', function () {
describe('Unit | Identity Access Management | Domain | UseCase | get-user-details-for-admin', function () {
let userRepository;

beforeEach(function () {
userRepository = { getUserDetailsForAdmin: sinon.stub() };
});

it('should get the user details in administration context', async function () {
it('gets the user details in administration context', async function () {
// given
const userId = 1;
const expectedUserDetailsForAdmin = { id: userId };
Expand Down

0 comments on commit 1e47392

Please sign in to comment.