mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-01 04:34:50 -04:00
Fix & test random slug reservation
This commit is contained in:
parent
1cdb372079
commit
d1609ddfbf
@ -17,8 +17,9 @@ export const seed = new Elysia()
|
|||||||
const err = validateTranslations(body.translations);
|
const err = validateTranslations(body.translations);
|
||||||
if (err) return error(400, err);
|
if (err) return error(400, err);
|
||||||
|
|
||||||
const { status, ...ret } = await seedMovie(body);
|
const ret = await seedMovie(body);
|
||||||
return error(status, ret);
|
if (ret.status === 422) return error(422, ret);
|
||||||
|
return error(ret.status, ret);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
body: "seed-movie",
|
body: "seed-movie",
|
||||||
|
@ -30,18 +30,22 @@ export type SeedMovieResponse = typeof SeedMovieResponse.static;
|
|||||||
|
|
||||||
export const seedMovie = async (
|
export const seedMovie = async (
|
||||||
seed: SeedMovie,
|
seed: SeedMovie,
|
||||||
): Promise<SeedMovieResponse & {
|
): Promise<
|
||||||
status: "Created" | "OK" | "Conflict";
|
| (SeedMovieResponse & { status: "Created" | "OK" | "Conflict" })
|
||||||
}> => {
|
| { status: 422; message: string }
|
||||||
const { translations, videos: vids, ...bMovie } = seed;
|
> => {
|
||||||
|
|
||||||
if (seed.slug === "random") {
|
if (seed.slug === "random") {
|
||||||
if (seed.airDate === null) {
|
if (!seed.airDate) {
|
||||||
throw new KErrorT("`random` is a reserved slug. Use something else.");
|
return {
|
||||||
|
status: 422,
|
||||||
|
message: "`random` is a reserved slug. Use something else.",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
seed.slug = `random-${getYear(seed.airDate)}`;
|
seed.slug = `random-${getYear(seed.airDate)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { translations, videos: vids, ...bMovie } = seed;
|
||||||
|
|
||||||
const ret = await db.transaction(async (tx) => {
|
const ret = await db.transaction(async (tx) => {
|
||||||
const movie: Show = {
|
const movie: Show = {
|
||||||
kind: "movie",
|
kind: "movie",
|
||||||
|
@ -192,6 +192,16 @@ describe("Movie seeding", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Refuses random as a slug", async () => {
|
||||||
|
const [resp, body] = await createMovie({ ...bubble, slug: "random", airDate: null });
|
||||||
|
expectStatus(resp, body).toBe(422);
|
||||||
|
});
|
||||||
|
it("Refuses random as a slug but fallback w/ airDate", async () => {
|
||||||
|
const [resp, body] = await createMovie({ ...bubble, slug: "random" });
|
||||||
|
expectStatus(resp, body).toBe(201);
|
||||||
|
expect(body.slug).toBe("random-2022");
|
||||||
|
});
|
||||||
|
|
||||||
test.todo("Create correct video slug (version)", async () => {});
|
test.todo("Create correct video slug (version)", async () => {});
|
||||||
test.todo("Create correct video slug (part)", async () => {});
|
test.todo("Create correct video slug (part)", async () => {});
|
||||||
test.todo("Create correct video slug (rendering)", async () => {});
|
test.todo("Create correct video slug (rendering)", async () => {});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user