Adds reconcileModlistBuffer, which resends the modlist-updated message once per Scheduled mission with a modlist attached, when its start is within DISCORD_MODLIST_BUFFER_HOURS (default 8). Tracked by the new discordModlistBufferSentAt marker, so it is independent of the roll-call modlist sync. Also fixes type errors in modlist-file-access.int.spec.ts.
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { getTestPayload } from "../helpers/get-test-payload";
|
|
import { Payload } from "payload";
|
|
|
|
import type { AccessArgs, AccessResult } from "payload";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
|
|
import { ModLists } from "@/collections/server/ModLists";
|
|
import { scopedAdminPageAccess } from "@/utils/access-control/divisionAccess";
|
|
|
|
let payload: Payload;
|
|
|
|
const TIMEOUT = 30_000;
|
|
|
|
/**
|
|
* Replicate the production wrapping exactly: payload.config.ts maps every
|
|
* collection through `scopedAdminPageAccess(slug, read)`, and the file-serving
|
|
* route (`/api/mod-lists/file/<name>`) invokes `read` with
|
|
* `isReadingStaticFile: true`. The vitest environment has no Next.js HTTP
|
|
* server, so invoking the access function directly is the standard way to
|
|
* unit-test Payload access control (see admin-page-access.int.spec.ts).
|
|
*/
|
|
const readAccess = scopedAdminPageAccess(ModLists.slug, ModLists.access?.read) as (
|
|
args: AccessArgs,
|
|
) => Promise<AccessResult>;
|
|
|
|
/**
|
|
* A synthetic args object: non-admin pathname (REST/file route), no auth cookie.
|
|
* `isReadingStaticFile` is a sibling of `req` (Payload builds
|
|
* `{ data, isReadingStaticFile, req }` for the file route), not nested in `req`.
|
|
*/
|
|
const anonReq = (pathname: string, isReadingStaticFile?: boolean): AccessArgs =>
|
|
({
|
|
isReadingStaticFile,
|
|
req: { user: null, payload, pathname },
|
|
}) as unknown as AccessArgs;
|
|
|
|
describe("ModLists file access", () => {
|
|
beforeAll(async () => {
|
|
payload = await getTestPayload();
|
|
}, TIMEOUT);
|
|
|
|
afterAll(async () => {
|
|
// Nothing persists.
|
|
});
|
|
|
|
it(
|
|
"lets anyone with the link download the preset without signing in",
|
|
async () => {
|
|
// The file-serving route runs read with isReadingStaticFile: true.
|
|
const result = await readAccess(anonReq("/api/mod-lists/file/x.html", true));
|
|
expect(result).toBe(true);
|
|
},
|
|
TIMEOUT,
|
|
);
|
|
|
|
it(
|
|
"still requires mod-lists:read for anonymous REST and admin-panel reads",
|
|
async () => {
|
|
// A logged-out REST read of the document metadata is denied.
|
|
const api = await readAccess(anonReq("/api/mod-lists/1"));
|
|
expect(api).toBe(false);
|
|
|
|
// The admin-panel path keeps its permission gate (no user → denied).
|
|
const admin = await readAccess(anonReq("/admin/collections/mod-lists", true));
|
|
expect(admin).toBe(false);
|
|
},
|
|
TIMEOUT,
|
|
);
|
|
});
|