Skip to content

Commit

Permalink
adds a test that runs the db seed, making sure it's compatible with l…
Browse files Browse the repository at this point in the history
…atest schema (#402)

* feat: test seeds the db and asserts >0 students and users. for now this should work, might have to modify the assertions as we go.

* feat: comments

* feat: comments

* fix: comment

* fix: test name as per code review comment

* fix: adding catch block to make the failures cleaner
  • Loading branch information
thomhickey authored Sep 4, 2024
1 parent 7ac442c commit 8aae5f4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/backend/db/lib/seed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import test from "ava";
import { getTestDatabase } from "@/backend/tests/fixtures/get-test-database";
import { getDb } from "@/backend/db/lib/get-db";
import { seedfile } from "@/backend/db/lib/seed";

test("seedfile works with current schema", async (t) => {
// note that this also seeds the database from tests/seed.ts
const { connectionString } = await getTestDatabase();
const { db } = getDb(connectionString);

try {
await seedfile(connectionString); // this runs our production seed file

const students = await db.selectFrom("student").selectAll().execute();
t.true(students.length > 0, "There should be at least one student");

const users = await db.selectFrom("user").selectAll().execute();
t.true(users.length > 0, "There should be at least one user");
} catch (error) {
t.fail(
`Seedfile execution failed: ${
error instanceof Error ? error.message : String(error)
}`
);
} finally {
await db.destroy();
}
});

0 comments on commit 8aae5f4

Please sign in to comment.