Skip to content

Commit

Permalink
feat(eig): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminDNUM committed Sep 25, 2024
1 parent 3d37e91 commit fab34cd
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions packages/backend/src/helpers/__tests__/eig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const { isDeclarationligibleToEig } = require("../eig");
const { statuts: dsStatuts } = require("../ds-statuts");
const { expect } = require("@playwright/test");

describe("isDeclarationligibleToEig", () => {
const declaration = {
id: 26,
libelle: "declaration1",
dateDebut: "2024-09-01",
dateFin: "2024-09-07",
};

const allStatuts = Object.values(dsStatuts);

const okStatuts = [
dsStatuts.SEJOUR_EN_COURS,
dsStatuts.VALIDEE_8J,
dsStatuts.TERMINEE,
];

const badStatus = allStatuts.filter((s) => !okStatuts.includes(s));

it.each(okStatuts)(
"should return true for statut %p and good date range",
(statut) => {
declaration.statut = statut;
jest.useFakeTimers().setSystemTime(new Date("2024-09-01"));
expect(isDeclarationligibleToEig(declaration)).toBe(true);

jest.useFakeTimers().setSystemTime(new Date("2024-09-06"));
expect(isDeclarationligibleToEig(declaration)).toBe(true);

jest.useFakeTimers().setSystemTime(new Date("2024-09-07"));
expect(isDeclarationligibleToEig(declaration)).toBe(true);

jest.useFakeTimers().setSystemTime(new Date("2024-09-14"));
expect(isDeclarationligibleToEig(declaration)).toBe(true);
},
);

it.each(badStatus)(
"should return false for statut %p and good date range",
(statut) => {
declaration.statut = statut;
jest.useFakeTimers().setSystemTime(new Date("2024-09-01"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);

jest.useFakeTimers().setSystemTime(new Date("2024-09-06"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);

jest.useFakeTimers().setSystemTime(new Date("2024-09-07"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);

jest.useFakeTimers().setSystemTime(new Date("2024-09-14"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);
},
);

it.each(allStatuts)(
"should return false for statut %p and bad date range",
(statut) => {
declaration.statut = statut;
jest.useFakeTimers().setSystemTime(new Date("2024-08-31"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);

jest.useFakeTimers().setSystemTime(new Date("2024-09-15"));
expect(isDeclarationligibleToEig(declaration)).toBe(false);
},
);
});

0 comments on commit fab34cd

Please sign in to comment.