mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -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);
|
||||
if (err) return error(400, err);
|
||||
|
||||
const { status, ...ret } = await seedMovie(body);
|
||||
return error(status, ret);
|
||||
const ret = await seedMovie(body);
|
||||
if (ret.status === 422) return error(422, ret);
|
||||
return error(ret.status, ret);
|
||||
},
|
||||
{
|
||||
body: "seed-movie",
|
||||
|
@ -30,18 +30,22 @@ export type SeedMovieResponse = typeof SeedMovieResponse.static;
|
||||
|
||||
export const seedMovie = async (
|
||||
seed: SeedMovie,
|
||||
): Promise<SeedMovieResponse & {
|
||||
status: "Created" | "OK" | "Conflict";
|
||||
}> => {
|
||||
const { translations, videos: vids, ...bMovie } = seed;
|
||||
|
||||
): Promise<
|
||||
| (SeedMovieResponse & { status: "Created" | "OK" | "Conflict" })
|
||||
| { status: 422; message: string }
|
||||
> => {
|
||||
if (seed.slug === "random") {
|
||||
if (seed.airDate === null) {
|
||||
throw new KErrorT("`random` is a reserved slug. Use something else.");
|
||||
if (!seed.airDate) {
|
||||
return {
|
||||
status: 422,
|
||||
message: "`random` is a reserved slug. Use something else.",
|
||||
};
|
||||
}
|
||||
seed.slug = `random-${getYear(seed.airDate)}`;
|
||||
}
|
||||
|
||||
const { translations, videos: vids, ...bMovie } = seed;
|
||||
|
||||
const ret = await db.transaction(async (tx) => {
|
||||
const movie: Show = {
|
||||
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 (part)", async () => {});
|
||||
test.todo("Create correct video slug (rendering)", async () => {});
|
||||
|
Loading…
x
Reference in New Issue
Block a user