diff --git a/packages/reva-api/modules/finance/unifvae/batches/fundingRequestUnifvae.batch.test.ts b/packages/reva-api/modules/finance/unifvae/batches/fundingRequestUnifvae.batch.test.ts index 47a81035e..dc5cf3591 100644 --- a/packages/reva-api/modules/finance/unifvae/batches/fundingRequestUnifvae.batch.test.ts +++ b/packages/reva-api/modules/finance/unifvae/batches/fundingRequestUnifvae.batch.test.ts @@ -3,7 +3,7 @@ import { Gender } from "@prisma/client"; import { prismaClient } from "../../../../prisma/client"; import { generateFundingRequestUnifvaeBatchCsvStream } from "./fundingRequestUnifvae"; -const fundingRequestSample = { +const FUNDING_REQUEST_SAMPLE = { candidateSecondname: "Lapin", candidateThirdname: "Piou", basicSkillsCost: 12.3, @@ -29,7 +29,7 @@ beforeAll(async () => { financeModule: "unifvae", fundingRequestUnifvae: { create: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, fundingRequestBatchUnifvae: { create: { sent: false, @@ -50,7 +50,7 @@ beforeAll(async () => { financeModule: "unifvae", fundingRequestUnifvae: { create: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, fundingRequestBatchUnifvae: { create: { sent: true, @@ -71,7 +71,7 @@ beforeAll(async () => { financeModule: "unifvae", fundingRequestUnifvae: { create: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, fundingRequestBatchUnifvae: { create: { sent: false, diff --git a/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts b/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts index 1923b7211..bc4c011c8 100644 --- a/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts +++ b/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts @@ -13,12 +13,10 @@ import { CANDIDACY_UNIFVAE, CANDIDACY_UNIREVA, CANDIDATE_MAN, + FUNDING_REQUEST_SAMPLE, ORGANISM_EXPERT_FILIERE, + PAYMENT_REQUEST, } from "../../../../test/fixtures"; -import { - fundingRequestSample, - paymentRequestInputBase, -} from "../../../../test/fixtures/funding-requests.fixture"; import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper"; import { createCandidacyUnifvae, @@ -94,7 +92,7 @@ const injectGraphqlPaymentRequestCreation = async () => arguments: { candidacyId: CANDIDACY_UNIFVAE.id, paymentRequest: { - ...paymentRequestInputBase, + ...PAYMENT_REQUEST, }, }, }, @@ -133,7 +131,7 @@ test("should create fundingRequestUnifvae with matching batch", async () => { arguments: { candidacyId: CANDIDACY_UNIFVAE.id, fundingRequest: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, }, }, enumFields: ["candidateGender"], @@ -146,7 +144,7 @@ test("should create fundingRequestUnifvae with matching batch", async () => { expect(obj).toMatchObject({ data: { candidacy_createFundingRequestUnifvae: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, }, }, }); @@ -162,9 +160,9 @@ test("should create fundingRequestUnifvae with matching batch", async () => { where: { id: CANDIDATE_MAN.id }, }); expect(myCandidate).toMatchObject({ - firstname2: fundingRequestSample.candidateSecondname, - firstname3: fundingRequestSample.candidateThirdname, - gender: fundingRequestSample.candidateGender, + firstname2: FUNDING_REQUEST_SAMPLE.candidateSecondname, + firstname3: FUNDING_REQUEST_SAMPLE.candidateThirdname, + gender: FUNDING_REQUEST_SAMPLE.candidateGender, }); // Check batch @@ -210,7 +208,7 @@ test("Should fail to create fundingRequestUnifvae when candidacy is not bound to arguments: { candidacyId: CANDIDACY_UNIREVA.id, fundingRequest: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, }, }, enumFields: ["candidateGender"], @@ -243,7 +241,7 @@ test("should fail to create a fundingRequestUnifvae whith a 'hors care' candidac arguments: { candidacyId: CANDIDACY_UNIFVAE.id, fundingRequest: { - ...fundingRequestSample, + ...FUNDING_REQUEST_SAMPLE, }, }, enumFields: ["candidateGender"], diff --git a/packages/reva-api/modules/finance/unifvae/validation/accompagnement.test.ts b/packages/reva-api/modules/finance/unifvae/validation/accompagnement.test.ts index 504eac4b8..2893e9a9a 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/accompagnement.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/accompagnement.test.ts @@ -1,6 +1,6 @@ import { Decimal } from "@prisma/client/runtime/library"; -import { fundingRequestFullCertOkHours } from "../../../../test/fixtures/funding-requests.fixture"; +import { FUNDING_REQUEST_FULL_CERT_OK_HOURS } from "../../../../test/fixtures"; import { validateAccompagnement } from "./accompagnement"; test("Should yield an error when no cost associated to hour count for accompaniment", () => { @@ -19,7 +19,7 @@ test("Should yield an error when no cost associated to hour count for accompanim test("Should be ok with only individual hours", () => { const errors = validateAccompagnement({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualHourCount: new Decimal(2), individualCost: new Decimal(24.5), }); @@ -28,7 +28,7 @@ test("Should be ok with only individual hours", () => { test("Should be ok with individual + collective hours", () => { const errors = validateAccompagnement({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualHourCount: new Decimal(2), individualCost: new Decimal(24.5), collectiveHourCount: new Decimal(3.5), diff --git a/packages/reva-api/modules/finance/unifvae/validation/cout-total.test.ts b/packages/reva-api/modules/finance/unifvae/validation/cout-total.test.ts index d2db84bd9..2df8ae58f 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/cout-total.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/cout-total.test.ts @@ -1,12 +1,12 @@ import { Decimal } from "@prisma/client/runtime/library"; -import { fundingRequestFullCertOkHours } from "../../../../test/fixtures/funding-requests.fixture"; +import { FUNDING_REQUEST_FULL_CERT_OK_HOURS } from "../../../../test/fixtures"; import { validateCoutTotal } from "./cout-total"; test("Should yield an error when total cost > 3200", () => { const errors = validateCoutTotal({ maximumTotalCostAllowed: new Decimal(3200), - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualCost: new Decimal(500), collectiveCost: new Decimal(500), basicSkillsCost: new Decimal(500), @@ -21,7 +21,7 @@ test("Should yield an error when total cost > 3200", () => { test("Should be ok if total cost equals 3200", () => { const errors = validateCoutTotal({ maximumTotalCostAllowed: new Decimal(3200), - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualCost: new Decimal(500), collectiveCost: new Decimal(500), basicSkillsCost: new Decimal(500), diff --git a/packages/reva-api/modules/finance/unifvae/validation/couts-horaires.test.ts b/packages/reva-api/modules/finance/unifvae/validation/couts-horaires.test.ts index 0258baa0b..0496db638 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/couts-horaires.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/couts-horaires.test.ts @@ -1,11 +1,11 @@ import { Decimal } from "@prisma/client/runtime/library"; -import { fundingRequestFullCertOkHours } from "../../../../test/fixtures/funding-requests.fixture"; +import { FUNDING_REQUEST_FULL_CERT_OK_HOURS } from "../../../../test/fixtures"; import { validateCoutsHoraires } from "./couts-horaires"; test("Should yield an error when individualCost > 70", () => { const errors = validateCoutsHoraires({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualCost: new Decimal(72), }); expect(errors.length).toBe(1); @@ -15,7 +15,7 @@ test("Should yield an error when individualCost > 70", () => { test("Should yield an error when collectiveCost > 35", () => { const errors = validateCoutsHoraires({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, collectiveCost: new Decimal(37), }); expect(errors.length).toBe(1); @@ -25,7 +25,7 @@ test("Should yield an error when collectiveCost > 35", () => { test("Should be ok with collectiveCost:35 and individualCost:70", () => { const errors = validateCoutsHoraires({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualCost: new Decimal(70), collectiveCost: new Decimal(35), }); diff --git a/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts b/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts index f2ca58efb..ec3a06c7b 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts @@ -1,11 +1,11 @@ import { Candidacy } from "@prisma/client"; import { prismaClient } from "../../../../prisma/client"; -import { CERTIFICATION_AUTHORITY_STRUCTURES } from "../../../../test/fixtures"; import { - fundingRequestFullCertOkHours, - fundingRequestNoHours, -} from "../../../../test/fixtures/funding-requests.fixture"; + CERTIFICATION_AUTHORITY_STRUCTURES, + FUNDING_REQUEST_FULL_CERT_OK_HOURS, + FUNDING_REQUEST_NO_HOURS, +} from "../../../../test/fixtures"; import { validateFeasibilityChecks } from "./feasibility-checks"; let candNoFeasibilty: Candidacy, @@ -109,7 +109,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should fail when feasibility not sent", async () => { const errors = await validateFeasibilityChecks({ candidacyId: candNoFeasibilty.id, - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, }); expect(errors.length).toEqual(1); expect(errors[0].fieldName).toBe("GLOBAL"); @@ -121,7 +121,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should fail when feasibility decision is still pending", async () => { const errors = await validateFeasibilityChecks({ candidacyId: candFeasibiltyPending.id, - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, }); expect(errors.length).toEqual(1); expect(errors[0].fieldName).toBe("GLOBAL"); @@ -133,7 +133,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should fail when feasibility rejected and funding request has disallowed items", async () => { const errors = await validateFeasibilityChecks({ candidacyId: candFeasibiltyRejected.id, - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, }); console.log(errors); expect(errors.length).toEqual(6); @@ -142,7 +142,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should succeed when feasibility rejected and request has only allowed items", async () => { const errors = await validateFeasibilityChecks({ candidacyId: candFeasibiltyValidated.id, - ...fundingRequestNoHours, + ...FUNDING_REQUEST_NO_HOURS, }); expect(errors.length).toEqual(0); }); @@ -150,7 +150,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should succeed when feasibility validated", async () => { const errors = await validateFeasibilityChecks({ candidacyId: candFeasibiltyValidated.id, - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, }); expect(errors.length).toEqual(0); }); diff --git a/packages/reva-api/modules/finance/unifvae/validation/forfait-heures.test.ts b/packages/reva-api/modules/finance/unifvae/validation/forfait-heures.test.ts index 857476bd8..974a2a82a 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/forfait-heures.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/forfait-heures.test.ts @@ -1,12 +1,12 @@ import { Decimal } from "@prisma/client/runtime/library"; -import { fundingRequestFullCertOkHours } from "../../../../test/fixtures/funding-requests.fixture"; +import { FUNDING_REQUEST_FULL_CERT_OK_HOURS } from "../../../../test/fixtures"; import { valideForfaitHeures } from "./forfait-heures"; describe("individualHourCount rules", () => { test("Should yield an error when full certification and > 30", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, individualHourCount: new Decimal(32), }); @@ -17,7 +17,7 @@ describe("individualHourCount rules", () => { }); test("Should yield an error when partial certification and > 15", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, individualHourCount: new Decimal(16), }); @@ -28,7 +28,7 @@ describe("individualHourCount rules", () => { }); test("Should return no error when full certification and <= 30", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, individualHourCount: new Decimal(30), }); @@ -36,7 +36,7 @@ describe("individualHourCount rules", () => { }); test("Should return no error when partial certification and <= 15", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, individualHourCount: new Decimal(15), }); @@ -47,7 +47,7 @@ describe("individualHourCount rules", () => { describe("collectiveHourCount rules", () => { test("Should yield an error when full certification and > 20", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, collectiveHourCount: new Decimal(22), }); @@ -58,7 +58,7 @@ describe("collectiveHourCount rules", () => { }); test("Should yield an error when partial certification and > 10", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, collectiveHourCount: new Decimal(12), }); @@ -69,7 +69,7 @@ describe("collectiveHourCount rules", () => { }); test("Should return no error when full certification and <= 20", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, collectiveHourCount: new Decimal(10), }); @@ -77,7 +77,7 @@ describe("collectiveHourCount rules", () => { }); test("Should return no error when partial certification and <= 10", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, collectiveHourCount: new Decimal(10), }); @@ -88,7 +88,7 @@ describe("collectiveHourCount rules", () => { describe("complementaryTraining hours sum rules", () => { test("Should yield 3 errors when full certification and sum > 70", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, basicSkillsHourCount: new Decimal(68), mandatoryTrainingsHourCount: new Decimal(1), @@ -102,7 +102,7 @@ describe("complementaryTraining hours sum rules", () => { }); test("Should yield 3 errors when partial certification and sum > 35", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, basicSkillsHourCount: new Decimal(33), mandatoryTrainingsHourCount: new Decimal(1), @@ -116,7 +116,7 @@ describe("complementaryTraining hours sum rules", () => { }); test("Should return no error when full certification and sum <= 70", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: false, basicSkillsHourCount: new Decimal(67), mandatoryTrainingsHourCount: new Decimal(1), @@ -127,7 +127,7 @@ describe("complementaryTraining hours sum rules", () => { }); test("Should return no error when partial certification and sum <= 35", () => { const errors = valideForfaitHeures({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, isCertificationPartial: true, basicSkillsHourCount: new Decimal(32), mandatoryTrainingsHourCount: new Decimal(1), diff --git a/packages/reva-api/modules/finance/unifvae/validation/valid-numbers.test.ts b/packages/reva-api/modules/finance/unifvae/validation/valid-numbers.test.ts index 0ae197f9d..7f12a85c8 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/valid-numbers.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/valid-numbers.test.ts @@ -16,7 +16,7 @@ const fundingRequestBase = { otherTrainingCost: new Decimal(1), }; -const fundingRequestFullCertOkHours = { +const FUNDING_REQUEST_FULL_CERT_OK_HOURS = { ...fundingRequestBase, isPartialCertification: false, basicSkillsHourCount: new Decimal(1), @@ -29,7 +29,7 @@ const fundingRequestFullCertOkHours = { test("Should yield an error when a number is negative", () => { const errors = validHoursCountAndCosts({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, individualCost: new Decimal(-3), }); expect(errors.length).toBe(1); @@ -39,7 +39,7 @@ test("Should yield an error when a number is negative", () => { test("Should yield an error when an hour count is not multiple of 0,5", () => { const errors = validHoursCountAndCosts({ - ...fundingRequestFullCertOkHours, + ...FUNDING_REQUEST_FULL_CERT_OK_HOURS, basicSkillsHourCount: new Decimal(2.3), basicSkillsCost: new Decimal(34.12), }); diff --git a/packages/reva-api/test/fixtures/funding-request.ts b/packages/reva-api/test/fixtures/funding-requests.fixture.ts similarity index 75% rename from packages/reva-api/test/fixtures/funding-request.ts rename to packages/reva-api/test/fixtures/funding-requests.fixture.ts index 12bb762cf..35727f05e 100644 --- a/packages/reva-api/test/fixtures/funding-request.ts +++ b/packages/reva-api/test/fixtures/funding-requests.fixture.ts @@ -30,7 +30,7 @@ const fundingRequestBase = { otherTrainingCost: new Decimal(1), }; -export const fundingRequestNoHours = { +export const FUNDING_REQUEST_NO_HOURS = { companionId: dummyUuid, ...candidateInfo, ...fundingContactInfo, @@ -49,7 +49,7 @@ export const fundingRequestNoHours = { isPartialCertification: false, }; -export const fundingRequestFullCertOkHours = { +export const FUNDING_REQUEST_FULL_CERT_OK_HOURS = { ...fundingRequestBase, isPartialCertification: false, basicSkillsHourCount: new Decimal(1), @@ -60,7 +60,7 @@ export const fundingRequestFullCertOkHours = { otherTrainingHourCount: new Decimal(1), }; -export const fundingRequestSample = { +export const FUNDING_REQUEST_SAMPLE = { ...fundingRequestBase, basicSkillsCost: 12.3, basicSkillsHourCount: 2.5, @@ -75,19 +75,3 @@ export const fundingRequestSample = { otherTrainingCost: 21.3, otherTrainingHourCount: 2.5, }; - -export const paymentRequestInputBase = { - individualEffectiveHourCount: 0, - individualEffectiveCost: 0, - collectiveEffectiveHourCount: 0, - collectiveEffectiveCost: 0, - mandatoryTrainingsEffectiveHourCount: 0, - mandatoryTrainingsEffectiveCost: 0, - basicSkillsEffectiveHourCount: 0, - basicSkillsEffectiveCost: 0, - certificateSkillsEffectiveHourCount: 0, - certificateSkillsEffectiveCost: 0, - otherTrainingEffectiveHourCount: 0, - otherTrainingEffectiveCost: 0, - invoiceNumber: "Invoice-001", -}; diff --git a/packages/reva-api/test/fixtures/index.ts b/packages/reva-api/test/fixtures/index.ts index 3972f5a01..f8d621b9a 100644 --- a/packages/reva-api/test/fixtures/index.ts +++ b/packages/reva-api/test/fixtures/index.ts @@ -3,4 +3,6 @@ export * from "./candidacies.fixture"; export * from "./candidates.fixture"; export * from "./certifications.fixture"; export * from "./feasibilities.fixture"; +export * from "./funding-requests.fixture"; export * from "./organisms.fixture"; +export * from "./payment-requests.fixture"; diff --git a/packages/reva-api/test/fixtures/payment-requests.fixture.ts b/packages/reva-api/test/fixtures/payment-requests.fixture.ts new file mode 100644 index 000000000..cd895dda6 --- /dev/null +++ b/packages/reva-api/test/fixtures/payment-requests.fixture.ts @@ -0,0 +1,15 @@ +export const PAYMENT_REQUEST = { + individualEffectiveHourCount: 0, + individualEffectiveCost: 0, + collectiveEffectiveHourCount: 0, + collectiveEffectiveCost: 0, + mandatoryTrainingsEffectiveHourCount: 0, + mandatoryTrainingsEffectiveCost: 0, + basicSkillsEffectiveHourCount: 0, + basicSkillsEffectiveCost: 0, + certificateSkillsEffectiveHourCount: 0, + certificateSkillsEffectiveCost: 0, + otherTrainingEffectiveHourCount: 0, + otherTrainingEffectiveCost: 0, + invoiceNumber: "Invoice-001", +};