Skip to content

Commit

Permalink
refactor(api): migrate get-certification-point-of-contact usecase
Browse files Browse the repository at this point in the history
in identity-access-management
  • Loading branch information
er-lim committed Dec 5, 2024
1 parent 7c518be commit fde9b51
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
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 * as localeService from '../../../shared/domain/services/locale-service.js';
import * as userSerializer from '../../../shared/infrastructure/serializers/jsonapi/user-serializer.js';
import { requestResponseUtils } from '../../../shared/infrastructure/utils/request-response-utils.js';
Expand Down Expand Up @@ -237,7 +236,7 @@ const validateUserAccountEmail = async function (request, h) {

const getCertificationPointOfContact = async function (request) {
const authenticatedUserId = request.auth.credentials.userId;
const certificationPointOfContact = await libUsecases.getCertificationPointOfContact({ userId: authenticatedUserId });
const certificationPointOfContact = await usecases.getCertificationPointOfContact({ userId: authenticatedUserId });
return certificationPointOfContactSerializer.serialize(certificationPointOfContact);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/**
* @typedef {import('./index.js').CenterRepository} CenterRepository
* @typedef {import('../../../src/certification/enrolment/domain/models/Center.js').Center} Center
* @typedef {import('../../../certification/enrolment/infrastructure/repositories/center-repository.js').CenterRepository} CenterRepository
* @typedef {import('../../../../lib/infrastructure/repositories/certification-point-of-contact-repository.js').CertificationPointOfContactRepository} CertificationPointOfContactRepository
* @typedef {import('../../../certification/enrolment/domain/models/Center.js').Center} Center
*/
import { CONCURRENCY_HEAVY_OPERATIONS } from '../../../src/shared/infrastructure/constants.js';
import { PromiseUtils } from '../../../src/shared/infrastructure/utils/promise-utils.js';
import { CONCURRENCY_HEAVY_OPERATIONS } from '../../../shared/infrastructure/constants.js';
import { PromiseUtils } from '../../../shared/infrastructure/utils/promise-utils.js';

/**
* @param {Object} params
* @param {string} params.userId
* @param {CenterRepository} params.centerRepository
* @param {CertificationPointOfContactRepository} params.certificationPointOfContactRepository
*/
const getCertificationPointOfContact = async function ({
userId,
Expand Down
4 changes: 4 additions & 0 deletions api/src/identity-access-management/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import * as userReconciliationService from '../../../../lib/domain/services/user
import { oidcAuthenticationServiceRegistry } from '../../../../lib/domain/usecases/index.js';
import * as campaignParticipationRepository from '../../../../lib/infrastructure/repositories/campaign-participation-repository.js';
import * as campaignRepository from '../../../../lib/infrastructure/repositories/campaign-repository.js';
import * as certificationPointOfContactRepository from '../../../../lib/infrastructure/repositories/certification-point-of-contact-repository.js';
import * as organizationLearnerRepository from '../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import * as centerRepository from '../../../certification/enrolment/infrastructure/repositories/center-repository.js';
import * as userRecommendedTrainingRepository from '../../../devcomp/infrastructure/repositories/user-recommended-training-repository.js';
import { repositories as campaignRepositories } from '../../../prescription/campaign/infrastructure/repositories/index.js';
import { config } from '../../../shared/config.js';
Expand Down Expand Up @@ -52,7 +54,9 @@ const repositories = {
campaignParticipationRepository,
campaignRepository,
campaignToJoinRepository: campaignRepositories.campaignToJoinRepository,
centerRepository,
certificationCenterMembershipRepository,
certificationPointOfContactRepository,
emailValidationDemandRepository,
emailRepository,
eventLoggingJobRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { usecases } from '../../../../lib/domain/usecases/index.js';
import { CERTIFICATION_FEATURES } from '../../../../src/certification/shared/domain/constants.js';
import { CERTIFICATION_CENTER_MEMBERSHIP_ROLES } from '../../../../src/shared/domain/models/CertificationCenterMembership.js';
import { databaseBuilder, domainBuilder, expect } from '../../../test-helper.js';
import { CERTIFICATION_FEATURES } from '../../../../../src/certification/shared/domain/constants.js';
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
import { CERTIFICATION_CENTER_MEMBERSHIP_ROLES } from '../../../../../src/shared/domain/models/CertificationCenterMembership.js';
import { databaseBuilder, domainBuilder, expect } from '../../../../test-helper.js';

const { getCertificationPointOfContact } = usecases;

describe('Integration | UseCase | get-certification-point-of-contact', function () {
it('should return the CertificationPointOfContact', async function () {
describe('Integration | Identity Access Management | Domain | UseCase | get-certification-point-of-contact', function () {
it('returns the CertificationPointOfContact', async function () {
// given
const user = databaseBuilder.factory.buildUser();
const certificationCenter = databaseBuilder.factory.buildCertificationCenter();
Expand Down
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 { userController } from '../../../../../src/identity-access-management/application/user/user.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 @@ -475,7 +474,7 @@ describe('Unit | Identity Access Management | Application | Controller | User',

describe('#getCertificationPointOfContact', function () {
beforeEach(function () {
sinon.stub(libUsecases, 'getCertificationPointOfContact');
sinon.stub(usecases, 'getCertificationPointOfContact');
});

it('returns a serialized CertificationPointOfContact', async function () {
Expand Down Expand Up @@ -514,7 +513,7 @@ describe('Unit | Identity Access Management | Application | Controller | User',
},
};

libUsecases.getCertificationPointOfContact.withArgs({ userId: 123 }).resolves(certificationPointOfContact);
usecases.getCertificationPointOfContact.withArgs({ userId: 123 }).resolves(certificationPointOfContact);

// when
const response = await userController.getCertificationPointOfContact(request, hFake);
Expand Down

0 comments on commit fde9b51

Please sign in to comment.