mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Add tests & fix roles/staff
This commit is contained in:
parent
e3a537896a
commit
dfaf5480ad
@ -102,7 +102,7 @@ async function getStaffRoles({
|
||||
...(query
|
||||
? [sql`word_similarity(${query}::text, ${staff.name})`]
|
||||
: sortToSql(sort)),
|
||||
shows.pk,
|
||||
staff.pk,
|
||||
)
|
||||
.limit(limit);
|
||||
}
|
||||
@ -232,6 +232,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
||||
})
|
||||
.from(roles)
|
||||
.innerJoin(shows, eq(roles.showPk, shows.pk))
|
||||
.innerJoin(transQ, eq(shows.pk, transQ.pk))
|
||||
.where(
|
||||
and(
|
||||
eq(roles.staffPk, member.pk),
|
||||
@ -359,7 +360,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
||||
after,
|
||||
query,
|
||||
sort,
|
||||
filter: and(eq(shows.pk, roles.showPk), filter),
|
||||
filter: and(eq(roles.showPk, movie.pk), filter),
|
||||
});
|
||||
return createPage(items, { url, sort, limit });
|
||||
},
|
||||
@ -426,7 +427,7 @@ export const staffH = new Elysia({ tags: ["staff"] })
|
||||
after,
|
||||
query,
|
||||
sort,
|
||||
filter: and(eq(shows.pk, roles.showPk), filter),
|
||||
filter: and(eq(roles.showPk, serie.pk), filter),
|
||||
});
|
||||
return createPage(items, { url, sort, limit });
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ export async function getStudios({
|
||||
after?: string;
|
||||
limit: number;
|
||||
query?: string;
|
||||
sort?: Sort,
|
||||
sort?: Sort;
|
||||
filter?: SQL;
|
||||
languages: string[];
|
||||
fallbackLanguage?: boolean;
|
||||
|
@ -39,3 +39,39 @@ export const getStaffRoles = async (
|
||||
const body = await resp.json();
|
||||
return [resp, body] as const;
|
||||
};
|
||||
|
||||
export const getSerieStaff = async (
|
||||
serie: string,
|
||||
opts: {
|
||||
filter?: string;
|
||||
limit?: number;
|
||||
after?: string;
|
||||
sort?: string | string[];
|
||||
},
|
||||
) => {
|
||||
const resp = await app.handle(
|
||||
new Request(buildUrl(`series/${serie}/staff`, opts), {
|
||||
method: "GET",
|
||||
}),
|
||||
);
|
||||
const body = await resp.json();
|
||||
return [resp, body] as const;
|
||||
};
|
||||
|
||||
export const getMovieStaff = async (
|
||||
movie: string,
|
||||
opts: {
|
||||
filter?: string;
|
||||
limit?: number;
|
||||
after?: string;
|
||||
sort?: string | string[];
|
||||
},
|
||||
) => {
|
||||
const resp = await app.handle(
|
||||
new Request(buildUrl(`movies/${movie}/staff`, opts), {
|
||||
method: "GET",
|
||||
}),
|
||||
);
|
||||
const body = await resp.json();
|
||||
return [resp, body] as const;
|
||||
};
|
||||
|
@ -1,5 +1,10 @@
|
||||
import { beforeAll, describe, expect, it } from "bun:test";
|
||||
import { createSerie, getStaff, getStaffRoles } from "tests/helpers";
|
||||
import {
|
||||
createSerie,
|
||||
getSerieStaff,
|
||||
getStaff,
|
||||
getStaffRoles,
|
||||
} from "tests/helpers";
|
||||
import { expectStatus } from "tests/utils";
|
||||
import { madeInAbyss } from "~/models/examples";
|
||||
|
||||
@ -25,4 +30,25 @@ describe("Get a staff member", () => {
|
||||
expect(body.slug).toBe(member.slug);
|
||||
expect(body.latinName).toBe(member.latinName);
|
||||
});
|
||||
it("Get staff's roles", async () => {
|
||||
const role = madeInAbyss.staff[0];
|
||||
const [resp, body] = await getStaffRoles(role.staff.slug, {});
|
||||
|
||||
expectStatus(resp, body).toBe(200);
|
||||
expect(body.items).toBeArrayOfSize(1);
|
||||
expect(body.items[0].kind).toBe(role.kind);
|
||||
expect(body.items[0].character.name).toBe(role.character.name);
|
||||
expect(body.items[0].show.slug).toBe(madeInAbyss.slug);
|
||||
});
|
||||
it("Get series's staff", async () => {
|
||||
const role = madeInAbyss.staff[0];
|
||||
const [resp, body] = await getSerieStaff(madeInAbyss.slug, {});
|
||||
|
||||
expectStatus(resp, body).toBe(200);
|
||||
expect(body.items).toBeArrayOfSize(1);
|
||||
expect(body.items[0].kind).toBe(role.kind);
|
||||
expect(body.items[0].character.name).toBe(role.character.name);
|
||||
expect(body.items[0].staff.slug).toBe(role.staff.slug);
|
||||
expect(body.items[0].staff.name).toBe(role.staff.name);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user