Add a client-safe ROUTINE_EVENT_TYPES list (game:tick, economy:tick, market:auto-generate) and hide those types on /events behind an off-by-default Routine ticks switch. The dashboard always excludes them so real events fill the recent list. Tick bins now skip no-op emissions: game tick requires shipment, construction, or production activity; market tick requires an expiry or generation; economy tick requires processed items or errors. Historical events stay in the database and remain visible via the toggle or the admin panel.
82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
import { getPayload, type 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, type EventType } from "@/utils/event-log/eventTypes";
|
|
import {
|
|
ROUTINE_EVENT_TYPES,
|
|
excludeRoutineEventsWhere,
|
|
isRoutineEventType,
|
|
} from "@/utils/event-log/routine";
|
|
|
|
let payload: Payload;
|
|
|
|
const RUN = `evlogroutine-${Date.now().toString(36)}`;
|
|
const TIMEOUT = 30_000;
|
|
const eventIds: number[] = [];
|
|
|
|
describe("routine event classification (pure)", () => {
|
|
it("marks tick summaries as routine", () => {
|
|
expect(isRoutineEventType(EventTypes.GameTick)).toBe(true);
|
|
expect(isRoutineEventType(EventTypes.EconomyTick)).toBe(true);
|
|
expect(isRoutineEventType(EventTypes.MarketAutoGenerate)).toBe(true);
|
|
expect(ROUTINE_EVENT_TYPES).toHaveLength(3);
|
|
});
|
|
|
|
it("leaves player-facing events visible", () => {
|
|
expect(isRoutineEventType(EventTypes.MinigameFlappy)).toBe(false);
|
|
expect(isRoutineEventType(EventTypes.StoryBeatRead)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("routine event filtering (database)", () => {
|
|
beforeAll(async () => {
|
|
payload = await getPayload({ config: await config });
|
|
}, TIMEOUT);
|
|
|
|
afterAll(async () => {
|
|
if (!payload) return;
|
|
for (const id of eventIds) {
|
|
await payload
|
|
.delete({ collection: "game-event-logs", id, overrideAccess: true })
|
|
.catch(() => {});
|
|
}
|
|
});
|
|
|
|
const emit = async (type: EventType, message: string): Promise<number> => {
|
|
await emitGameEvent(payload, { type, message });
|
|
const res = await payload.find({
|
|
collection: "game-event-logs",
|
|
where: { message: { equals: message } },
|
|
sort: "-id",
|
|
limit: 1,
|
|
overrideAccess: true,
|
|
depth: 0,
|
|
});
|
|
const doc = res.docs[0];
|
|
expect(doc).toBeDefined();
|
|
eventIds.push(doc.id);
|
|
return doc.id;
|
|
};
|
|
|
|
it("excludes routine types and keeps the rest", async () => {
|
|
const ids = [
|
|
await emit(EventTypes.GameTick, `${RUN}-game-tick`),
|
|
await emit(EventTypes.EconomyTick, `${RUN}-economy-tick`),
|
|
await emit(EventTypes.MarketAutoGenerate, `${RUN}-market-generate`),
|
|
await emit(EventTypes.MinigameFlappy, `${RUN}-flappy`),
|
|
];
|
|
|
|
const filtered = await payload.find({
|
|
collection: "game-event-logs",
|
|
where: { and: [{ id: { in: ids } }, excludeRoutineEventsWhere()] },
|
|
limit: ids.length,
|
|
overrideAccess: true,
|
|
depth: 0,
|
|
});
|
|
|
|
expect(filtered.docs.map((doc) => doc.type)).toEqual([EventTypes.MinigameFlappy]);
|
|
});
|
|
});
|