Test videos creation of slugs

This commit is contained in:
Zoe Roux 2025-01-26 22:34:47 +01:00
parent e5bb462e36
commit f2c1982afa
No known key found for this signature in database
4 changed files with 132 additions and 8 deletions

View File

@ -95,7 +95,7 @@ export const insertEntries = async (
slug: sql<string>` slug: sql<string>`
concat( concat(
${show.slug}::text, ${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 ${videos.version} <> 1 then ('-v' || ${videos.version}) else '' end,
case when exists(${hasRenderingQ}) then concat('-', ${videos.rendering}) else '' end case when exists(${hasRenderingQ}) then concat('-', ${videos.rendering}) else '' end
) )

View File

@ -94,9 +94,14 @@ export const entryTranslations = schema.table(
(t) => [primaryKey({ columns: [t.pk, t.language] })], (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" }), translations: many(entryTranslations, { relationName: "entryTranslations" }),
evj: many(entryVideoJoin, { relationName: "evj_entry" }), evj: many(entryVideoJoin, { relationName: "evj_entry" }),
show: one(shows, {
relationName: "show_entries",
fields: [entries.showPk],
references: [shows.pk],
}),
})); }));
export const entryTrRelations = relations(entryTranslations, ({ one }) => ({ export const entryTrRelations = relations(entryTranslations, ({ one }) => ({

View File

@ -13,6 +13,7 @@ import {
varchar, varchar,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { image, language, schema } from "./utils"; import { image, language, schema } from "./utils";
import { entries } from "./entries";
export const showKind = schema.enum("show_kind", ["serie", "movie"]); export const showKind = schema.enum("show_kind", ["serie", "movie"]);
export const showStatus = schema.enum("show_status", [ export const showStatus = schema.enum("show_status", [
@ -128,6 +129,7 @@ export const showsRelations = relations(shows, ({ many, one }) => ({
fields: [shows.pk, shows.originalLanguage], fields: [shows.pk, shows.originalLanguage],
references: [showTranslations.pk, showTranslations.language], references: [showTranslations.pk, showTranslations.language],
}), }),
entries: many(entries, { relationName: "show_entries" }),
})); }));
export const showsTrRelations = relations(showTranslations, ({ one }) => ({ export const showsTrRelations = relations(showTranslations, ({ one }) => ({
show: one(shows, { show: one(shows, {

View File

@ -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 { eq } from "drizzle-orm";
import { expectStatus } from "tests/utils"; import { expectStatus } from "tests/utils";
import { db } from "~/db"; 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 { bubble } from "~/models/examples";
import { dune, duneVideo } from "~/models/examples/dune-2021"; import { dune, duneVideo } from "~/models/examples/dune-2021";
import { createMovie } from "./movies-helper"; import { createMovie, createVideo } from "../helper";
describe("Movie seeding", () => { describe("Movie seeding", () => {
it("Can create a movie", async () => { it("Can create a movie", async () => {
@ -293,13 +299,124 @@ describe("Movie seeding", () => {
); );
}); });
test.todo("Create correct video slug (version)", async () => {}); it("Create correct video slug", async () => {
test.todo("Create correct video slug (part)", async () => {}); const [vresp, video] = await createVideo({
test.todo("Create correct video slug (rendering)", async () => {}); 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 () => { 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