mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
405 lines
10 KiB
TypeScript
405 lines
10 KiB
TypeScript
import { beforeAll, describe, expect, it } from "bun:test";
|
|
import { eq } from "drizzle-orm";
|
|
import { createMovie, createSerie, createVideo } from "tests/helpers";
|
|
import { expectStatus } from "tests/utils";
|
|
import { db } from "~/db";
|
|
import { entries, shows, videos } from "~/db/schema";
|
|
import { bubble, madeInAbyss } from "~/models/examples";
|
|
|
|
beforeAll(async () => {
|
|
await db.delete(shows);
|
|
await db.delete(entries);
|
|
await db.delete(videos);
|
|
let [ret, body] = await createSerie(madeInAbyss);
|
|
expectStatus(ret, body).toBe(201);
|
|
[ret, body] = await createMovie(bubble);
|
|
expectStatus(ret, body).toBe(201);
|
|
});
|
|
|
|
describe("Video seeding", () => {
|
|
it("Can create a video without entry", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "unknown", from: "test" },
|
|
part: null,
|
|
path: "/video/unknown s1e13.mkv",
|
|
rendering: "sha",
|
|
version: 1,
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/unknown s1e13.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "unknown", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(0);
|
|
expect(vid!.evj).toBeArrayOfSize(0);
|
|
});
|
|
|
|
it("With slug", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "mia", season: [1], episode: [13], from: "test" },
|
|
part: null,
|
|
path: "/video/mia s1e13.mkv",
|
|
rendering: "sha",
|
|
version: 1,
|
|
for: [{ slug: `${madeInAbyss.slug}-s1e13` }],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/mia s1e13.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "mia", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe(`${madeInAbyss.slug}-s1e13`);
|
|
expect(vid!.evj[0].entry.slug).toBe(`${madeInAbyss.slug}-s1e13`);
|
|
});
|
|
|
|
it("With movie", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "bubble", from: "test" },
|
|
part: null,
|
|
path: "/video/bubble.mkv",
|
|
rendering: "sha",
|
|
version: 1,
|
|
for: [{ movie: bubble.slug }],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/bubble.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "bubble", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe(bubble.slug);
|
|
expect(vid!.evj[0].entry.slug).toBe(bubble.slug);
|
|
});
|
|
|
|
it("With season/episode", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "mia", season: [2], episode: [1], from: "test" },
|
|
part: null,
|
|
path: "/video/mia s2e1.mkv",
|
|
rendering: "renderingsha",
|
|
version: 1,
|
|
for: [
|
|
{
|
|
serie: madeInAbyss.slug,
|
|
season: madeInAbyss.entries[3].seasonNumber!,
|
|
episode: madeInAbyss.entries[3].episodeNumber!,
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/mia s2e1.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "mia", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe(`${madeInAbyss.slug}-s2e1`);
|
|
expect(vid!.evj[0].entry.slug).toBe(`${madeInAbyss.slug}-s2e1`);
|
|
});
|
|
|
|
it("With special", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "mia", season: [0], episode: [3], from: "test" },
|
|
part: null,
|
|
path: "/video/mia sp3.mkv",
|
|
rendering: "notehu",
|
|
version: 1,
|
|
for: [
|
|
{
|
|
serie: madeInAbyss.slug,
|
|
special: madeInAbyss.entries[1].number!,
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/mia sp3.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "mia", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe(`${madeInAbyss.slug}-sp3`);
|
|
expect(vid!.evj[0].entry.slug).toBe(`${madeInAbyss.slug}-sp3`);
|
|
});
|
|
|
|
it("With order", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: { title: "mia", season: [0], episode: [3], from: "test" },
|
|
part: null,
|
|
path: "/video/mia 13.5.mkv",
|
|
rendering: "notehu",
|
|
version: 1,
|
|
for: [
|
|
{
|
|
serie: madeInAbyss.slug,
|
|
order: 13.5,
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/mia 13.5.mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "mia", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe("made-in-abyss-dawn-of-the-deep-soul");
|
|
expect(vid!.evj[0].entry.slug).toBe("made-in-abyss-dawn-of-the-deep-soul");
|
|
});
|
|
|
|
it("With external id", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: {
|
|
title: "mia",
|
|
season: [0],
|
|
episode: [3],
|
|
from: "test",
|
|
externalId: {
|
|
themoviedb: { serieId: "72636", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
part: null,
|
|
path: "/video/mia s1e13 [tmdb=72636].mkv",
|
|
rendering: "notehu",
|
|
version: 1,
|
|
for: [
|
|
{
|
|
externalId: {
|
|
themoviedb: { serieId: "72636", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/mia s1e13 [tmdb=72636].mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "mia", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe("made-in-abyss-s1e13-notehu");
|
|
expect(vid!.evj[0].entry.slug).toBe("made-in-abyss-s1e13");
|
|
});
|
|
|
|
it("With movie external id", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: {
|
|
title: "bubble",
|
|
from: "test",
|
|
externalId: {
|
|
themoviedb: { dataId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
part: null,
|
|
path: "/video/bubble [tmdb=912598].mkv",
|
|
rendering: "onetuh",
|
|
version: 1,
|
|
for: [
|
|
{
|
|
externalId: {
|
|
themoviedb: { serieId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/bubble [tmdb=912598].mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "bubble", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe("bubble-onetuh");
|
|
expect(vid!.evj[0].entry.slug).toBe("bubble");
|
|
});
|
|
|
|
it("Two for the same entry", async () => {
|
|
const [resp, body] = await createVideo({
|
|
guess: {
|
|
title: "bubble",
|
|
from: "test",
|
|
externalId: {
|
|
themoviedb: { dataId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
part: null,
|
|
path: "/video/bubble [tmdb=912598].mkv",
|
|
rendering: "cwhtn",
|
|
version: 1,
|
|
for: [
|
|
{ movie: "bubble" },
|
|
{
|
|
externalId: {
|
|
themoviedb: { serieId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/bubble [tmdb=912598].mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "bubble", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe("bubble-cwhtn");
|
|
expect(vid!.evj[0].entry.slug).toBe("bubble");
|
|
});
|
|
|
|
it("Two for the same entry WITHOUT rendering", async () => {
|
|
await db.delete(videos);
|
|
const [resp, body] = await createVideo({
|
|
guess: {
|
|
title: "bubble",
|
|
from: "test",
|
|
externalId: {
|
|
themoviedb: { dataId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
part: null,
|
|
path: "/video/bubble [tmdb=912598].mkv",
|
|
rendering: "cwhtn",
|
|
version: 1,
|
|
for: [
|
|
{ movie: "bubble" },
|
|
{
|
|
externalId: {
|
|
themoviedb: { serieId: "912598", season: 1, episode: 13 },
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
expectStatus(resp, body).toBe(201);
|
|
expect(body).toBeArrayOfSize(1);
|
|
expect(body[0].id).toBeString();
|
|
|
|
const vid = await db.query.videos.findFirst({
|
|
where: eq(videos.id, body[0].id),
|
|
with: {
|
|
evj: { with: { entry: true } },
|
|
},
|
|
});
|
|
|
|
expect(vid).not.toBeNil();
|
|
expect(vid!.path).toBe("/video/bubble [tmdb=912598].mkv");
|
|
expect(vid!.guess).toMatchObject({ title: "bubble", from: "test" });
|
|
|
|
expect(body[0].entries).toBeArrayOfSize(1);
|
|
expect(vid!.evj).toBeArrayOfSize(1);
|
|
|
|
expect(vid!.evj[0].slug).toBe("bubble");
|
|
expect(vid!.evj[0].entry.slug).toBe("bubble");
|
|
});
|
|
});
|