Skip to content

Commit

Permalink
tests: Add some tests (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
iNeoO authored Jul 18, 2024
1 parent 3fb9bfe commit 4b48c0e
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/frontend-bo/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineNuxtConfig({
"@gouvminint/vue-dsfr/styles",
"@gouvfr/dsfr/dist/utility/icons/icons.min.css",
"@/assets/css/main.css",
"@nuxt/test-utils/module",
],
modules: [
"nuxt-security",
Expand Down
9 changes: 7 additions & 2 deletions packages/frontend-bo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"lint": "eslint --fix ./src"
"lint": "eslint --fix ./src",
"test": "vitest"
},
"dependencies": {
"@gouvfr/dsfr": "~1.11.2",
Expand All @@ -33,14 +34,18 @@
},
"devDependencies": {
"@nuxt/eslint-config": "^0.3.6",
"@nuxt/test-utils": "^3.13.1",
"@socialgouv/eslint-config-recommended": "^1.131.0",
"@vue/test-utils": "^2.4.6",
"eslint": "^8.57.0",
"eslint-plugin-prettier": "^5.1.3",
"happy-dom": "^14.12.3",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"sass": "~1.77.0",
"sass-loader": "~14.2.0",
"typescript": "~5.4.3"
"typescript": "~5.4.3",
"vitest": "^2.0.1"
},
"lint-staged": {
"src/**/*.{js,vue,ts}": "npx eslint --cache --fix"
Expand Down
88 changes: 88 additions & 0 deletions packages/frontend-bo/src/utils/demandes-sejours.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { describe, it, expect } from "vitest";
import demandeSejours from "./demandes-sejours";

import { organisme } from "#imports";

describe("getSaison", () => {
it("should return Hiver for dates in January", () => {
const demande = { dateDebut: "2023-01-15" };
expect(demandeSejours.getSaison(demande)).toBe("Hiver");
});

it("should return Printemps for dates in April", () => {
const demande = { dateDebut: "2023-04-15" };
expect(demandeSejours.getSaison(demande)).toBe("Printemps");
});

it("should return Eté for dates in July", () => {
const demande = { dateDebut: "2023-07-15" };
expect(demandeSejours.getSaison(demande)).toBe("Eté");
});

it("should return Automne for dates in October", () => {
const demande = { dateDebut: "2023-10-15" };
expect(demandeSejours.getSaison(demande)).toBe("Automne");
});

it("should return undefined if dateDebut is missing", () => {
const demande = {};
expect(demandeSejours.getSaison(demande)).toBeUndefined();
});
});

describe("isDeclaration8Jours", () => {
it("should return true for TRANSMISE_8J status", () => {
expect(
demandeSejours.isDeclaration8Jours(demandeSejours.statuts.TRANSMISE_8J),
).toBe(true);
});

it("should return true for VALIDEE_8J status", () => {
expect(
demandeSejours.isDeclaration8Jours(demandeSejours.statuts.VALIDEE_8J),
).toBe(true);
});

it("should return false for a non-8J status", () => {
expect(demandeSejours.isDeclaration8Jours("ANOTHER_STATUS")).toBe(false);
});
});

describe("getOrganismeTitle", () => {
it("should return the full name for a PERSONNE_PHYSIQUE", () => {
const demande = {
typeOrganisme: organisme.type.PERSONNE_PHYSIQUE,
personnePhysique: {
prenom: "John",
nomUsage: "Doe",
nomNaissance: "Smith",
},
};
expect(demandeSejours.getOrganismeTitle(demande)).toBe("John Doe");
});

it("should return the birth name if nomUsage is missing for a PERSONNE_PHYSIQUE", () => {
const demande = {
typeOrganisme: organisme.type.PERSONNE_PHYSIQUE,
personnePhysique: { prenom: "John", nomNaissance: "Smith" },
};
expect(demandeSejours.getOrganismeTitle(demande)).toBe("John Smith");
});

it("should return the raisonSociale for a PERSONNE_MORALE", () => {
const demande = {
typeOrganisme: organisme.type.PERSONNE_MORALE,
personneMorale: { raisonSociale: "Acme Corp" },
};
expect(demandeSejours.getOrganismeTitle(demande)).toBe("Acme Corp");
});
});

describe("getDateDebutFin", () => {
it("should return the formatted date range", () => {
const demande = { dateDebut: "2023-07-01", dateFin: "2023-07-15" };
expect(demandeSejours.getDateDebutFin(demande)).toBe(
"01/07/2023 - 15/07/2023",
);
});
});
7 changes: 7 additions & 0 deletions packages/frontend-bo/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineVitestConfig } from "@nuxt/test-utils/config";

export default defineVitestConfig({
test: {
environment: "nuxt",
},
});
Loading

0 comments on commit 4b48c0e

Please sign in to comment.