chore: import upstream snapshot with attribution
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
CI / E2E Cloudflare (4/8) (push) Failing after 0s
CI / E2E Cloudflare (8/8) (push) Failing after 1s
CI / Lint (push) Failing after 1s
Auto Extract / Extract (push) Failing after 4s
CI / Version Check (push) Failing after 9s
CI / Integration Tests (push) Failing after 1s
CI / E2E tests (1/8) (push) Failing after 1s
CI / E2E tests (2/8) (push) Failing after 2s
CI / E2E tests (3/8) (push) Failing after 2s
CI / Browser Tests (push) Failing after 1s
CI / E2E tests (5/8) (push) Failing after 1s
CI / E2E Cloudflare (2/8) (push) Failing after 2s
CI / Typecheck (push) Failing after 1s
CI / Changeset Validation (push) Failing after 2s
CI / E2E Cloudflare (5/8) (push) Failing after 1s
CI / E2E Cloudflare (6/8) (push) Failing after 1s
CI / E2E Cloudflare (7/8) (push) Failing after 1s
CodeQL / Analyze (javascript-typescript) (push) Failing after 1s
Format / Format (push) Failing after 0s
CodeQL / Analyze (actions) (push) Failing after 4s
CI / E2E tests (4/8) (push) Failing after 1s
CI / E2E tests (6/8) (push) Failing after 1s
CI / E2E tests (7/8) (push) Failing after 2s
CI / E2E tests (8/8) (push) Failing after 1s
CI / E2E Cloudflare (1/8) (push) Failing after 1s
CI / E2E Cloudflare (3/8) (push) Failing after 2s
Preview Releases / Publish Preview (push) Failing after 0s
zizmor / Run zizmor (push) Failing after 1s
Release / Release (push) Failing after 2s
CI / Smoke Tests (push) Failing after 5m36s
CI / Tests (push) Failing after 6m36s
Release / Sync Templates (push) Has been skipped
CI / E2E Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Dev-bypass seed gating.
|
||||
*
|
||||
* The route seeds sample data by default; `?content=0` (or `false`) applies
|
||||
* schema/structure only so an agent or test harness can start from a clean
|
||||
* site without deleting seeded entries afterwards.
|
||||
*/
|
||||
|
||||
import type { APIContext } from "astro";
|
||||
import type { Kysely } from "kysely";
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
|
||||
import { ContentRepository } from "../../../src/database/repositories/content.js";
|
||||
import type { Database } from "../../../src/database/types.js";
|
||||
import type { SeedFile } from "../../../src/seed/types.js";
|
||||
import { setupTestDatabase, teardownTestDatabase } from "../../utils/test-db.js";
|
||||
|
||||
const fixtureSeed: SeedFile = {
|
||||
version: "1",
|
||||
settings: { title: "Fixture Site" },
|
||||
collections: [
|
||||
{
|
||||
slug: "posts",
|
||||
label: "Posts",
|
||||
fields: [{ slug: "title", label: "Title", type: "string" }],
|
||||
},
|
||||
],
|
||||
taxonomies: [
|
||||
{
|
||||
name: "tags",
|
||||
label: "Tags",
|
||||
hierarchical: false,
|
||||
collections: ["posts"],
|
||||
terms: [{ slug: "sample-tag", label: "Sample Tag" }],
|
||||
},
|
||||
],
|
||||
bylines: [{ id: "sample", slug: "sample-author", displayName: "Sample Author" }],
|
||||
content: {
|
||||
posts: [{ id: "post-1", slug: "sample-post", data: { title: "Sample Post" } }],
|
||||
},
|
||||
menus: [
|
||||
{
|
||||
name: "primary",
|
||||
label: "Primary",
|
||||
items: [{ type: "custom", label: "Home", url: "/" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
vi.mock("virtual:emdash/seed", () => ({ seed: fixtureSeed, userSeed: null }), { virtual: true });
|
||||
|
||||
import { GET } from "../../../src/astro/routes/api/setup/dev-bypass.js";
|
||||
|
||||
function makeContext(db: Kysely<Database>, search = ""): APIContext {
|
||||
return {
|
||||
locals: { emdash: { db, storage: null, config: {} } },
|
||||
url: new URL(`http://localhost:4321/_emdash/api/setup/dev-bypass${search}`),
|
||||
session: undefined,
|
||||
} as unknown as APIContext;
|
||||
}
|
||||
|
||||
async function countPosts(db: Kysely<Database>) {
|
||||
const { items } = await new ContentRepository(db).findMany("posts", {});
|
||||
return items.length;
|
||||
}
|
||||
|
||||
async function countRows(db: Kysely<Database>, table: "taxonomies" | "_emdash_bylines") {
|
||||
const rows = await db.selectFrom(table).select("id").execute();
|
||||
return rows.length;
|
||||
}
|
||||
|
||||
describe("setup dev-bypass seed gating", () => {
|
||||
let db: Kysely<Database>;
|
||||
|
||||
beforeEach(async () => {
|
||||
db = await setupTestDatabase();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await teardownTestDatabase(db);
|
||||
});
|
||||
|
||||
it("seeds sample data by default", async () => {
|
||||
const response = await GET(makeContext(db));
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
expect(await countPosts(db)).toBe(1);
|
||||
expect(await countRows(db, "taxonomies")).toBe(1);
|
||||
expect(await countRows(db, "_emdash_bylines")).toBe(1);
|
||||
});
|
||||
|
||||
it("applies schema only with ?content=0", async () => {
|
||||
const response = await GET(makeContext(db, "?content=0"));
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
expect(await countPosts(db)).toBe(0);
|
||||
expect(await countRows(db, "taxonomies")).toBe(0);
|
||||
expect(await countRows(db, "_emdash_bylines")).toBe(0);
|
||||
|
||||
// Schema and structure still apply
|
||||
const collections = await db
|
||||
.selectFrom("_emdash_collections")
|
||||
.select("slug")
|
||||
.where("slug", "=", "posts")
|
||||
.execute();
|
||||
expect(collections).toHaveLength(1);
|
||||
|
||||
const taxonomyDefs = await db
|
||||
.selectFrom("_emdash_taxonomy_defs")
|
||||
.select("name")
|
||||
.where("name", "=", "tags")
|
||||
.execute();
|
||||
expect(taxonomyDefs).toHaveLength(1);
|
||||
|
||||
const menus = await db
|
||||
.selectFrom("_emdash_menus")
|
||||
.select("name")
|
||||
.where("name", "=", "primary")
|
||||
.execute();
|
||||
expect(menus).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("accepts ?content=false", async () => {
|
||||
const response = await GET(makeContext(db, "?content=false"));
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
expect(await countPosts(db)).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user