mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Exclude extras & test availableCount/entryCount
This commit is contained in:
parent
54ee704ab9
commit
bbbf7b32e0
@ -1,4 +1,4 @@
|
|||||||
import { and, count, eq, exists, sql } from "drizzle-orm";
|
import { and, count, eq, exists, ne, sql } from "drizzle-orm";
|
||||||
import { db } from "~/db";
|
import { db } from "~/db";
|
||||||
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
import { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
|
||||||
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
|
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
|
||||||
@ -107,6 +107,7 @@ export async function updateAvailableCount(
|
|||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(entries.showPk, shows.pk),
|
eq(entries.showPk, shows.pk),
|
||||||
|
ne(entries.kind, "extra"),
|
||||||
exists(
|
exists(
|
||||||
db
|
db
|
||||||
.select()
|
.select()
|
||||||
@ -119,7 +120,9 @@ export async function updateAvailableCount(
|
|||||||
entriesCount: sql`${db
|
entriesCount: sql`${db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(entries)
|
.from(entries)
|
||||||
.where(eq(entries.showPk, shows.pk))}`,
|
.where(
|
||||||
|
and(eq(entries.showPk, shows.pk), ne(entries.kind, "extra")),
|
||||||
|
)}`,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.where(eq(shows.pk, sql`any(${sqlarr(showPks)})`));
|
.where(eq(shows.pk, sql`any(${sqlarr(showPks)})`));
|
||||||
|
28
api/tests/series/get-series.test.ts
Normal file
28
api/tests/series/get-series.test.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { beforeAll, describe, expect, it } from "bun:test";
|
||||||
|
import { createSerie, getSerie } from "tests/helpers";
|
||||||
|
import { expectStatus } from "tests/utils";
|
||||||
|
import { madeInAbyss } from "~/models/examples";
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await createSerie(madeInAbyss);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Get seasons", () => {
|
||||||
|
it("Invalid slug", async () => {
|
||||||
|
const [resp, body] = await getSerie("sotneuhn", { langs: "en" });
|
||||||
|
|
||||||
|
expectStatus(resp, body).toBe(404);
|
||||||
|
expect(body).toMatchObject({
|
||||||
|
status: 404,
|
||||||
|
message: expect.any(String),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("With a valid entryCount/availableCount", async () => {
|
||||||
|
const [resp, body] = await getSerie(madeInAbyss.slug, { langs: "en" });
|
||||||
|
|
||||||
|
console.log(body)
|
||||||
|
expectStatus(resp, body).toBe(200);
|
||||||
|
expect(body.entriesCount).toBe(madeInAbyss.entries.length);
|
||||||
|
expect(body.availableCount).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user