mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Fix entries test with videos
This commit is contained in:
parent
66fadb2b20
commit
e86ab9c081
@ -111,9 +111,9 @@ async function getEntries({
|
|||||||
.from(entryVideoJoin)
|
.from(entryVideoJoin)
|
||||||
.where(eq(entryVideoJoin.entryPk, entries.pk))
|
.where(eq(entryVideoJoin.entryPk, entries.pk))
|
||||||
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
.leftJoin(videos, eq(videos.pk, entryVideoJoin.videoPk))
|
||||||
.as("video");
|
.as("videos");
|
||||||
const videosJ = db
|
const videosJ = db
|
||||||
.select({ videos: sql`json_agg("video")`.as("videos") })
|
.select({ videos: sql`coalesce(json_agg("videos"), '[]'::json)`.as("videos") })
|
||||||
.from(videosQ)
|
.from(videosQ)
|
||||||
.as("videos_json");
|
.as("videos_json");
|
||||||
|
|
||||||
@ -130,9 +130,9 @@ async function getEntries({
|
|||||||
.select({
|
.select({
|
||||||
...entryCol,
|
...entryCol,
|
||||||
...transCol,
|
...transCol,
|
||||||
videos: sql`${videosJ.videos}`.as("videos"),
|
videos: videosJ.videos,
|
||||||
// specials don't have an `episodeNumber` but a `number` field.
|
// specials don't have an `episodeNumber` but a `number` field.
|
||||||
number: sql<number>`${episodeNumber}`.as("number"),
|
number: episodeNumber,
|
||||||
|
|
||||||
// merge `extraKind` into `kind`
|
// merge `extraKind` into `kind`
|
||||||
kind: sql<EntryKind>`case when ${kind} = 'extra' then ${extraKind} else ${kind}::text end`.as(
|
kind: sql<EntryKind>`case when ${kind} = 'extra' then ${extraKind} else ${kind}::text end`.as(
|
||||||
@ -140,11 +140,11 @@ async function getEntries({
|
|||||||
),
|
),
|
||||||
|
|
||||||
// assign more restrained types to make typescript happy.
|
// assign more restrained types to make typescript happy.
|
||||||
externalId: sql<any>`${externalId}`.as("externalId"),
|
externalId: sql<any>`${externalId}`,
|
||||||
order: sql<number>`${order}`.as("order"),
|
order: sql<number>`${order}`,
|
||||||
seasonNumber: sql<number>`${seasonNumber}`.as("seasonNumber"),
|
seasonNumber: sql<number>`${seasonNumber}`,
|
||||||
episodeNumber: sql<number>`${episodeNumber}`.as("episodeNumber"),
|
episodeNumber: sql<number>`${episodeNumber}`,
|
||||||
name: sql<string>`${name}`.as("name"),
|
name: sql<string>`${name}`,
|
||||||
})
|
})
|
||||||
.from(entries)
|
.from(entries)
|
||||||
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
.innerJoin(transQ, eq(entries.pk, transQ.pk))
|
||||||
|
@ -131,7 +131,7 @@ export const insertEntries = async (
|
|||||||
entryPk: retEntries[i].pk,
|
entryPk: retEntries[i].pk,
|
||||||
entrySlug: retEntries[i].slug,
|
entrySlug: retEntries[i].slug,
|
||||||
// The first video should not have a rendering.
|
// The first video should not have a rendering.
|
||||||
needRendering: j && seed.videos!.length > 1,
|
needRendering: j !== 0 && seed.videos!.length > 1,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
if (!ret) {
|
if (!ret) {
|
||||||
return error(404, {
|
return error(404, {
|
||||||
status: 404,
|
status: 404,
|
||||||
message: "Movie not found",
|
message: `No movie found with id or slug: '${id}'.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!ret.language) {
|
if (!ret.language) {
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
SeedImage,
|
SeedImage,
|
||||||
TranslationRecord,
|
TranslationRecord,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { Video } from "../video";
|
import { EmbeddedVideo } from "../video";
|
||||||
import { BaseEntry, EntryTranslation } from "./base-entry";
|
import { BaseEntry, EntryTranslation } from "./base-entry";
|
||||||
|
|
||||||
export const BaseEpisode = t.Intersect([
|
export const BaseEpisode = t.Intersect([
|
||||||
@ -27,7 +27,7 @@ export const Episode = t.Intersect([
|
|||||||
EntryTranslation(),
|
EntryTranslation(),
|
||||||
BaseEpisode,
|
BaseEpisode,
|
||||||
t.Object({
|
t.Object({
|
||||||
videos: t.Optional(t.Array(Video)),
|
videos: t.Optional(t.Array(EmbeddedVideo)),
|
||||||
}),
|
}),
|
||||||
DbMetadata,
|
DbMetadata,
|
||||||
]);
|
]);
|
||||||
|
@ -3,7 +3,7 @@ import { type Prettify, comment } from "~/utils";
|
|||||||
import { madeInAbyss, registerExamples } from "../examples";
|
import { madeInAbyss, registerExamples } from "../examples";
|
||||||
import { DbMetadata, SeedImage } from "../utils";
|
import { DbMetadata, SeedImage } from "../utils";
|
||||||
import { Resource } from "../utils/resource";
|
import { Resource } from "../utils/resource";
|
||||||
import { Video } from "../video";
|
import { EmbeddedVideo } from "../video";
|
||||||
import { BaseEntry } from "./base-entry";
|
import { BaseEntry } from "./base-entry";
|
||||||
|
|
||||||
export const ExtraType = t.UnionEnum([
|
export const ExtraType = t.UnionEnum([
|
||||||
@ -36,7 +36,7 @@ export const Extra = t.Intersect([
|
|||||||
Resource(),
|
Resource(),
|
||||||
BaseExtra,
|
BaseExtra,
|
||||||
t.Object({
|
t.Object({
|
||||||
video: t.Optional(Video),
|
video: t.Optional(EmbeddedVideo),
|
||||||
}),
|
}),
|
||||||
DbMetadata,
|
DbMetadata,
|
||||||
]);
|
]);
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
SeedImage,
|
SeedImage,
|
||||||
TranslationRecord,
|
TranslationRecord,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { Video } from "../video";
|
import { EmbeddedVideo } from "../video";
|
||||||
import { BaseEntry, EntryTranslation } from "./base-entry";
|
import { BaseEntry, EntryTranslation } from "./base-entry";
|
||||||
|
|
||||||
export const BaseMovieEntry = t.Intersect(
|
export const BaseMovieEntry = t.Intersect(
|
||||||
@ -45,7 +45,7 @@ export const MovieEntry = t.Intersect([
|
|||||||
MovieEntryTranslation,
|
MovieEntryTranslation,
|
||||||
BaseMovieEntry,
|
BaseMovieEntry,
|
||||||
t.Object({
|
t.Object({
|
||||||
videos: t.Optional(t.Array(Video)),
|
videos: t.Optional(t.Array(EmbeddedVideo)),
|
||||||
}),
|
}),
|
||||||
DbMetadata,
|
DbMetadata,
|
||||||
]);
|
]);
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
SeedImage,
|
SeedImage,
|
||||||
TranslationRecord,
|
TranslationRecord,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { Video } from "../video";
|
import { EmbeddedVideo } from "../video";
|
||||||
import { BaseEntry, EntryTranslation } from "./base-entry";
|
import { BaseEntry, EntryTranslation } from "./base-entry";
|
||||||
|
|
||||||
export const BaseSpecial = t.Intersect(
|
export const BaseSpecial = t.Intersect(
|
||||||
@ -37,7 +37,7 @@ export const Special = t.Intersect([
|
|||||||
EntryTranslation(),
|
EntryTranslation(),
|
||||||
BaseSpecial,
|
BaseSpecial,
|
||||||
t.Object({
|
t.Object({
|
||||||
videos: t.Optional(t.Array(Video)),
|
videos: t.Optional(t.Array(EmbeddedVideo)),
|
||||||
}),
|
}),
|
||||||
DbMetadata,
|
DbMetadata,
|
||||||
]);
|
]);
|
||||||
|
@ -2,6 +2,7 @@ import { t } from "elysia";
|
|||||||
import { type Prettify, comment } from "~/utils";
|
import { type Prettify, comment } from "~/utils";
|
||||||
import { bubbleImages, registerExamples, youtubeExample } from "../examples";
|
import { bubbleImages, registerExamples, youtubeExample } from "../examples";
|
||||||
import { DbMetadata, Resource } from "../utils";
|
import { DbMetadata, Resource } from "../utils";
|
||||||
|
import { EmbeddedVideo } from "../video";
|
||||||
import { BaseEntry, EntryTranslation } from "./base-entry";
|
import { BaseEntry, EntryTranslation } from "./base-entry";
|
||||||
|
|
||||||
export const BaseUnknownEntry = t.Intersect(
|
export const BaseUnknownEntry = t.Intersect(
|
||||||
@ -27,6 +28,9 @@ export const UnknownEntry = t.Intersect([
|
|||||||
Resource(),
|
Resource(),
|
||||||
UnknownEntryTranslation,
|
UnknownEntryTranslation,
|
||||||
BaseUnknownEntry,
|
BaseUnknownEntry,
|
||||||
|
t.Object({
|
||||||
|
video: t.Optional(EmbeddedVideo),
|
||||||
|
}),
|
||||||
DbMetadata,
|
DbMetadata,
|
||||||
]);
|
]);
|
||||||
export type UnknownEntry = Prettify<typeof UnknownEntry.static>;
|
export type UnknownEntry = Prettify<typeof UnknownEntry.static>;
|
||||||
|
@ -38,7 +38,7 @@ export const SeedVideo = t.Object({
|
|||||||
season: t.Optional(t.Array(t.Integer(), { default: [] })),
|
season: t.Optional(t.Array(t.Integer(), { default: [] })),
|
||||||
episode: t.Optional(t.Array(t.Integer(), { default: [] })),
|
episode: t.Optional(t.Array(t.Integer(), { default: [] })),
|
||||||
// TODO: maybe replace "extra" with the `extraKind` value (aka behind-the-scene, trailer, etc)
|
// TODO: maybe replace "extra" with the `extraKind` value (aka behind-the-scene, trailer, etc)
|
||||||
type: t.Optional(t.UnionEnum(["episode", "movie", "extra"])),
|
kind: t.Optional(t.UnionEnum(["episode", "movie", "extra"])),
|
||||||
|
|
||||||
from: t.String({
|
from: t.String({
|
||||||
description: "Name of the tool that made the guess",
|
description: "Name of the tool that made the guess",
|
||||||
@ -71,4 +71,8 @@ export type SeedVideo = typeof SeedVideo.static;
|
|||||||
export const Video = t.Intersect([Resource(), SeedVideo, DbMetadata]);
|
export const Video = t.Intersect([Resource(), SeedVideo, DbMetadata]);
|
||||||
export type Video = Prettify<typeof Video.static>;
|
export type Video = Prettify<typeof Video.static>;
|
||||||
|
|
||||||
|
// type used in entry responses
|
||||||
|
export const EmbeddedVideo = t.Omit(Video, ["createdAt", "updatedAt"]);
|
||||||
|
export type EmbeddedVideo = Prettify<typeof EmbeddedVideo.static>;
|
||||||
|
|
||||||
registerExamples(Video, bubbleVideo);
|
registerExamples(Video, bubbleVideo);
|
||||||
|
15
api/tests/manual.ts
Normal file
15
api/tests/manual.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { db, migrate } from "~/db";
|
||||||
|
import { shows, videos } from "~/db/schema";
|
||||||
|
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
|
||||||
|
import { createSerie, createVideo } from "./helpers";
|
||||||
|
|
||||||
|
// test file used to run manually using `bun tests/manual.ts`
|
||||||
|
|
||||||
|
await migrate();
|
||||||
|
await db.delete(shows);
|
||||||
|
await db.delete(videos);
|
||||||
|
|
||||||
|
const [_, vid] = await createVideo(madeInAbyssVideo);
|
||||||
|
console.log(vid);
|
||||||
|
const [__, ser] = await createSerie(madeInAbyss);
|
||||||
|
console.log(ser);
|
@ -21,7 +21,7 @@ describe("Get movie", () => {
|
|||||||
expectStatus(resp, body).toBe(404);
|
expectStatus(resp, body).toBe(404);
|
||||||
expect(body).toMatchObject({
|
expect(body).toMatchObject({
|
||||||
status: 404,
|
status: 404,
|
||||||
message: "Movie not found",
|
message: expect.any(String),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it("Retrive by slug", async () => {
|
it("Retrive by slug", async () => {
|
||||||
|
@ -3,12 +3,19 @@ import { createSerie, createVideo, getEntries, getExtras } from "tests/helpers";
|
|||||||
import { expectStatus } from "tests/utils";
|
import { expectStatus } from "tests/utils";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { shows, videos } from "~/db/schema";
|
import { shows, videos } from "~/db/schema";
|
||||||
import { madeInAbyss, madeInAbyssVideo } from "~/models/examples";
|
import { madeInAbyss as base, madeInAbyssVideo } from "~/models/examples";
|
||||||
|
|
||||||
|
// make a copy so we can mutate it.
|
||||||
|
const madeInAbyss = JSON.parse(JSON.stringify(base)) as typeof base;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await db.delete(shows);
|
await db.delete(shows);
|
||||||
await db.delete(videos);
|
await db.delete(videos);
|
||||||
console.log(await createVideo(madeInAbyssVideo));
|
const [_, vid] = await createVideo(madeInAbyssVideo);
|
||||||
|
for (const entry of madeInAbyss.entries.filter((x) => x.videos?.length))
|
||||||
|
entry.videos = [vid[0].id];
|
||||||
|
for (const entry of madeInAbyss.extras.filter((x) => x.video))
|
||||||
|
entry.video = vid[0].id;
|
||||||
await createSerie(madeInAbyss);
|
await createSerie(madeInAbyss);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user