Skip to content

Commit

Permalink
feat(mon-pix): move anonymize user usecase in src
Browse files Browse the repository at this point in the history
  • Loading branch information
er-lim committed Nov 12, 2024
1 parent b74566e commit 8afd28c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 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 userAnonymizedDetailsForAdminSerializer from '../../../../lib/infrastructure/serializers/jsonapi/user-anonymized-details-for-admin-serializer.js';
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js';
import { usecases } from '../../domain/usecases/index.js';
Expand Down Expand Up @@ -78,7 +77,7 @@ const anonymizeUser = async function (request, h, dependencies = { userAnonymize
const adminMemberId = request.auth.credentials.userId;

await DomainTransaction.execute(async (domainTransaction) => {
await libUsecases.anonymizeUser({
await usecases.anonymizeUser({
userId: userToAnonymizeId,
updatedByUserId: adminMemberId,
domainTransaction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import { UserAnonymizedEventLoggingJob } from '../../../src/identity-access-management/domain/models/UserAnonymizedEventLoggingJob.js';
import { config } from '../../../src/shared/config.js';
import { UserNotFoundError } from '../../../src/shared/domain/errors.js';

import { config } from '../../../shared/config.js';
import { UserNotFoundError } from '../../../shared/domain/errors.js';
import { UserAnonymizedEventLoggingJob } from '../models/UserAnonymizedEventLoggingJob.js';

/**
* @param params
* @param{string} params.userId
* @param{string} params.updatedByUserId
* @param{boolean} params.preventAuditLogging
* @param{UserRepository} params.userRepository
* @param{AuthenticationMethodRepository} params.authenticationMethodRepository
* @param{MembershipRepository} params.membershipRepository
* @param{CertificationCenterMembershipRepository} params.certificationCenterMembershipRepository
* @param{OrganizationLearnerRepository} params.organizationLearnerRepository
* @param{RefreshTokenRepository} params.refreshTokenRepository
* @param{ResetPasswordDemandRepository} params.resetPasswordDemandRepository
* @param{UserLoginRepository} params.userLoginRepository
* @param{AdminMemberRepository} params.adminMemberRepository
* @param{UserAnonymizedEventLoggingJobRepository} params.userAnonymizedEventLoggingJobRepository
* @returns {Promise<null>}
*/
const anonymizeUser = async function ({
userId,
updatedByUserId,
Expand Down
6 changes: 6 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,6 +7,8 @@ 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 { userAnonymizedEventLoggingJobRepository } from '../../../../lib/infrastructure/repositories/jobs/user-anonymized-event-logging-job-repository.js';
import * as membershipRepository from '../../../../lib/infrastructure/repositories/membership-repository.js';
import * as organizationLearnerRepository from '../../../../lib/infrastructure/repositories/organization-learner-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';
Expand All @@ -21,6 +23,7 @@ import * as userLoginRepository from '../../../shared/infrastructure/repositorie
import * as codeUtils from '../../../shared/infrastructure/utils/code-utils.js';
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
import { certificationCenterMembershipRepository } from '../../../team/infrastructure/repositories/certification-center-membership.repository.js';
import { accountRecoveryDemandRepository } from '../../infrastructure/repositories/account-recovery-demand.repository.js';
import * as authenticationMethodRepository from '../../infrastructure/repositories/authentication-method.repository.js';
import { emailValidationDemandRepository } from '../../infrastructure/repositories/email-validation-demand.repository.js';
Expand All @@ -47,12 +50,15 @@ const repositories = {
campaignParticipationRepository,
campaignRepository,
campaignToJoinRepository: campaignRepositories.campaignToJoinRepository,
certificationCenterMembershipRepository,
emailValidationDemandRepository,
eventLoggingJobRepository,
membershipRepository,
oidcProviderRepository,
organizationLearnerRepository,
refreshTokenRepository,
resetPasswordDemandRepository,
userAnonymizedEventLoggingJobRepository,
userEmailRepository,
userLoginRepository,
userRecommendedTrainingRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { anonymizeUser } from '../../../../../lib/domain/usecases/anonymize-user.js';
import { userAnonymizedEventLoggingJobRepository } from '../../../../../lib/infrastructure/repositories/jobs/user-anonymized-event-logging-job-repository.js';
import * as membershipRepository from '../../../../../lib/infrastructure/repositories/membership-repository.js';
import * as organizationLearnerRepository from '../../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import { PIX_ADMIN } from '../../../../../src/authorization/domain/constants.js';
import { RefreshToken } from '../../../../../src/identity-access-management/domain/models/RefreshToken.js';
import { UserAnonymizedEventLoggingJob } from '../../../../../src/identity-access-management/domain/models/UserAnonymizedEventLoggingJob.js';
import { anonymizeUser } from '../../../../../src/identity-access-management/domain/usecases/anonymize-user.usecase.js';
import * as authenticationMethodRepository from '../../../../../src/identity-access-management/infrastructure/repositories/authentication-method.repository.js';
import { refreshTokenRepository } from '../../../../../src/identity-access-management/infrastructure/repositories/refresh-token.repository.js';
import { resetPasswordDemandRepository } from '../../../../../src/identity-access-management/infrastructure/repositories/reset-password-demand.repository.js';
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 { 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 @@ -207,7 +206,7 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |
const domainTransaction = {
knexTransaction: Symbol('transaction'),
};
sinon.stub(libUsecases, 'anonymizeUser');
sinon.stub(usecases, 'anonymizeUser');
sinon.stub(usecases, 'getUserDetailsForAdmin').resolves(userDetailsForAdmin);
sinon.stub(DomainTransaction, 'execute').callsFake((callback) => {
return callback(domainTransaction);
Expand All @@ -227,7 +226,7 @@ describe('Unit | Identity Access Management | Application | Controller | Admin |

// then
expect(DomainTransaction.execute).to.have.been.called;
expect(libUsecases.anonymizeUser).to.have.been.calledWithExactly({ userId, updatedByUserId, domainTransaction });
expect(usecases.anonymizeUser).to.have.been.calledWithExactly({ userId, updatedByUserId, domainTransaction });
expect(usecases.getUserDetailsForAdmin).to.have.been.calledWithExactly({ userId });
expect(userAnonymizedDetailsForAdminSerializer.serialize).to.have.been.calledWithExactly(userDetailsForAdmin);
expect(response.statusCode).to.equal(200);
Expand Down

0 comments on commit 8afd28c

Please sign in to comment.