Skip to content

Commit

Permalink
refactor(api): payment request and funding request fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDos committed Nov 14, 2024
1 parent 4a8bbe8 commit a3b4bba
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,7 +29,7 @@ beforeAll(async () => {
financeModule: "unifvae",
fundingRequestUnifvae: {
create: {
...fundingRequestSample,
...FUNDING_REQUEST_SAMPLE,
fundingRequestBatchUnifvae: {
create: {
sent: false,
Expand All @@ -50,7 +50,7 @@ beforeAll(async () => {
financeModule: "unifvae",
fundingRequestUnifvae: {
create: {
...fundingRequestSample,
...FUNDING_REQUEST_SAMPLE,
fundingRequestBatchUnifvae: {
create: {
sent: true,
Expand All @@ -71,7 +71,7 @@ beforeAll(async () => {
financeModule: "unifvae",
fundingRequestUnifvae: {
create: {
...fundingRequestSample,
...FUNDING_REQUEST_SAMPLE,
fundingRequestBatchUnifvae: {
create: {
sent: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -94,7 +92,7 @@ const injectGraphqlPaymentRequestCreation = async () =>
arguments: {
candidacyId: CANDIDACY_UNIFVAE.id,
paymentRequest: {
...paymentRequestInputBase,
...PAYMENT_REQUEST,
},
},
},
Expand Down Expand Up @@ -133,7 +131,7 @@ test("should create fundingRequestUnifvae with matching batch", async () => {
arguments: {
candidacyId: CANDIDACY_UNIFVAE.id,
fundingRequest: {
...fundingRequestSample,
...FUNDING_REQUEST_SAMPLE,
},
},
enumFields: ["candidateGender"],
Expand All @@ -146,7 +144,7 @@ test("should create fundingRequestUnifvae with matching batch", async () => {
expect(obj).toMatchObject({
data: {
candidacy_createFundingRequestUnifvae: {
...fundingRequestSample,
...FUNDING_REQUEST_SAMPLE,
},
},
});
Expand All @@ -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
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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),
});
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
Expand All @@ -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),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -142,15 +142,15 @@ 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);
});

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);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
});
Expand All @@ -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),
});
Expand All @@ -28,15 +28,15 @@ 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),
});
expect(errors.length).toBe(0);
});
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),
});
Expand All @@ -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),
});
Expand All @@ -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),
});
Expand All @@ -69,15 +69,15 @@ 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),
});
expect(errors.length).toBe(0);
});
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),
});
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand All @@ -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),
});
Expand Down
Loading

0 comments on commit a3b4bba

Please sign in to comment.