Exclude extras & test availableCount/entryCount

This commit is contained in:
Zoe Roux 2025-03-08 14:36:39 +01:00
parent 54ee704ab9
commit bbbf7b32e0
No known key found for this signature in database
2 changed files with 33 additions and 2 deletions

View File

@ -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 { entries, entryVideoJoin, showTranslations, shows } from "~/db/schema";
import { conflictUpdateAllExcept, sqlarr } from "~/db/utils";
@ -107,6 +107,7 @@ export async function updateAvailableCount(
.where(
and(
eq(entries.showPk, shows.pk),
ne(entries.kind, "extra"),
exists(
db
.select()
@ -119,7 +120,9 @@ export async function updateAvailableCount(
entriesCount: sql`${db
.select({ count: count() })
.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)})`));

View 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);
});
});