1
0
Fork 0
polaris-task-force/tests/int/event-log-discord-flag.int.spec.ts
Z8MB1E 88e89c9e55 feat(npc-dialogue): post opted-in event effects to Discord dispatch channel
Event nodes gain a 'Post this event to the Discord NPC dispatch channel'
checkbox. The flag rides emit() onto game_event_logs (discordRequested +
announcement bookkeeping columns, migration add_event_log_discord_fields),
and a new bot poller stamps pending rows into an amber NPC Dispatch embed
with relative-time mention and a link back to the source contact.

Bot delivery itself is unverifiable locally (no Discord token or channel id
in dev); the DB-side contract is covered by an integration test and a live
probe walk confirmed discord_requested persists end to end.
2026-10-14 16:57:33 -04:00

79 lines
2.1 KiB
TypeScript

import { getPayload, Payload } from "payload";
import config from "@/payload.config";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { emitGameEvent } from "@/utils/event-log/emit";
import { EventTypes } from "@/utils/event-log/eventTypes";
let payload: Payload;
const RUN = `evdisc-${Date.now().toString(36)}`;
const TIMEOUT = 30_000;
const eventIds: number[] = [];
/** Emit an event and return its persisted document. */
async function emit(input: Parameters<typeof emitGameEvent>[1]) {
await emitGameEvent(payload, input);
const res = await payload.find({
collection: "game-event-logs",
where: { message: { equals: input.message } },
sort: "-id",
limit: 1,
overrideAccess: true,
depth: 0,
});
const doc = res.docs[0];
expect(doc).toBeDefined();
eventIds.push(doc.id);
return doc;
}
describe("discordRequested flag on game events", () => {
beforeAll(async () => {
payload = await getPayload({ config });
}, TIMEOUT);
afterAll(async () => {
for (const id of eventIds) {
await payload
.delete({ collection: "game-event-logs", id, overrideAccess: true })
.catch(() => {});
}
});
it(
"persists discordRequested when the emitter opts in",
async () => {
const doc = await emit({
type: EventTypes.NpcDialogue,
message: `${RUN} opted in`,
discordRequested: true,
});
expect(doc.discordRequested).toBe(true);
// The bot stamps these only after posting; emitting must leave them clear.
expect(doc.discordAnnouncedAt).toBeFalsy();
expect(doc.discordMessageId).toBeFalsy();
},
TIMEOUT,
);
it(
"defaults to false when omitted or explicitly false",
async () => {
const omitted = await emit({
type: EventTypes.NpcDialogue,
message: `${RUN} omitted`,
});
expect(omitted.discordRequested).toBe(false);
const explicitFalse = await emit({
type: EventTypes.NpcDialogue,
message: `${RUN} explicit false`,
discordRequested: false,
});
expect(explicitFalse.discordRequested).toBe(false);
},
TIMEOUT,
);
});