mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Add staff migrations & basic tests
This commit is contained in:
parent
25f042fbd7
commit
e3a537896a
28
api/drizzle/0014_staff.sql
Normal file
28
api/drizzle/0014_staff.sql
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
CREATE TYPE "kyoo"."role_kind" AS ENUM('actor', 'director', 'writter', 'producer', 'music', 'other');--> statement-breakpoint
|
||||||
|
CREATE TABLE "kyoo"."roles" (
|
||||||
|
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."roles_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||||
|
"show_pk" integer NOT NULL,
|
||||||
|
"staff_pk" integer NOT NULL,
|
||||||
|
"kind" "kyoo"."role_kind" NOT NULL,
|
||||||
|
"order" integer NOT NULL,
|
||||||
|
"character" jsonb
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "kyoo"."staff" (
|
||||||
|
"pk" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "kyoo"."staff_pk_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||||
|
"id" uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"slug" varchar(255) NOT NULL,
|
||||||
|
"name" text NOT NULL,
|
||||||
|
"latin_name" text,
|
||||||
|
"image" jsonb,
|
||||||
|
"external_id" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone NOT NULL,
|
||||||
|
CONSTRAINT "staff_id_unique" UNIQUE("id"),
|
||||||
|
CONSTRAINT "staff_slug_unique" UNIQUE("slug")
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "kyoo"."roles" ADD CONSTRAINT "roles_show_pk_shows_pk_fk" FOREIGN KEY ("show_pk") REFERENCES "kyoo"."shows"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "kyoo"."roles" ADD CONSTRAINT "roles_staff_pk_staff_pk_fk" FOREIGN KEY ("staff_pk") REFERENCES "kyoo"."staff"("pk") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
CREATE INDEX "role_kind" ON "kyoo"."roles" USING hash ("kind");--> statement-breakpoint
|
||||||
|
CREATE INDEX "role_order" ON "kyoo"."roles" USING btree ("order");
|
1487
api/drizzle/meta/0014_snapshot.json
Normal file
1487
api/drizzle/meta/0014_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -99,6 +99,13 @@
|
|||||||
"when": 1741444868735,
|
"when": 1741444868735,
|
||||||
"tag": "0013_original",
|
"tag": "0013_original",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 14,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1741601145901,
|
||||||
|
"tag": "0014_staff",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { StaticDecode } from "@sinclair/typebox";
|
|
||||||
import { type SQL, and, eq, ne, sql } from "drizzle-orm";
|
import { type SQL, and, eq, ne, sql } from "drizzle-orm";
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
@ -105,7 +104,7 @@ async function getEntries({
|
|||||||
after: string | undefined;
|
after: string | undefined;
|
||||||
limit: number;
|
limit: number;
|
||||||
query: string | undefined;
|
query: string | undefined;
|
||||||
sort: StaticDecode<typeof entrySort>;
|
sort: Sort;
|
||||||
filter: SQL | undefined;
|
filter: SQL | undefined;
|
||||||
languages: string[];
|
languages: string[];
|
||||||
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
}): Promise<(Entry | Extra | UnknownEntry)[]> {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { StaticDecode } from "@sinclair/typebox";
|
|
||||||
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import {
|
import {
|
||||||
@ -159,7 +158,7 @@ export async function getShows({
|
|||||||
after?: string;
|
after?: string;
|
||||||
limit: number;
|
limit: number;
|
||||||
query?: string;
|
query?: string;
|
||||||
sort?: StaticDecode<typeof showSort>;
|
sort?: Sort;
|
||||||
filter?: SQL;
|
filter?: SQL;
|
||||||
languages: string[];
|
languages: string[];
|
||||||
fallbackLanguage?: boolean;
|
fallbackLanguage?: boolean;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { StaticDecode } from "@sinclair/typebox";
|
|
||||||
import { type SQL, and, eq, sql } from "drizzle-orm";
|
import { type SQL, and, eq, sql } from "drizzle-orm";
|
||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
@ -82,7 +81,7 @@ async function getStaffRoles({
|
|||||||
after?: string;
|
after?: string;
|
||||||
limit: number;
|
limit: number;
|
||||||
query?: string;
|
query?: string;
|
||||||
sort?: StaticDecode<typeof staffRoleSort>;
|
sort?: Sort;
|
||||||
filter?: SQL;
|
filter?: SQL;
|
||||||
}) {
|
}) {
|
||||||
return await db
|
return await db
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { StaticDecode } from "@sinclair/typebox";
|
|
||||||
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
import { type SQL, and, eq, exists, sql } from "drizzle-orm";
|
||||||
import Elysia, { t } from "elysia";
|
import Elysia, { t } from "elysia";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
@ -74,7 +73,7 @@ export async function getStudios({
|
|||||||
after?: string;
|
after?: string;
|
||||||
limit: number;
|
limit: number;
|
||||||
query?: string;
|
query?: string;
|
||||||
sort?: StaticDecode<typeof studioSort>;
|
sort?: Sort,
|
||||||
filter?: SQL;
|
filter?: SQL;
|
||||||
languages: string[];
|
languages: string[];
|
||||||
fallbackLanguage?: boolean;
|
fallbackLanguage?: boolean;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
export * from "./movies-helper";
|
export * from "./movies-helper";
|
||||||
export * from "./series-helper";
|
export * from "./series-helper";
|
||||||
export * from "./studio-helper";
|
export * from "./studio-helper";
|
||||||
|
export * from "./staff-helper";
|
||||||
export * from "./videos-helper";
|
export * from "./videos-helper";
|
||||||
|
|
||||||
export * from "~/elysia";
|
export * from "~/elysia";
|
||||||
|
41
api/tests/helpers/staff-helper.ts
Normal file
41
api/tests/helpers/staff-helper.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import { buildUrl } from "tests/utils";
|
||||||
|
import { app } from "~/elysia";
|
||||||
|
|
||||||
|
export const getStaff = async (id: string, query: {}) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl(`staff/${id}`, query), {
|
||||||
|
method: "GET",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getStaffRoles = async (
|
||||||
|
staff: string,
|
||||||
|
{
|
||||||
|
langs,
|
||||||
|
...opts
|
||||||
|
}: {
|
||||||
|
filter?: string;
|
||||||
|
limit?: number;
|
||||||
|
after?: string;
|
||||||
|
sort?: string | string[];
|
||||||
|
query?: string;
|
||||||
|
langs?: string;
|
||||||
|
preferOriginal?: boolean;
|
||||||
|
},
|
||||||
|
) => {
|
||||||
|
const resp = await app.handle(
|
||||||
|
new Request(buildUrl(`staff/${staff}/roles`, opts), {
|
||||||
|
method: "GET",
|
||||||
|
headers: langs
|
||||||
|
? {
|
||||||
|
"Accept-Language": langs,
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const body = await resp.json();
|
||||||
|
return [resp, body] as const;
|
||||||
|
};
|
28
api/tests/series/get-staff.test.ts
Normal file
28
api/tests/series/get-staff.test.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { beforeAll, describe, expect, it } from "bun:test";
|
||||||
|
import { createSerie, getStaff, getStaffRoles } from "tests/helpers";
|
||||||
|
import { expectStatus } from "tests/utils";
|
||||||
|
import { madeInAbyss } from "~/models/examples";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await createSerie(madeInAbyss);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Get a staff member", () => {
|
||||||
|
it("Invalid slug", async () => {
|
||||||
|
const [resp, body] = await getStaff("sotneuhn", {});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(404);
|
||||||
|
expect(body).toMatchObject({
|
||||||
|
status: 404,
|
||||||
|
message: expect.any(String),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("Get staff by id", async () => {
|
||||||
|
const member = madeInAbyss.staff[0].staff;
|
||||||
|
const [resp, body] = await getStaff(member.slug, {});
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.slug).toBe(member.slug);
|
||||||
|
expect(body.latinName).toBe(member.latinName);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user