test: move resetDb to own testing lib function
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
import { beforeEach, describe, expect, it } from "bun:test";
|
||||
|
||||
import app from "~/index";
|
||||
import { getTestDb } from "~/libs/test/getTestDb";
|
||||
import { resetTestDb } from "~/libs/test/resetTestDb";
|
||||
import { server } from "~/mocks";
|
||||
import { resetDb } from "~/models/db";
|
||||
import { deviceTokensTable } from "~/models/schema";
|
||||
|
||||
server.listen();
|
||||
@@ -15,7 +15,7 @@ describe("requests the /token route", () => {
|
||||
const db = getTestDb();
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetDb();
|
||||
await resetTestDb();
|
||||
});
|
||||
|
||||
it("should succeed", async () => {
|
||||
|
||||
@@ -3,8 +3,8 @@ import { beforeEach, describe, expect, it } from "bun:test";
|
||||
import app from "~/index";
|
||||
import { getTestDb } from "~/libs/test/getTestDb";
|
||||
import { getTestEnv } from "~/libs/test/getTestEnv";
|
||||
import { resetTestDb } from "~/libs/test/resetTestDb";
|
||||
import { server } from "~/mocks";
|
||||
import { resetDb } from "~/models/db";
|
||||
import { deviceTokensTable } from "~/models/schema";
|
||||
|
||||
server.listen();
|
||||
@@ -13,7 +13,7 @@ describe("requests the /watch-status route", () => {
|
||||
const db = getTestDb();
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetDb();
|
||||
await resetTestDb();
|
||||
});
|
||||
|
||||
it("saving title, deviceId in db, should succeed", async () => {
|
||||
|
||||
11
src/libs/test/resetTestDb.ts
Normal file
11
src/libs/test/resetTestDb.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { tables } from "~/models/schema";
|
||||
|
||||
import { getTestDb } from "./getTestDb";
|
||||
|
||||
export async function resetTestDb() {
|
||||
const db = getTestDb();
|
||||
|
||||
for (const table of tables) {
|
||||
await db.delete(table);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ import { drizzle } from "drizzle-orm/libsql";
|
||||
|
||||
import type { Env } from "~/types/env";
|
||||
|
||||
import { tables } from "./schema";
|
||||
|
||||
type Db = ReturnType<typeof createDb>;
|
||||
let db: Db | null = null;
|
||||
|
||||
@@ -17,14 +15,6 @@ export function getDb(env: Env): Db {
|
||||
return db;
|
||||
}
|
||||
|
||||
export async function resetDb() {
|
||||
if (!db) return;
|
||||
|
||||
for (const table of tables) {
|
||||
await db.delete(table);
|
||||
}
|
||||
}
|
||||
|
||||
function createDb(env: Env) {
|
||||
const client = createClient({
|
||||
url: env.TURSO_URL,
|
||||
|
||||
Reference in New Issue
Block a user