Remove tests afterAll

This commit is contained in:
Zoe Roux 2025-01-28 12:41:20 +01:00
parent 7906374553
commit 740bf7adaa
No known key found for this signature in database
4 changed files with 8 additions and 26 deletions

View File

@ -1,5 +1,4 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies"; import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
@ -7,15 +6,12 @@ import { shows } from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune1984 } from "~/models/examples/dune-1984"; import { dune1984 } from "~/models/examples/dune-1984";
import { dune } from "~/models/examples/dune-2021"; import { dune } from "~/models/examples/dune-2021";
import { createMovie, getMovies, app } from "../helper"; import { app, createMovie, getMovies } from "../helper";
beforeAll(async () => { beforeAll(async () => {
await db.delete(shows); await db.delete(shows);
for (const movie of [bubble, dune1984, dune]) await seedMovie(movie); for (const movie of [bubble, dune1984, dune]) await seedMovie(movie);
}); });
afterAll(async () => {
await db.delete(shows);
});
describe("with a null value", () => { describe("with a null value", () => {
// Those before/after hooks are NOT scopped to the describe due to a bun bug // Those before/after hooks are NOT scopped to the describe due to a bun bug
@ -47,9 +43,6 @@ describe("with a null value", () => {
externalId: {}, externalId: {},
}); });
}); });
afterAll(async () => {
await db.delete(shows).where(eq(shows.slug, "no-air-date"));
});
it("sort by dates desc with a null value", async () => { it("sort by dates desc with a null value", async () => {
let [resp, body] = await getMovies({ let [resp, body] = await getMovies({

View File

@ -1,4 +1,4 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { seedMovie } from "~/controllers/seed/movies"; import { seedMovie } from "~/controllers/seed/movies";
import { db } from "~/db"; import { db } from "~/db";
@ -14,9 +14,6 @@ beforeAll(async () => {
await db.delete(shows); await db.delete(shows);
for (const movie of [bubble, dune1984, dune]) await seedMovie(movie); for (const movie of [bubble, dune1984, dune]) await seedMovie(movie);
}); });
afterAll(async () => {
await db.delete(shows);
});
describe("Get all movies", () => { describe("Get all movies", () => {
it("Invalid filter params", async () => { it("Invalid filter params", async () => {

View File

@ -8,7 +8,7 @@ let bubbleId = "";
beforeAll(async () => { beforeAll(async () => {
const ret = await seedMovie(bubble); const ret = await seedMovie(bubble);
if (ret.status !== 422) bubbleId = ret.id; if (!("status" in ret)) bubbleId = ret.id;
}); });
describe("Get movie", () => { describe("Get movie", () => {

View File

@ -1,14 +1,8 @@
import { afterAll, beforeAll, describe, expect, it } from "bun:test"; import { beforeAll, describe, expect, it } from "bun:test";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { db } from "~/db"; import { db } from "~/db";
import { import { showTranslations, shows, videos } from "~/db/schema";
entries,
entryVideoJoin,
showTranslations,
shows,
videos,
} from "~/db/schema";
import { bubble } from "~/models/examples"; import { bubble } from "~/models/examples";
import { dune, duneVideo } from "~/models/examples/dune-2021"; import { dune, duneVideo } from "~/models/examples/dune-2021";
import { createMovie, createVideo } from "../helper"; import { createMovie, createVideo } from "../helper";
@ -388,6 +382,7 @@ describe("Movie seeding", () => {
}, },
]); ]);
expectStatus(vresp, video).toBe(201); expectStatus(vresp, video).toBe(201);
console.log(video);
const [resp, body] = await createMovie({ const [resp, body] = await createMovie({
...bubble, ...bubble,
@ -395,7 +390,7 @@ describe("Movie seeding", () => {
videos: [video[0].id, video[1].id], videos: [video[0].id, video[1].id],
}); });
expectStatus(resp, body).toBe(201); expectStatus(resp, body).toBe(201);
console.log(body) console.log(body);
const ret = await db.query.shows.findFirst({ const ret = await db.query.shows.findFirst({
where: eq(shows.id, body.id), where: eq(shows.id, body.id),
@ -415,10 +410,7 @@ describe("Movie seeding", () => {
const cleanup = async () => { const cleanup = async () => {
await db.delete(shows); await db.delete(shows);
await db.delete(entries);
await db.delete(entryVideoJoin);
await db.delete(videos); await db.delete(videos);
}; };
// cleanup db beforehand to unsure tests are consistent // cleanup db beforehand to unsure tests are consistent
beforeAll(cleanup); beforeAll(cleanup);
afterAll(cleanup);