mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Create simple watchlist tests
This commit is contained in:
parent
bf361a79d1
commit
b3edf31afc
@ -1,5 +1,6 @@
|
|||||||
export * from "./movies-helper";
|
export * from "./movies-helper";
|
||||||
export * from "./series-helper";
|
export * from "./series-helper";
|
||||||
|
export * from "./shows-helper";
|
||||||
export * from "./studio-helper";
|
export * from "./studio-helper";
|
||||||
export * from "./staff-helper";
|
export * from "./staff-helper";
|
||||||
export * from "./videos-helper";
|
export * from "./videos-helper";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { buildUrl } from "tests/utils";
|
import { buildUrl } from "tests/utils";
|
||||||
import { app } from "~/base";
|
import { app } from "~/base";
|
||||||
import type { SeedMovie } from "~/models/movie";
|
import type { SeedMovie } from "~/models/movie";
|
||||||
|
import type { MovieWatchStatus } from "~/models/watchlist";
|
||||||
import { getJwtHeaders } from "./jwt";
|
import { getJwtHeaders } from "./jwt";
|
||||||
|
|
||||||
export const getMovie = async (
|
export const getMovie = async (
|
||||||
@ -66,3 +67,21 @@ export const createMovie = async (movie: SeedMovie) => {
|
|||||||
const body = await resp.json();
|
const body = await resp.json();
|
||||||
return [resp, body] as const;
|
return [resp, body] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setMovieStatus = async (
|
||||||
|
id: string,
|
||||||
|
status: Omit<MovieWatchStatus, "percent">,
|
||||||
|
) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl(`movies/${id}/watchstatus`), {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(status),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(await getJwtHeaders()),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
||||||
|
@ -2,6 +2,7 @@ import { buildUrl } from "tests/utils";
|
|||||||
import { app } from "~/base";
|
import { app } from "~/base";
|
||||||
import type { SeedSerie } from "~/models/serie";
|
import type { SeedSerie } from "~/models/serie";
|
||||||
import { getJwtHeaders } from "./jwt";
|
import { getJwtHeaders } from "./jwt";
|
||||||
|
import { SerieWatchStatus } from "~/models/watchlist";
|
||||||
|
|
||||||
export const createSerie = async (serie: SeedSerie) => {
|
export const createSerie = async (serie: SeedSerie) => {
|
||||||
const resp = await app.handle(
|
const resp = await app.handle(
|
||||||
@ -162,3 +163,21 @@ export const getNews = async ({
|
|||||||
const body = await resp.json();
|
const body = await resp.json();
|
||||||
return [resp, body] as const;
|
return [resp, body] as const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setSerieStatus = async (
|
||||||
|
id: string,
|
||||||
|
status: SerieWatchStatus
|
||||||
|
) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl(`movies/${id}/watchstatus`), {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(status),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(await getJwtHeaders()),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
||||||
|
60
api/tests/helpers/shows-helper.ts
Normal file
60
api/tests/helpers/shows-helper.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { buildUrl } from "tests/utils";
|
||||||
|
import { app } from "~/base";
|
||||||
|
import { getJwtHeaders } from "./jwt";
|
||||||
|
|
||||||
|
export const getShows = async ({
|
||||||
|
langs,
|
||||||
|
...query
|
||||||
|
}: {
|
||||||
|
filter?: string;
|
||||||
|
limit?: number;
|
||||||
|
after?: string;
|
||||||
|
sort?: string | string[];
|
||||||
|
query?: string;
|
||||||
|
langs?: string;
|
||||||
|
preferOriginal?: boolean;
|
||||||
|
}) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl("shows", query), {
|
||||||
|
method: "GET",
|
||||||
|
headers: langs
|
||||||
|
? {
|
||||||
|
"Accept-Language": langs,
|
||||||
|
...(await getJwtHeaders()),
|
||||||
|
}
|
||||||
|
: await getJwtHeaders(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getWatchlist = async (
|
||||||
|
id: string,
|
||||||
|
{
|
||||||
|
langs,
|
||||||
|
...query
|
||||||
|
}: {
|
||||||
|
filter?: string;
|
||||||
|
limit?: number;
|
||||||
|
after?: string;
|
||||||
|
sort?: string | string[];
|
||||||
|
query?: string;
|
||||||
|
langs?: string;
|
||||||
|
preferOriginal?: boolean;
|
||||||
|
},
|
||||||
|
) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl(`profiles/${id}/watchlist`, query), {
|
||||||
|
method: "GET",
|
||||||
|
headers: langs
|
||||||
|
? {
|
||||||
|
"Accept-Language": langs,
|
||||||
|
...(await getJwtHeaders()),
|
||||||
|
}
|
||||||
|
: await getJwtHeaders(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
94
api/tests/movies/watchstatus.test.ts
Normal file
94
api/tests/movies/watchstatus.test.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import { beforeAll, describe, expect, it } from "bun:test";
|
||||||
|
import {
|
||||||
|
createMovie,
|
||||||
|
getMovie,
|
||||||
|
getShows,
|
||||||
|
getWatchlist,
|
||||||
|
setMovieStatus,
|
||||||
|
} from "tests/helpers";
|
||||||
|
import { expectStatus } from "tests/utils";
|
||||||
|
import { db } from "~/db";
|
||||||
|
import { shows } from "~/db/schema";
|
||||||
|
import { bubble } from "~/models/examples";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await db.delete(shows);
|
||||||
|
const [ret, body] = await createMovie(bubble);
|
||||||
|
expectStatus(ret, body).toBe(201);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Set & get watch status", () => {
|
||||||
|
it("Creates watchlist entry", async () => {
|
||||||
|
let [resp, body] = await getWatchlist("me", {});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(0);
|
||||||
|
|
||||||
|
const [r, b] = await setMovieStatus(bubble.slug, {
|
||||||
|
status: "completed",
|
||||||
|
completedAt: "2024-12-21",
|
||||||
|
score: 85,
|
||||||
|
});
|
||||||
|
expectStatus(r, b).toBe(201);
|
||||||
|
|
||||||
|
[resp, body] = await getWatchlist("me", {});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
expect(body.items[0].slug).toBe(bubble.slug);
|
||||||
|
expect(body.items[0].watchStatus).toMatchObject({
|
||||||
|
status: "completed",
|
||||||
|
completedAt: "2024-12-21",
|
||||||
|
score: 85,
|
||||||
|
percent: 100,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Edit watchlist entry", async () => {
|
||||||
|
let [resp, body] = await getWatchlist("me", {});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
|
||||||
|
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(201);
|
||||||
|
|
||||||
|
[resp, body] = await getWatchlist("me", {});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
expect(body.items[0].slug).toBe(bubble.slug);
|
||||||
|
expect(body.items[0].watchStatus).toMatchObject({
|
||||||
|
status: "completed",
|
||||||
|
completedAt: "2024-12-21",
|
||||||
|
score: 85,
|
||||||
|
percent: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Return watchstatus in /shows", async () => {
|
||||||
|
const [resp, body] = await getShows({});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.items).toBeArrayOfSize(1);
|
||||||
|
expect(body.items[0].slug).toBe(bubble.slug);
|
||||||
|
expect(body.items[0].watchStatus).toMatchObject({
|
||||||
|
status: "completed",
|
||||||
|
completedAt: "2024-12-21",
|
||||||
|
score: 85,
|
||||||
|
percent: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Return watchstatus in /movies/:id", async () => {
|
||||||
|
const [resp, body] = await getMovie(bubble.slug, {});
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.slug).toBe(bubble.slug);
|
||||||
|
expect(body.watchStatus).toMatchObject({
|
||||||
|
status: "completed",
|
||||||
|
completedAt: "2024-12-21",
|
||||||
|
score: 85,
|
||||||
|
percent: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user