Skip to content

Commit

Permalink
♻️ refactor migrate issue report
Browse files Browse the repository at this point in the history
  • Loading branch information
yaf committed Oct 10, 2024
1 parent d231be0 commit 19df400
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 64 deletions.

This file was deleted.

5 changes: 0 additions & 5 deletions api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import * as certificationAssessmentRepository from '../../../src/certification/s
import * as certificationCenterRepository from '../../../src/certification/shared/infrastructure/repositories/certification-center-repository.js';
import * as certificationChallengeLiveAlertRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js';
import * as certificationChallengeRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-repository.js';
import * as certificationCourseRepository from '../../../src/certification/shared/infrastructure/repositories/certification-course-repository.js';
import * as certificationIssueReportRepository from '../../../src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js';
import * as flashAlgorithmConfigurationRepository from '../../../src/certification/shared/infrastructure/repositories/flash-algorithm-configuration-repository.js';
import * as issueReportCategoryRepository from '../../../src/certification/shared/infrastructure/repositories/issue-report-category-repository.js';
import * as sharedSessionRepository from '../../../src/certification/shared/infrastructure/repositories/session-repository.js';
Expand Down Expand Up @@ -191,7 +189,6 @@ function requirePoleEmploiNotifier() {
* @typedef {dataProtectionOfficerRepository} DataProtectionOfficerRepository
* @typedef {userAnonymizedEventLoggingJobRepository} UserAnonymizedEventLoggingJobRepository
* @typedef {certificationCandidateRepository} CertificationCandidateRepository
* @typedef {certificationCourseRepository} CertificationCourseRepository
* @typedef {userRepository} UserRepository
* @typedef {certificationChallengesService} CertificationChallengesService
* @typedef {verifyCertificateCodeService} VerifyCertificateCodeService
Expand Down Expand Up @@ -237,9 +234,7 @@ const dependencies = {
certificationChallengeLiveAlertRepository,
certificationChallengeRepository,
certificationChallengesService,
certificationCourseRepository,
certificationCpfCityRepository,
certificationIssueReportRepository,
certificationOfficerRepository,
certificationPointOfContactRepository,
certificationRepository,
Expand Down
2 changes: 0 additions & 2 deletions api/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as certificationCenterInvitations from './application/certification-cen
import * as certificationCenterMemberships from './application/certification-center-memberships/index.js';
import * as certificationCenters from './application/certification-centers/index.js';
import * as certificationCourses from './application/certification-courses/index.js';
import * as certificationIssueReports from './application/certification-issue-reports/index.js';
import * as certificationPointOfContacts from './application/certification-point-of-contacts/index.js';
import * as certifications from './application/certifications/index.js';
import * as frameworks from './application/frameworks/index.js';
Expand All @@ -31,7 +30,6 @@ const routes = [
certificationCenterMemberships,
certificationCourses,
certificationPointOfContacts,
certificationIssueReports,
certifications,
healthcheck,
memberships,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { deleteCertificationIssueReport as deleteCertificationIssueReportUsecase } from '../domain/usecases/delete-certification-issue-report.js';
import { manuallyResolveCertificationIssueReport } from '../domain/usecases/manually-resolve-certification-issue-report.js';

async function deleteCertificationIssueReport(request, h, dependencies = { deleteCertificationIssueReportUsecase }) {
const certificationIssueReportId = request.params.id;
await dependencies.deleteCertificationIssueReportUsecase({ certificationIssueReportId });

// TODO return code 204 instead of null ?
return null;
}

async function manuallyResolve(request, h, dependencies = { manuallyResolveCertificationIssueReport }) {
const certificationIssueReportId = request.params.id;
const resolution = request.payload.data.resolution;
await dependencies.manuallyResolveCertificationIssueReport({
certificationIssueReportId,
resolution,
});

return h.response().code(204);
}

const certificationIssueReportController = { deleteCertificationIssueReport, manuallyResolve };

export { certificationIssueReportController };
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi';

import { securityPreHandlers } from '../../../src/shared/application/security-pre-handlers.js';
import { identifiersType } from '../../../src/shared/domain/types/identifiers-type.js';
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { certificationIssueReportController } from './certification-issue-report-controller.js';

const register = async function (server) {
Expand Down
7 changes: 7 additions & 0 deletions api/src/certification/session-management/domain/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ class SessionNotAccessible extends DomainError {
}
}

class CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually extends DomainError {
constructor(message = 'Le signalement ne peut pas être modifié manuellement') {
super(message);
}
}

export {
CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually,
ChallengeToBeDeneutralizedNotFoundError,
ChallengeToBeNeutralizedNotFoundError,
CsvWithNoSessionDataError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ForbiddenAccess } from '../../../src/shared/domain/errors.js';
import { ForbiddenAccess } from '../../../../shared/domain/errors.js';

const deleteCertificationIssueReport = async function ({
certificationIssueReportId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually } from '../../../src/shared/domain/errors.js';
import { CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually } from '../../domain/errors.js';

const manuallyResolveCertificationIssueReport = async function ({
certificationIssueReportId,
Expand Down
7 changes: 0 additions & 7 deletions api/src/shared/domain/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ class CertificationCourseNotPublishableError extends DomainError {
}
}

class CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually extends DomainError {
constructor(message = 'Le signalement ne peut pas être modifié manuellement') {
super(message);
}
}

class ImportLearnerConfigurationError extends DomainError {
constructor(message, code) {
super(message);
Expand Down Expand Up @@ -1123,7 +1117,6 @@ export {
CertificationCourseNotPublishableError,
CertificationEndedByFinalizationError,
CertificationEndedBySupervisorError,
CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually,
ChallengeAlreadyAnsweredError,
ChallengeNotAskedError,
CsvImportError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { certificationIssueReportController } from '../../../../lib/application/certification-issue-reports/certification-issue-report-controller.js';
import { usecases } from '../../../../lib/domain/usecases/index.js';
import { expect, hFake, sinon } from '../../../test-helper.js';
import { certificationIssueReportController } from '../../../../../src/certification/session-management/application/certification-issue-report-controller.js';
import { manuallyResolveCertificationIssueReport } from '../../../../../src/certification/session-management/domain/usecases/manually-resolve-certification-issue-report.js';
import { expect, hFake, sinon } from '../../../../test-helper.js';

describe('Unit | Controller | certification-issue-report-controller', function () {
describe('#deleteCertificationIssueReport', function () {
it('should proceed to deletion', async function () {
it('should call deleteCertificationIssuerReport usecase', async function () {
// given
const certificationIssueReportId = 456;
const userId = 789;
sinon.stub(usecases, 'deleteCertificationIssueReport');
const dependencies = { deleteCertificationIssueReportUsecase: sinon.stub() };

// when
const response = await certificationIssueReportController.deleteCertificationIssueReport(
Expand All @@ -21,11 +21,14 @@ describe('Unit | Controller | certification-issue-report-controller', function (
},
},
hFake,
dependencies,
);

// then
expect(response).to.be.null;
expect(usecases.deleteCertificationIssueReport).to.have.been.calledWithExactly({ certificationIssueReportId });
expect(dependencies.deleteCertificationIssueReportUsecase).to.have.been.calledWithExactly({
certificationIssueReportId,
});
});
});

Expand All @@ -42,18 +45,14 @@ describe('Unit | Controller | certification-issue-report-controller', function (
},
},
};
const manuallyResolveCertificationIssueReportStub = sinon.stub(
usecases,
'manuallyResolveCertificationIssueReport',
);
manuallyResolveCertificationIssueReportStub.resolves();
const dependencies = { manuallyResolveCertificationIssueReport: sinon.stub() };

// when
const response = await certificationIssueReportController.manuallyResolve(request, hFake);
const response = await certificationIssueReportController.manuallyResolve(request, hFake, dependencies);

// then
expect(response.statusCode).to.deep.equal(204);
expect(manuallyResolveCertificationIssueReportStub).has.been.calledOnceWith({
expect(dependencies.manuallyResolveCertificationIssueReport).has.been.calledOnceWith({
certificationIssueReportId: 100,
resolution: 'resolved',
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { certificationIssueReportController } from '../../../../lib/application/certification-issue-reports/certification-issue-report-controller.js';
import * as moduleUnderTest from '../../../../lib/application/certification-issue-reports/index.js';
import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js';
import { expect, HttpTestServer, sinon } from '../../../test-helper.js';
import { certificationIssueReportController } from '../../../../../src/certification/session-management/application/certification-issue-report-controller.js';
import * as moduleUnderTest from '../../../../../src/certification/session-management/application/certification-issue-report-route.js';
import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js';
import { expect, HttpTestServer, sinon } from '../../../../test-helper.js';

describe('Unit | Application | Certifications Issue Report | Route', function () {
describe('DELETE /api/certification-issue-reports/{id}', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'lodash';

import { deleteCertificationIssueReport } from '../../../../lib/domain/usecases/delete-certification-issue-report.js';
import { ForbiddenAccess } from '../../../../src/shared/domain/errors.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js';
import { deleteCertificationIssueReport } from '../../../../../../src/certification/session-management/domain/usecases/delete-certification-issue-report.js';
import { ForbiddenAccess } from '../../../../../../src/shared/domain/errors.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js';

describe('Unit | UseCase | delete-certification-issue-report', function () {
const certificationCourseRepository = { getSessionId: () => _.noop() };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { manuallyResolveCertificationIssueReport } from '../../../../lib/domain/usecases/manually-resolve-certification-issue-report.js';
import { CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually } from '../../../../src/shared/domain/errors.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js';
import { CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually } from '../../../../../../src/certification/session-management/domain/errors.js';
import { manuallyResolveCertificationIssueReport } from '../../../../../../src/certification/session-management/domain/usecases/manually-resolve-certification-issue-report.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js';

describe('Unit | UseCase | manually-resolve-certification-issue-report', function () {
describe('when certification issue report is not resolved', function () {
Expand Down

0 comments on commit 19df400

Please sign in to comment.