Skip to content

Commit f000283

Browse files
committed
clean up tests
1 parent a612394 commit f000283

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

packages/orm-cli/src/commands/db-migrate.test.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
55
import yargs from "yargs";
66

77
import { orm, sql } from "@casekit/orm";
8+
import { unindent } from "@casekit/unindent";
89

910
import { globalOptions } from "#options.js";
1011
import { OrmCLIConfig } from "#types.js";
@@ -80,11 +81,17 @@ describe("db migrate", () => {
8081
`${migrationsPath}/${migrations[0]}`,
8182
"utf8",
8283
) as string;
83-
expect(content).toContain(`CREATE SCHEMA IF NOT EXISTS "${schema}"`);
84-
expect(content).toContain(`CREATE TABLE "${schema}"."user"`);
85-
expect(content).toContain('"id" uuid');
86-
expect(content).toContain('"email" text');
87-
expect(content).toContain('"name" text');
84+
85+
expect(content).toEqual(unindent`
86+
CREATE SCHEMA IF NOT EXISTS "${schema}";
87+
88+
CREATE TABLE "${schema}"."user" (
89+
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
90+
"email" text NOT NULL,
91+
"name" text,
92+
PRIMARY KEY ("id")
93+
);
94+
` + "\n");
8895
});
8996

9097
test("runs pending migrations", async () => {
@@ -230,9 +237,10 @@ describe("db migrate", () => {
230237
`${migrationsPath}/${migrations[0]}`,
231238
"utf8",
232239
) as string;
233-
expect(content).toContain("ALTER TABLE");
234-
expect(content).toContain("ADD COLUMN");
235-
expect(content).toContain('"createdAt"');
240+
241+
expect(content).toEqual(unindent`
242+
ALTER TABLE "${schema}"."user" ADD COLUMN "createdAt" timestamptz NOT NULL DEFAULT now();
243+
` + "\n");
236244
});
237245

238246
test("multiple migrations are applied in order", async () => {
@@ -279,8 +287,10 @@ describe("db migrate", () => {
279287
[schema],
280288
);
281289

282-
expect(tables.rows.map((r) => r.table_name)).toContain("first_table");
283-
expect(tables.rows.map((r) => r.table_name)).toContain("second_table");
290+
expect(tables.rows.map((r) => r.table_name)).toEqual([
291+
"first_table",
292+
"second_table",
293+
]);
284294

285295
const migrationRecords = await db.query(`
286296
SELECT name FROM public._orm_migrations ORDER BY id

0 commit comments

Comments
 (0)