All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import "../../setup.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
import { canonicalizeUrl } from "../../../lib/canonical-url.ts";
|
|
import { up as up0013 } from "../../../db/migrations/0013_dump_url_canonical.ts";
|
|
import { DatabaseSync } from "node:sqlite";
|
|
|
|
// Migration 0013 carries a frozen copy of the canonicalizer to backfill old
|
|
// rows. Until the rules change on purpose (with a new backfill migration), the
|
|
// two must agree, or rows from before and after the migration won't match.
|
|
Deno.test("migration 0013 backfills the same keys canonicalizeUrl computes", () => {
|
|
const urls = [
|
|
"http://www.example.com/a/?utm_source=x&b=2&a=1#top",
|
|
"https://youtu.be/abc123?t=5",
|
|
"https://www.youtube.com/playlist?list=PLx",
|
|
"https://app.example.com/#/route",
|
|
];
|
|
const db = new DatabaseSync(":memory:");
|
|
db.exec(`CREATE TABLE dumps (id TEXT PRIMARY KEY, url TEXT);`);
|
|
urls.forEach((url, i) =>
|
|
db.prepare(`INSERT INTO dumps (id, url) VALUES (?, ?);`).run(String(i), url)
|
|
);
|
|
up0013(db);
|
|
up0013(db); // idempotent
|
|
const rows = db.prepare(`SELECT id, url_canonical FROM dumps ORDER BY id;`)
|
|
.all() as { id: string; url_canonical: string }[];
|
|
assertEquals(
|
|
rows.map((r) => r.url_canonical),
|
|
urls.map(canonicalizeUrl),
|
|
);
|
|
db.close();
|
|
});
|