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>
29 lines
958 B
TypeScript
29 lines
958 B
TypeScript
import "../../setup.ts";
|
|
import { assertEquals } from "@std/assert";
|
|
import { DatabaseSync } from "node:sqlite";
|
|
import { up as up0004 } from "../../../db/migrations/0004_user_roles.ts";
|
|
import { up as up0005 } from "../../../db/migrations/0005_drop_is_admin.ts";
|
|
|
|
Deno.test("0004/0005: is_admin becomes role, then goes", () => {
|
|
const db = new DatabaseSync(":memory:");
|
|
db.exec(
|
|
`CREATE TABLE users (id TEXT PRIMARY KEY, is_admin INTEGER NOT NULL DEFAULT 0);`,
|
|
);
|
|
db.exec(`INSERT INTO users (id, is_admin) VALUES ('a', 1), ('b', 0);`);
|
|
up0004(db);
|
|
up0004(db);
|
|
up0005(db);
|
|
up0005(db);
|
|
assertEquals(
|
|
db.prepare(`SELECT id, role FROM users ORDER BY id;`).all().map((r) => ({
|
|
...r,
|
|
})),
|
|
[{ id: "a", role: "admin" }, { id: "b", role: "user" }],
|
|
);
|
|
const cols =
|
|
(db.prepare(`PRAGMA table_info(users);`).all() as { name: string }[])
|
|
.map((c) => c.name);
|
|
assertEquals(cols, ["id", "role"]);
|
|
db.close();
|
|
});
|