Fix tests & misc errors

This commit is contained in:
Zoe Roux
2025-04-07 15:38:08 +02:00
parent db0b244286
commit 080da9bc27
11 changed files with 136 additions and 53 deletions
+20 -1
View File
@@ -41,6 +41,25 @@ export const getSerie = async (
return [resp, body] as const;
};
export const getSeries = async ({
langs,
...query
}: { langs?: string; preferOriginal?: boolean; with?: string[] }) => {
const resp = await app.handle(
new Request(buildUrl("series", query), {
method: "GET",
headers: langs
? {
"Accept-Language": langs,
...(await getJwtHeaders()),
}
: await getJwtHeaders(),
}),
);
const body = await resp.json();
return [resp, body] as const;
};
export const getSeasons = async (
serie: string,
{
@@ -166,7 +185,7 @@ export const getNews = async ({
export const setSerieStatus = async (id: string, status: SerieWatchStatus) => {
const resp = await app.handle(
new Request(buildUrl(`movies/${id}/watchstatus`), {
new Request(buildUrl(`series/${id}/watchstatus`), {
method: "POST",
body: JSON.stringify(status),
headers: {
+18 -13
View File
@@ -1,24 +1,29 @@
import { processImages } from "~/controllers/seed/images";
import { db, migrate } from "~/db";
import { mqueue, shows, videos } from "~/db/schema";
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
import { createSerie, createVideo, getSerie } from "./helpers";
import { profiles, shows } from "~/db/schema";
import { madeInAbyss } from "~/models/examples";
import { createSerie, getSerie, setSerieStatus } from "./helpers";
import { getJwtHeaders } from "./helpers/jwt";
// test file used to run manually using `bun tests/manual.ts`
await migrate();
await db.delete(shows);
await db.delete(videos);
await db.delete(mqueue);
await db.delete(profiles);
const [_, vid] = await createVideo(madeInAbyssVideo);
console.log(vid);
const [__, ser] = await createSerie(madeInAbyss);
console.log(await getJwtHeaders());
const [_, ser] = await createSerie(madeInAbyss);
console.log(ser);
const [__, ret] = await setSerieStatus(madeInAbyss.slug, {
status: "watching",
startedAt: "2024-12-21",
completedAt: "2024-12-21",
seenCount: 2,
score: 85,
});
console.log(ret);
await processImages();
const [___, got] = await getSerie(madeInAbyss.slug, { with: ["translations"] });
console.log(got);
const [___, got] = await getSerie(madeInAbyss.slug, {});
console.log(JSON.stringify(got, undefined, 4));
process.exit(0);
+12 -14
View File
@@ -1,4 +1,4 @@
import { beforeAll, describe, expect, it } from "bun:test";
import { describe, expect, it } from "bun:test";
import { eq } from "drizzle-orm";
import { defaultBlurhash, processImages } from "~/controllers/seed/images";
import { db } from "~/db";
@@ -6,21 +6,19 @@ import { mqueue, shows, staff, studios, videos } from "~/db/schema";
import { madeInAbyss } from "~/models/examples";
import { createSerie } from "../helpers";
beforeAll(async () => {
await db.delete(shows);
await db.delete(studios);
await db.delete(staff);
await db.delete(videos);
await db.delete(mqueue);
await createSerie(madeInAbyss);
const release = await processImages();
// remove notifications to prevent other images to be downloaded (do not curl 20000 images for nothing)
release();
});
describe("images", () => {
it("Create a serie download images", async () => {
await db.delete(shows);
await db.delete(studios);
await db.delete(staff);
await db.delete(videos);
await db.delete(mqueue);
await createSerie(madeInAbyss);
const release = await processImages();
// remove notifications to prevent other images to be downloaded (do not curl 20000 images for nothing)
release();
const ret = await db.query.shows.findFirst({
where: eq(shows.slug, madeInAbyss.slug),
});
+8
View File
@@ -81,6 +81,14 @@ describe("Set & get watch status", () => {
});
it("Return watchstatus in /movies/:id", async () => {
const [r, b] = await setMovieStatus(bubble.slug, {
status: "rewatching",
// we still need to specify all values
completedAt: "2024-12-21",
score: 85,
});
expectStatus(r, b).toBe(200);
const [resp, body] = await getMovie(bubble.slug, {});
expectStatus(resp, body).toBe(200);
expect(body.slug).toBe(bubble.slug);