Test & fix entry video join

This commit is contained in:
Zoe Roux 2025-03-04 10:59:51 +01:00
parent 477fb24036
commit 70d0d480f6
No known key found for this signature in database
13 changed files with 77 additions and 35 deletions

View File

@ -121,6 +121,7 @@ export const insertEntries = async (
return {
videoId: seed.video,
entryPk: retEntries[i].pk,
entrySlug: retEntries[i].slug,
needRendering: false,
};
}
@ -128,6 +129,7 @@ export const insertEntries = async (
return seed.videos.map((x, j) => ({
videoId: x,
entryPk: retEntries[i].pk,
entrySlug: retEntries[i].slug,
// The first video should not have a rendering.
needRendering: j && seed.videos!.length > 1,
}));
@ -142,9 +144,9 @@ export const insertEntries = async (
db
.select({
entryPk: sql<number>`vids.entryPk::integer`.as("entry"),
videoPk: sql`${videos.pk}`.as("video"),
videoPk: videos.pk,
slug: computeVideoSlug(
sql`${show.slug}::text`,
sql`vids.entrySlug::text`,
sql`vids.needRendering::boolean`,
),
})

View File

@ -7,8 +7,11 @@ import { processOptImage } from "../images";
type StudioI = typeof studios.$inferInsert;
type StudioTransI = typeof studioTranslations.$inferInsert;
export const insertStudios = async (seed: SeedStudio[], showPk: number) => {
if (!seed.length) return [];
export const insertStudios = async (
seed: SeedStudio[] | undefined,
showPk: number,
) => {
if (!seed?.length) return [];
return await db.transaction(async (tx) => {
const vals: StudioI[] = seed.map((x) => {

View File

@ -8,6 +8,7 @@ import {
SeedImage,
TranslationRecord,
} from "../utils";
import { Video } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseEpisode = t.Intersect([
@ -25,6 +26,9 @@ export const Episode = t.Intersect([
Resource(),
EntryTranslation(),
BaseEpisode,
t.Object({
videos: t.Optional(t.Array(Video)),
}),
DbMetadata,
]);
export type Episode = Prettify<typeof Episode.static>;
@ -34,7 +38,7 @@ export const SeedEpisode = t.Intersect([
t.Object({
thumbnail: t.Nullable(SeedImage),
translations: TranslationRecord(EntryTranslation()),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })),
}),
]);
export type SeedEpisode = Prettify<typeof SeedEpisode.static>;
@ -45,4 +49,5 @@ registerExamples(Episode, {
...ep.translations.en,
...bubbleImages,
slug: `${madeInAbyss.slug}-s${ep.seasonNumber}-e${ep.episodeNumber}`,
videos: [],
});

View File

@ -3,6 +3,7 @@ import { type Prettify, comment } from "~/utils";
import { madeInAbyss, registerExamples } from "../examples";
import { DbMetadata, SeedImage } from "../utils";
import { Resource } from "../utils/resource";
import { Video } from "../video";
import { BaseEntry } from "./base-entry";
export const ExtraType = t.UnionEnum([
@ -31,7 +32,14 @@ export const BaseExtra = t.Intersect(
},
);
export const Extra = t.Intersect([Resource(), BaseExtra, DbMetadata]);
export const Extra = t.Intersect([
Resource(),
BaseExtra,
t.Object({
video: t.Optional(Video),
}),
DbMetadata,
]);
export type Extra = Prettify<typeof Extra.static>;
export const SeedExtra = t.Intersect([
@ -44,4 +52,4 @@ export const SeedExtra = t.Intersect([
]);
export type SeedExtra = Prettify<typeof SeedExtra.static>;
registerExamples(Extra, madeInAbyss.extras[0]);
registerExamples(Extra, { ...madeInAbyss.extras[0], video: undefined });

View File

@ -9,6 +9,7 @@ import {
SeedImage,
TranslationRecord,
} from "../utils";
import { Video } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseMovieEntry = t.Intersect(
@ -43,6 +44,9 @@ export const MovieEntry = t.Intersect([
Resource(),
MovieEntryTranslation,
BaseMovieEntry,
t.Object({
videos: t.Optional(t.Array(Video)),
}),
DbMetadata,
]);
export type MovieEntry = Prettify<typeof MovieEntry.static>;
@ -58,7 +62,7 @@ export const SeedMovieEntry = t.Intersect([
t.Object({ poster: t.Nullable(SeedImage) }),
]),
),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })),
}),
]);
export type SeedMovieEntry = Prettify<typeof SeedMovieEntry.static>;

View File

@ -8,6 +8,7 @@ import {
SeedImage,
TranslationRecord,
} from "../utils";
import { Video } from "../video";
import { BaseEntry, EntryTranslation } from "./base-entry";
export const BaseSpecial = t.Intersect(
@ -35,6 +36,9 @@ export const Special = t.Intersect([
Resource(),
EntryTranslation(),
BaseSpecial,
t.Object({
videos: t.Optional(t.Array(Video)),
}),
DbMetadata,
]);
export type Special = Prettify<typeof Special.static>;
@ -44,7 +48,7 @@ export const SeedSpecial = t.Intersect([
t.Object({
thumbnail: t.Nullable(SeedImage),
translations: TranslationRecord(EntryTranslation()),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })),
}),
]);
export type SeedSpecial = Prettify<typeof SeedSpecial.static>;

View File

@ -3,15 +3,15 @@ import type { Video } from "~/models/video";
export const madeInAbyssVideo: Video = {
id: "3cd436ee-01ff-4f45-ba98-654282531234",
slug: "made-in-abyss-s1e1",
path: "/video/Made in abyss S01E01.mkv",
slug: "made-in-abyss-s1e13",
path: "/video/Made in abyss S01E13.mkv",
rendering: "459429fa062adeebedcc2bb04b9965de0262bfa453369783132d261be79021bd",
part: null,
version: 1,
guess: {
title: "Made in abyss",
season: [1],
episode: [1],
episode: [13],
type: "episode",
from: "guessit",
},
@ -156,6 +156,7 @@ export const madeInAbyss = {
link: "https://www.themoviedb.org/tv/72636/season/1/episode/13",
},
},
videos: [madeInAbyssVideo.id],
},
{
kind: "special",
@ -240,7 +241,7 @@ export const madeInAbyss = {
name: "The Making of MADE IN ABYSS 01",
runtime: 17,
thumbnail: null,
video: "3cd436ee-01ff-4f45-ba98-654282531234",
video: madeInAbyssVideo.id,
},
],
studios: [

View File

@ -88,9 +88,9 @@ export const SeedMovie = t.Intersect([
}),
]),
),
videos: t.Optional(t.Array(t.String({ format: "uuid" }))),
videos: t.Optional(t.Array(t.String({ format: "uuid" }), { default: [] })),
collection: t.Optional(SeedCollection),
studios: t.Array(SeedStudio),
studios: t.Optional(t.Array(SeedStudio, { default: [] })),
}),
]);
export type SeedMovie = Prettify<typeof SeedMovie.static>;

