Skip to content

Commit

Permalink
[TECH] ♻️ Déplace un model dans son context
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Sep 27, 2024
2 parents 461871f + 2295ca1 commit 5c8d3d0
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 34 deletions.
3 changes: 2 additions & 1 deletion api/src/shared/application/error-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ArchivedCampaignError, DeletedCampaignError } from '../../prescription/
import { CampaignParticipationDeletedError } from '../../prescription/campaign-participation/domain/errors.js';
import { AggregateImportError, SiecleXmlImportError } from '../../prescription/learner-management/domain/errors.js';
import { OrganizationCantGetPlacesStatisticsError } from '../../prescription/organization-place/domain/errors.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../../team/domain/errors.js';
import * as DomainErrors from '../domain/errors.js';
import {
AutonomousCourseRequiresATargetProfileWithSimplifiedAccessError,
Expand Down Expand Up @@ -345,7 +346,7 @@ function _mapToHttpError(error) {
if (error instanceof DomainErrors.AlreadyExistingInvitationError) {
return new HttpErrors.PreconditionFailedError(error.message);
}
if (error instanceof DomainErrors.AlreadyAcceptedOrCancelledInvitationError) {
if (error instanceof AlreadyAcceptedOrCancelledInvitationError) {
return new HttpErrors.ConflictError(error.message);
}
if (error instanceof DomainErrors.AlreadyExistingCampaignParticipationError) {
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 @@ -649,12 +649,6 @@ class AlreadyExistingInvitationError extends DomainError {
}
}

class AlreadyAcceptedOrCancelledInvitationError extends DomainError {
constructor(message = "L'invitation a déjà été acceptée ou annulée.") {
super(message);
}
}

class AlreadyRatedAssessmentError extends DomainError {
constructor(message = 'Cette évaluation a déjà été évaluée.') {
super(message);
Expand Down Expand Up @@ -1083,7 +1077,6 @@ export {
AccountRecoveryDemandExpired,
AccountRecoveryUserAlreadyConfirmEmail,
AcquiredBadgeForbiddenDeletionError,
AlreadyAcceptedOrCancelledInvitationError,
AlreadyExistingCampaignParticipationError,
AlreadyExistingEntityError,
AlreadyExistingInvitationError,
Expand Down
3 changes: 2 additions & 1 deletion api/src/shared/domain/models/OrganizationInvitedUser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AlreadyAcceptedOrCancelledInvitationError } from '../../../team/domain/errors.js';
import { OrganizationInvitation } from '../../../team/domain/models/OrganizationInvitation.js';
import { AlreadyAcceptedOrCancelledInvitationError, AlreadyExistingMembershipError, NotFoundError } from '../errors.js';
import { AlreadyExistingMembershipError, NotFoundError } from '../errors.js';
import { roles } from './Membership.js';

class OrganizationInvitedUser {
Expand Down
2 changes: 0 additions & 2 deletions api/src/shared/domain/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import { CertifiableBadgeAcquisition } from './CertifiableBadgeAcquisition.js';
import { CertifiableProfileForLearningContent } from './CertifiableProfileForLearningContent.js';
import { CertificationCandidate } from './CertificationCandidate.js';
import { CertificationCenter } from './CertificationCenter.js';
import { CertificationCenterInvitedUser } from './CertificationCenterInvitedUser.js';
import { CertificationCenterMembership } from './CertificationCenterMembership.js';
import { CertificationChallenge } from './CertificationChallenge.js';
import { CertificationChallengeWithType } from './CertificationChallengeWithType.js';
Expand Down Expand Up @@ -151,7 +150,6 @@ export {
CertificationCandidate,
CertificationCandidateForSupervising,
CertificationCenter,
CertificationCenterInvitedUser,
CertificationCenterMembership,
CertificationChallenge,
CertificationChallengeWithType,
Expand Down
7 changes: 7 additions & 0 deletions api/src/team/domain/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { DomainError } from '../../shared/domain/errors.js';

class AlreadyAcceptedOrCancelledInvitationError extends DomainError {
constructor(message = "L'invitation a déjà été acceptée ou annulée.") {
super(message);
}
}

class AlreadyExistingAdminMemberError extends DomainError {
constructor(message = 'Cet agent a déjà accès') {
super(message);
Expand Down Expand Up @@ -33,6 +39,7 @@ class OrganizationArchivedError extends DomainError {
}

export {
AlreadyAcceptedOrCancelledInvitationError,
AlreadyExistingAdminMemberError,
MembershipNotFound,
OrganizationArchivedError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NotFoundError } from '../../../shared/domain/errors.js';
import { CertificationCenterInvitation } from '../../../team/domain/models/CertificationCenterInvitation.js';
import { AlreadyAcceptedOrCancelledInvitationError, NotFoundError } from '../errors.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../errors.js';

class CertificationCenterInvitedUser {
constructor({ userId, invitation, status, role } = {}) {
Expand Down
7 changes: 2 additions & 5 deletions api/src/team/domain/models/OrganizationInvitedUser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {
AlreadyAcceptedOrCancelledInvitationError,
AlreadyExistingMembershipError,
NotFoundError,
} from '../../../shared/domain/errors.js';
import { AlreadyExistingMembershipError, NotFoundError } from '../../../shared/domain/errors.js';
import { roles } from '../../../shared/domain/models/Membership.js';
import { OrganizationInvitation } from '../../../team/domain/models/OrganizationInvitation.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../errors.js';

class OrganizationInvitedUser {
constructor({ userId, invitation, currentRole, organizationHasMemberships, currentMembershipId, status } = {}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { knex } from '../../../../db/knex-database-connection.js';
import { NotFoundError } from '../../../shared/domain/errors.js';
import { CertificationCenterInvitedUser } from '../../../shared/domain/models/CertificationCenterInvitedUser.js';
import { CertificationCenterInvitedUser } from '../../domain/models/CertificationCenterInvitedUser.js';

const get = async function ({ certificationCenterInvitationId, email }) {
const invitation = await knex('certification-center-invitations')
Expand Down
3 changes: 2 additions & 1 deletion api/tests/integration/application/error-manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../src/identity-access-management/domain/errors.js';
import { CampaignParticipationDeletedError } from '../../../src/prescription/campaign-participation/domain/errors.js';
import * as DomainErrors from '../../../src/shared/domain/errors.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../../../src/team/domain/errors.js';
import { expect, HttpTestServer, sinon } from '../../test-helper.js';

describe('Integration | API | Controller Error', function () {
Expand Down Expand Up @@ -259,7 +260,7 @@ describe('Integration | API | Controller Error', function () {
});

it('responds Conflict when an AlreadyAcceptedOrCancelledInvitationError occurs', async function () {
routeHandler.throws(new DomainErrors.AlreadyAcceptedOrCancelledInvitationError());
routeHandler.throws(new AlreadyAcceptedOrCancelledInvitationError());
const response = await server.requestObject(request);

expect(response.statusCode).to.equal(CONFLICT_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import lodash from 'lodash';

import { NotFoundError } from '../../../../../src/shared/domain/errors.js';
import { CertificationCenterInvitedUser } from '../../../../../src/shared/domain/models/CertificationCenterInvitedUser.js';
import { CertificationCenterInvitation } from '../../../../../src/team/domain/models/CertificationCenterInvitation.js';
import { CertificationCenterInvitedUser } from '../../../../../src/team/domain/models/CertificationCenterInvitedUser.js';
import { certificationCenterInvitedUserRepository } from '../../../../../src/team/infrastructure/repositories/certification-center-invited-user.repository.js';
import { catchErr, databaseBuilder, expect, knex, sinon } from '../../../../test-helper.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AlreadyAcceptedOrCancelledInvitationError, NotFoundError } from '../../../../src/shared/domain/errors.js';
import { CertificationCenterInvitedUser } from '../../../../src/shared/domain/models/CertificationCenterInvitedUser.js';
import { CertificationCenterInvitation } from '../../../../src/team/domain/models/CertificationCenterInvitation.js';
import { catchErr, domainBuilder, expect } from '../../../test-helper.js';
import { NotFoundError } from '../../../../../src/shared/domain/errors.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../../../../../src/team/domain/errors.js';
import { CertificationCenterInvitation } from '../../../../../src/team/domain/models/CertificationCenterInvitation.js';
import { CertificationCenterInvitedUser } from '../../../../../src/team/domain/models/CertificationCenterInvitedUser.js';
import { catchErr, domainBuilder, expect } from '../../../../test-helper.js';

describe('Unit | Domain | Models | CertificationCenterInvitedUser', function () {
describe('#acceptInvitation', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
AlreadyAcceptedOrCancelledInvitationError,
AlreadyExistingMembershipError,
NotFoundError,
} from '../../../../../src/shared/domain/errors.js';
import { AlreadyExistingMembershipError, NotFoundError } from '../../../../../src/shared/domain/errors.js';
import { OrganizationInvitedUser } from '../../../../../src/shared/domain/models/OrganizationInvitedUser.js';
import { AlreadyAcceptedOrCancelledInvitationError } from '../../../../../src/team/domain/errors.js';
import { catchErr, domainBuilder, expect } from '../../../../test-helper.js';

describe('Unit | Team | Domain | Model | OrganizationInvitedUser', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AlreadyExistingMembershipError } from '../../../../../src/shared/domain/errors.js';
import { CertificationCenterInvitedUser } from '../../../../../src/shared/domain/models/CertificationCenterInvitedUser.js';
import { CertificationCenterInvitation } from '../../../../../src/team/domain/models/CertificationCenterInvitation.js';
import { CertificationCenterInvitedUser } from '../../../../../src/team/domain/models/CertificationCenterInvitedUser.js';
import { acceptCertificationCenterInvitation } from '../../../../../src/team/domain/usecases/accept-certification-center-invitation.usecase.js';
import { catchErr, domainBuilder, expect, sinon } from '../../../../test-helper.js';

Expand Down
4 changes: 0 additions & 4 deletions api/tests/unit/domain/errors_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ describe('Unit | Domain | Errors', function () {
expect(errors.OrganizationLearnerCannotBeDissociatedError).to.exist;
});

it('should export an AlreadyAcceptedOrCancelledInvitationError', function () {
expect(errors.AlreadyAcceptedOrCancelledInvitationError).to.exist;
});

it('should export an MissingAttributesError', function () {
expect(errors.MissingAttributesError).to.exist;
});
Expand Down

0 comments on commit 5c8d3d0

Please sign in to comment.