b3a7f98e5a
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
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { sql } from "kysely";
|
|
import { it, expect, beforeEach, afterEach } from "vitest";
|
|
|
|
import { handleContentCreate } from "../../src/api/index.js";
|
|
import { emdashLoader } from "../../src/loader.js";
|
|
import { runWithContext } from "../../src/request-context.js";
|
|
import {
|
|
describeEachDialect,
|
|
setupForDialectWithCollections,
|
|
teardownForDialect,
|
|
type DialectTestContext,
|
|
} from "../utils/test-db.js";
|
|
|
|
describeEachDialect("Loader scheduled-post visibility (#917)", (dialect) => {
|
|
let ctx: DialectTestContext;
|
|
|
|
beforeEach(async () => {
|
|
ctx = await setupForDialectWithCollections(dialect);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await teardownForDialect(ctx);
|
|
});
|
|
|
|
// Bypass repo.schedule()'s past-date guard so we can simulate the
|
|
// "scheduled time elapsed, cron hasn't promoted to published yet" state.
|
|
async function scheduledPost(title: string, scheduledAt: string): Promise<string> {
|
|
const r = await handleContentCreate(ctx.db, "post", { data: { title }, status: "draft" });
|
|
const { id, slug } = r.data!.item;
|
|
await sql`UPDATE ec_post SET status = 'scheduled', scheduled_at = ${scheduledAt} WHERE id = ${id}`.execute(
|
|
ctx.db,
|
|
);
|
|
return slug;
|
|
}
|
|
|
|
async function publishedSlugs(): Promise<string[]> {
|
|
const loader = emdashLoader();
|
|
const r = await runWithContext({ editMode: false, db: ctx.db }, () =>
|
|
loader.loadCollection!({ filter: { type: "post" } }),
|
|
);
|
|
return ("entries" in r ? (r.entries ?? []) : []).map((e) => e.slug);
|
|
}
|
|
|
|
it("should include scheduled posts whose scheduled_at has passed", async () => {
|
|
const slug = await scheduledPost("past", new Date(Date.now() - 1000).toISOString());
|
|
expect(await publishedSlugs()).toContain(slug);
|
|
});
|
|
|
|
it("should exclude scheduled posts whose scheduled_at is still in the future", async () => {
|
|
const slug = await scheduledPost("future", new Date(Date.now() + 3_600_000).toISOString());
|
|
expect(await publishedSlugs()).not.toContain(slug);
|
|
});
|
|
});
|