feat: purger les contenus expirés ou anciens
This commit is contained in:
@@ -10,11 +10,23 @@ vi.mock("./db", async () => {
|
||||
getVeilleDistinctValues: vi.fn(async () => ({ categories: [], niveaux: [], territoires: [] })),
|
||||
getAapItems: vi.fn(async () => ({ items: [], total: 0 })),
|
||||
getAapDistinctValues: vi.fn(async () => ({ regions: [], departements: [] })),
|
||||
purgeVeilleItems: vi.fn(async () => 12),
|
||||
purgeVeilleItemsOlderThan: vi.fn(async () => 4),
|
||||
purgeAapItems: vi.fn(async () => 9),
|
||||
purgeExpiredAapItems: vi.fn(async () => 3),
|
||||
purgeAapItemsOlderThan: vi.fn(async () => 2),
|
||||
};
|
||||
});
|
||||
|
||||
import { appRouter } from "./routers";
|
||||
import type { TrpcContext } from "./_core/context";
|
||||
import {
|
||||
purgeAapItems,
|
||||
purgeAapItemsOlderThan,
|
||||
purgeExpiredAapItems,
|
||||
purgeVeilleItems,
|
||||
purgeVeilleItemsOlderThan,
|
||||
} from "./db";
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -128,6 +140,36 @@ describe("protection admin", () => {
|
||||
const caller = appRouter.createCaller(ctx);
|
||||
await expect(caller.rss.classificationErrors({ page: 1, pageSize: 25 })).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("refuse les purges ciblées pour un non admin", async () => {
|
||||
const caller = appRouter.createCaller(makeUserCtx());
|
||||
await expect(caller.veille.purge({ scope: "older_than", months: 6 })).rejects.toThrow();
|
||||
await expect(caller.aap.purge({ scope: "expired" })).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("purges administrateur", () => {
|
||||
beforeEach(() => vi.clearAllMocks());
|
||||
|
||||
it("applique la durée choisie à la veille", async () => {
|
||||
const result = await appRouter.createCaller(makeAdminCtx()).veille.purge({ scope: "older_than", months: 6 });
|
||||
expect(purgeVeilleItemsOlderThan).toHaveBeenCalledWith(6);
|
||||
expect(purgeVeilleItems).not.toHaveBeenCalled();
|
||||
expect(result).toMatchObject({ success: true, deleted: 4, scope: "older_than", months: 6 });
|
||||
});
|
||||
|
||||
it("supprime uniquement les AAP clôturés lorsque demandé", async () => {
|
||||
const result = await appRouter.createCaller(makeAdminCtx()).aap.purge({ scope: "expired" });
|
||||
expect(purgeExpiredAapItems).toHaveBeenCalledOnce();
|
||||
expect(purgeAapItems).not.toHaveBeenCalled();
|
||||
expect(purgeAapItemsOlderThan).not.toHaveBeenCalled();
|
||||
expect(result).toMatchObject({ success: true, deleted: 3, scope: "expired", months: null });
|
||||
});
|
||||
|
||||
it("refuse une purge par ancienneté sans durée", async () => {
|
||||
const caller = appRouter.createCaller(makeAdminCtx());
|
||||
await expect(caller.aap.purge({ scope: "older_than" } as never)).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Tests accès public ───────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user