All checks were successful
Validation applicative / TypeScript, tests et build (push) Successful in 5m21s
59 lines
2.9 KiB
TypeScript
59 lines
2.9 KiB
TypeScript
import express from "express";
|
|
import request from "supertest";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
vi.mock("./_core/sdk", () => ({ sdk: { authenticateRequest: vi.fn() } }));
|
|
vi.mock("./db", () => ({ importMasseSalariale: vi.fn() }));
|
|
vi.mock("./masseSalarialeWorkbookImport", () => ({ parseMasseSalarialeWorkbookBuffer: vi.fn() }));
|
|
|
|
import { sdk } from "./_core/sdk";
|
|
import { importMasseSalariale } from "./db";
|
|
import { registerMasseSalarialeHttpRoutes } from "./masseSalarialeHttp";
|
|
import { parseMasseSalarialeWorkbookBuffer } from "./masseSalarialeWorkbookImport";
|
|
|
|
function makeApp() {
|
|
const app = express();
|
|
registerMasseSalarialeHttpRoutes(app);
|
|
return app;
|
|
}
|
|
|
|
describe("route HTTP d'import Masse salariale", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("interdit l'import Excel à un profil non administrateur", async () => {
|
|
(sdk.authenticateRequest as ReturnType<typeof vi.fn>).mockResolvedValue({ id: 2, role: "standard" });
|
|
|
|
await request(makeApp())
|
|
.post("/api/masse-salariale/previsionnels")
|
|
.attach("file", Buffer.from("PK\x03\x04 fichier Excel"), { filename: "masse.xlsx", contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" })
|
|
.expect(403);
|
|
|
|
expect(importMasseSalariale).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("importe un fichier Excel administrateur sans transmettre son contenu au client", async () => {
|
|
(sdk.authenticateRequest as ReturnType<typeof vi.fn>).mockResolvedValue({ id: 1, role: "admin" });
|
|
(parseMasseSalarialeWorkbookBuffer as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
salaries: [{ matricule: "000001", nom: "NOM", prenom: "PRENOM", poste: "Poste", dateEmbauche: "2024-01-01" }],
|
|
remunerations: [{
|
|
matricule: "000001", annee: 2026, nature: "previsionnel", salaireAnnuelBrutHorsPrimesCents: 100_000,
|
|
salaireAnnuelBrutAvecPrimesCents: 110_000, salaireMensuelBrutHorsPrimesCents: 8_333,
|
|
tauxChargeBps: 4_500, primeAstreinteCents: 10_000, primeCents: 0, primeReferenceCents: 0,
|
|
evolutionCents: 0, evolutionReferenceCents: 0, periodeReference: "2026-08", statut: "previsionnel", source: "fichier_modele_2026-08-28",
|
|
}],
|
|
});
|
|
(importMasseSalariale as ReturnType<typeof vi.fn>).mockResolvedValue({ salaries: 1, remunerations: 1 });
|
|
|
|
const response = await request(makeApp())
|
|
.post("/api/masse-salariale/previsionnels")
|
|
.attach("file", Buffer.from("PK\x03\x04 fichier Excel"), { filename: "masse.xlsx", contentType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" })
|
|
.expect(200);
|
|
|
|
expect(importMasseSalariale).toHaveBeenCalledWith(expect.any(Array), expect.any(Array), { replaceForecastYears: [2025, 2026, 2027] });
|
|
expect(response.body).toEqual({ salaries: 1, remunerations: 1, years: [2025, 2026, 2027] });
|
|
expect(JSON.stringify(response.body)).not.toContain("000001");
|
|
});
|
|
});
|