mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Test videos creation of slugs
This commit is contained in:
parent
e5bb462e36
commit
f2c1982afa
@ -95,7 +95,7 @@ export const insertEntries = async (
|
||||
slug: sql<string>`
|
||||
concat(
|
||||
${show.slug}::text,
|
||||
case when ${videos.part} <> null then ('-p' || ${videos.part}) else '' end,
|
||||
case when ${videos.part} is not null then ('-p' || ${videos.part}) else '' end,
|
||||
case when ${videos.version} <> 1 then ('-v' || ${videos.version}) else '' end,
|
||||
case when exists(${hasRenderingQ}) then concat('-', ${videos.rendering}) else '' end
|
||||
)
|
||||
|
@ -94,9 +94,14 @@ export const entryTranslations = schema.table(
|
||||
(t) => [primaryKey({ columns: [t.pk, t.language] })],
|
||||
);
|
||||
|
||||
export const entryRelations = relations(entries, ({ many }) => ({
|
||||
export const entryRelations = relations(entries, ({ one, many }) => ({
|
||||
translations: many(entryTranslations, { relationName: "entryTranslations" }),
|
||||
evj: many(entryVideoJoin, { relationName: "evj_entry" }),
|
||||
show: one(shows, {
|
||||
relationName: "show_entries",
|
||||
fields: [entries.showPk],
|
||||
references: [shows.pk],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const entryTrRelations = relations(entryTranslations, ({ one }) => ({
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
varchar,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { image, language, schema } from "./utils";
|
||||
import { entries } from "./entries";
|
||||
|
||||
export const showKind = schema.enum("show_kind", ["serie", "movie"]);
|
||||
export const showStatus = schema.enum("show_status", [
|
||||
@ -128,6 +129,7 @@ export const showsRelations = relations(shows, ({ many, one }) => ({
|
||||
fields: [shows.pk, shows.originalLanguage],
|
||||
references: [showTranslations.pk, showTranslations.language],
|
||||
}),
|
||||
entries: many(entries, { relationName: "show_entries" }),
|
||||
}));
|
||||
export const showsTrRelations = relations(showTranslations, ({ one }) => ({
|
||||
show: one(shows, {
|
||||
|
@ -1,11 +1,17 @@
|
||||
import { afterAll, beforeAll, describe, expect, it, test } from "bun:test";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { expectStatus } from "tests/utils";
|
||||
import { db } from "~/db";
|
||||
import { showTranslations, shows, videos } from "~/db/schema";
|
||||
import {
|
||||
entries,
|
||||
entryVideoJoin,
|
||||
showTranslations,
|
||||
shows,
|
||||
videos,
|
||||
} from "~/db/schema";
|
||||
import { bubble } from "~/models/examples";
|
||||
import { dune, duneVideo } from "~/models/examples/dune-2021";
|
||||
import { createMovie } from "./movies-helper";
|
||||
import { createMovie, createVideo } from "../helper";
|
||||
|
||||
describe("Movie seeding", () => {
|
||||
it("Can create a movie", async () => {
|
||||
@ -293,13 +299,124 @@ describe("Movie seeding", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test.todo("Create correct video slug (version)", async () => {});
|
||||
test.todo("Create correct video slug (part)", async () => {});
|
||||
test.todo("Create correct video slug (rendering)", async () => {});
|
||||
it("Create correct video slug", async () => {
|
||||
const [vresp, video] = await createVideo({
|
||||
path: "/video/bubble.mkv",
|
||||
part: null,
|
||||
version: 1,
|
||||
rendering: "oeunhtoeuth",
|
||||
});
|
||||
expectStatus(vresp, video).toBe(201);
|
||||
|
||||
const [resp, body] = await createMovie({
|
||||
...bubble,
|
||||
slug: "video-slug-test1",
|
||||
videos: [video[0].id],
|
||||
});
|
||||
expectStatus(resp, body).toBe(201);
|
||||
|
||||
const ret = await db.query.videos.findFirst({
|
||||
where: eq(videos.id, video[0].id),
|
||||
with: { evj: { with: { entry: true } } },
|
||||
});
|
||||
expect(ret).not.toBe(undefined);
|
||||
expect(ret!.evj).toBeArrayOfSize(1);
|
||||
expect(ret!.evj[0].slug).toBe("video-slug-test1");
|
||||
});
|
||||
|
||||
it("Create correct video slug (version)", async () => {
|
||||
const [vresp, video] = await createVideo({
|
||||
path: "/video/bubble2.mkv",
|
||||
part: null,
|
||||
version: 2,
|
||||
rendering: "oeunhtoeuth",
|
||||
});
|
||||
expectStatus(vresp, video).toBe(201);
|
||||
|
||||
const [resp, body] = await createMovie({
|
||||
...bubble,
|
||||
slug: "bubble-vtest",
|
||||
videos: [video[0].id],
|
||||
});
|
||||
expectStatus(resp, body).toBe(201);
|
||||
|
||||
const ret = await db.query.videos.findFirst({
|
||||
where: eq(videos.id, video[0].id),
|
||||
with: { evj: { with: { entry: true } } },
|
||||
});
|
||||
expect(ret).not.toBe(undefined);
|
||||
expect(ret!.evj).toBeArrayOfSize(1);
|
||||
expect(ret!.evj[0].slug).toBe("bubble-vtest-v2");
|
||||
});
|
||||
it("Create correct video slug (part)", async () => {
|
||||
const [vresp, video] = await createVideo({
|
||||
path: "/video/bubble5.mkv",
|
||||
part: 1,
|
||||
version: 2,
|
||||
rendering: "oaoeueunhtoeuth",
|
||||
});
|
||||
expectStatus(vresp, video).toBe(201);
|
||||
|
||||
const [resp, body] = await createMovie({
|
||||
...bubble,
|
||||
slug: "bubble-ptest",
|
||||
videos: [video[0].id],
|
||||
});
|
||||
expectStatus(resp, body).toBe(201);
|
||||
|
||||
const ret = await db.query.videos.findFirst({
|
||||
where: eq(videos.id, video[0].id),
|
||||
with: { evj: { with: { entry: true } } },
|
||||
});
|
||||
expect(ret).not.toBe(undefined);
|
||||
expect(ret!.evj).toBeArrayOfSize(1);
|
||||
expect(ret!.evj[0].slug).toBe("bubble-ptest-p1-v2");
|
||||
});
|
||||
it("Create correct video slug (rendering)", async () => {
|
||||
const [vresp, video] = await createVideo([
|
||||
{
|
||||
path: "/video/bubble3.mkv",
|
||||
part: null,
|
||||
version: 1,
|
||||
rendering: "oeunhtoeuth",
|
||||
},
|
||||
{
|
||||
path: "/video/bubble4.mkv",
|
||||
part: null,
|
||||
version: 1,
|
||||
rendering: "aoeuaoeu",
|
||||
},
|
||||
]);
|
||||
expectStatus(vresp, video).toBe(201);
|
||||
|
||||
const [resp, body] = await createMovie({
|
||||
...bubble,
|
||||
slug: "bubble-rtest",
|
||||
videos: [video[0].id, video[1].id],
|
||||
});
|
||||
expectStatus(resp, body).toBe(201);
|
||||
console.log(body)
|
||||
|
||||
const ret = await db.query.shows.findFirst({
|
||||
where: eq(shows.id, body.id),
|
||||
with: { entries: { with: { evj: { with: { entry: true } } } } },
|
||||
});
|
||||
expect(ret).not.toBe(undefined);
|
||||
expect(ret!.entries).toBeArrayOfSize(1);
|
||||
expect(ret!.entries[0].slug).toBe("bubble-rtest");
|
||||
expect(ret!.entries[0].evj).toBeArrayOfSize(2);
|
||||
expect(ret!.entries[0].evj).toContainValues([
|
||||
{ slug: "bubble-rtest-oeunhtoeuth" },
|
||||
{ slug: "bubble-rtest-aoeuaoeu" },
|
||||
{ slug: "bubble-rtest" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
const cleanup = async () => {
|
||||
await db.delete(shows);
|
||||
await db.delete(entries);
|
||||
await db.delete(entryVideoJoin);
|
||||
await db.delete(videos);
|
||||
};
|
||||
// cleanup db beforehand to unsure tests are consistent
|
||||
|
Loading…
x
Reference in New Issue
Block a user