Skip to article
Documentation

e2e/demo-fixture.ts

Linked repository file from this build.

import "dotenv/config";
import { reviewKey } from "../src/features/reviews/review-key";
import { demoActor } from "../src/lib/auth/roster";
import type { SnapReview } from "../src/programs/snap-negative/types";
import { createDemoSeed } from "../src/programs/snap-negative/seed";

/** Restore only the editable demo fixture; keep history and the rest of the FFY seed. */
export async function resetDemoFixture() {
  return appendDemoFixture(createDemoSeed());
}

/** Install an explicit historic workflow fixture without enabling new production transitions. */
export async function appendDemoFixture(review: SnapReview) {
  if (reviewKey(review) !== reviewKey(createDemoSeed()))
    throw new Error("E2E fixture setup only accepts the qualified demo review.");
  const url = process.env.DATABASE_URL;
  if (!url || !["localhost", "127.0.0.1"].includes(new URL(url).hostname)) {
    throw new Error("E2E demo setup requires DATABASE_URL pointing to localhost.");
  }
  const { reviewStore } = await import("../src/lib/db/review-store");
  const current = await reviewStore.load(reviewKey(review));
  const stored = {
    review,
    version: (current?.version ?? 0) + 1,
    requestId: crypto.randomUUID(),
    actor: demoActor("examiner"),
    savedAt: new Date().toISOString(),
  };
  await reviewStore.append(stored);
  return stored;
}