-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1090ac
commit ced869a
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { connectToDb, disconnectFromDb } from "./db.js"; | ||
|
||
export default async function createDatabase() { | ||
await connectToDb(":memory:"); | ||
|
||
return async () => { | ||
await disconnectFromDb(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
import { describe, expect, test } from "bun:test"; | ||
import { describe, expect, test, beforeEach } from "bun:test"; | ||
|
||
import createDatabase from "../storage/db/database-test-init.js"; | ||
|
||
import db from "@db"; | ||
|
||
describe("smoke", () => { | ||
test("does math still hold?", () => { | ||
expect(1 + 1).toBe(2); | ||
}); | ||
}); | ||
|
||
describe("database smoke", () => { | ||
beforeEach(createDatabase); | ||
|
||
test("does database work?", async () => { | ||
const res = await db() | ||
.insertInto("birthdays") | ||
.values({ | ||
day: 1, | ||
month: 2, | ||
userId: "12345", | ||
}) | ||
.returningAll() | ||
.executeTakeFirstOrThrow(); | ||
|
||
expect(res).toMatchObject({ | ||
day: 1, | ||
month: 2, | ||
userId: "12345", | ||
}); | ||
|
||
const res2 = await db().selectFrom("birthdays").selectAll().executeTakeFirstOrThrow(); | ||
expect(res).toStrictEqual(res2); | ||
}); | ||
}); |