View File

@ -98,9 +98,9 @@ export const SeedSerie = t.Intersect([
),
seasons: t.Array(SeedSeason),
entries: t.Array(SeedEntry),
extras: t.Optional(t.Array(SeedExtra)),
extras: t.Optional(t.Array(SeedExtra, { default: [] })),
collection: t.Optional(SeedCollection),
studios: t.Array(SeedStudio),
studios: t.Optional(t.Array(SeedStudio, { default: [] })),
}),
]);
export type SeedSerie = typeof SeedSerie.static;

View File

@ -1,14 +1,15 @@
import { beforeAll, describe, expect, it } from "bun:test";
import { getEntries, getExtras, getUnknowns } from "tests/helpers";
import { createSerie, createVideo, getEntries, getExtras } from "tests/helpers";
import { expectStatus } from "tests/utils";
import { seedSerie } from "~/controllers/seed/series";
import { madeInAbyss } from "~/models/examples";
let miaId = "";
import { db } from "~/db";
import { shows, videos } from "~/db/schema";
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
beforeAll(async () => {
const ret = await seedSerie(madeInAbyss);
if (!("status" in ret)) miaId = ret.id;
await db.delete(shows);
await db.delete(videos);
console.log(await createVideo(madeInAbyssVideo));
await createSerie(madeInAbyss);
});
describe("Get entries", () => {
@ -27,6 +28,12 @@ describe("Get entries", () => {
expectStatus(resp, body).toBe(200);
expect(body.items).toBeArrayOfSize(madeInAbyss.entries.length);
});
it("With videos", async () => {
const [resp, body] = await getEntries(madeInAbyss.slug, { langs: "en" });
expectStatus(resp, body).toBe(200);
expect(body.items[0].videos).toBeArrayOfSize(1);
});
});
describe("Get extra", () => {

View File

@ -1,14 +1,10 @@
import { beforeAll, describe, expect, it } from "bun:test";
import { getSeasons } from "tests/helpers";
import { createSerie, getSeasons } from "tests/helpers";
import { expectStatus } from "tests/utils";
import { seedSerie } from "~/controllers/seed/series";
import { madeInAbyss } from "~/models/examples";
let miaId = "";
beforeAll(async () => {
const ret = await seedSerie(madeInAbyss);
if (!("status" in ret)) miaId = ret.id;
await createSerie(madeInAbyss);
});
describe("Get seasons", () => {

View File

@ -25,7 +25,12 @@ describe("Serie seeding", () => {
where: eq(shows.id, body.id),
with: {
seasons: { orderBy: seasons.seasonNumber },
entries: { with: { translations: true } },
entries: {
with: {
translations: true,
evj: { with: { video: true } },
},
},
},
});
@ -37,7 +42,9 @@ describe("Serie seeding", () => {
madeInAbyss.entries.length + madeInAbyss.extras.length,
);
const ep13 = madeInAbyss.entries.find((x) => x.order === 13)!;
const { videos: _, ...ep13 } = madeInAbyss.entries.find(
(x) => x.order === 13,
)!;
expect(ret!.entries.find((x) => x.order === 13)).toMatchObject({
...ep13,
slug: "made-in-abyss-s1e13",
@ -48,6 +55,12 @@ describe("Serie seeding", () => {
...ep13.translations.en,
},
],
evj: [
expect.objectContaining({
slug: madeInAbyssVideo.slug,
video: expect.objectContaining({ path: madeInAbyssVideo.path }),
}),
],
});
const { number, ...special } = madeInAbyss.entries.find(

View File

@ -1,11 +1,10 @@
import { beforeAll, describe, expect, it } from "bun:test";
import { getSerie, getShowsByStudio, getStudio } from "tests/helpers";
import { createSerie, getSerie, getShowsByStudio, getStudio } from "tests/helpers";
import { expectStatus } from "tests/utils";
import { seedSerie } from "~/controllers/seed/series";
import { madeInAbyss } from "~/models/examples";
beforeAll(async () => {
await seedSerie(madeInAbyss);
await createSerie(madeInAbyss);
});
describe("Get by studio", () => {