Automatiska tester, och rättningar som testerna hittade
Vitest med enhetstester utan databas och databastester mot en egen testdatabas vars namn måste sluta på _test. Rättar tomma MAP_*-värden i .env och säkerhetskopior med å, ä och ö i filnamnet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e8d79ee10
commit
dcb5d43429
30 files changed
+2872
-13
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { beforeEach, expect, it } from "vitest";
|
||||
import { nextEntityCode, nextMapCode, nextMarkerCode, nextRelationCode, nextScheduleCode } from "@/lib/ids";
|
||||
import { describeDb, makeBook, makeUser, prisma, resetAll } from "../helpers/db";
|
||||
|
||||
describeDb("löpande ID", () => {
|
||||
let bookId: string;
|
||||
let otherBookId: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetAll();
|
||||
const user = await makeUser();
|
||||
bookId = (await makeBook(user.id, "A")).id;
|
||||
otherBookId = (await makeBook(user.id, "B")).id;
|
||||
});
|
||||
|
||||
it("räknar upp per typ i varje bok", async () => {
|
||||
expect(await nextEntityCode(bookId, "CHARACTER")).toBe("KI-0001");
|
||||
expect(await nextEntityCode(bookId, "CHARACTER")).toBe("KI-0002");
|
||||
expect(await nextEntityCode(bookId, "PET")).toBe("DI-0001");
|
||||
expect(await nextEntityCode(bookId, "CHARACTER")).toBe("KI-0003");
|
||||
});
|
||||
|
||||
it("börjar om i en ny bok", async () => {
|
||||
await nextEntityCode(bookId, "CHARACTER");
|
||||
await nextEntityCode(bookId, "CHARACTER");
|
||||
expect(await nextEntityCode(otherBookId, "CHARACTER")).toBe("KI-0001");
|
||||
});
|
||||
|
||||
it("ger inget ID åt typer utan ID", async () => {
|
||||
expect(await nextEntityCode(bookId, "APP")).toBeNull();
|
||||
expect(await nextEntityCode(bookId, "WEBSITE")).toBeNull();
|
||||
expect(await prisma.idCounter.count({ where: { bookId } })).toBe(0);
|
||||
});
|
||||
|
||||
it("använder egna räknare för relationer, placeringar, scheman och kartor", async () => {
|
||||
expect(await nextRelationCode(bookId)).toBe("REI-0001");
|
||||
expect(await nextMarkerCode(bookId)).toBe("PI-0001");
|
||||
expect(await nextScheduleCode(bookId)).toBe("SCI-0001");
|
||||
expect(await nextMapCode(bookId, "GEO")).toBe("KD-R_0001");
|
||||
expect(await nextMapCode(bookId, "IMAGE")).toBe("KD-E_0001");
|
||||
expect(await nextMapCode(bookId, "GEO")).toBe("KD-R_0002");
|
||||
});
|
||||
|
||||
it("ger unika nummer även när många skapas samtidigt", async () => {
|
||||
const codes = await Promise.all(Array.from({ length: 25 }, () => nextEntityCode(bookId, "CHARACTER")));
|
||||
expect(new Set(codes).size).toBe(25);
|
||||
expect(codes.sort()[0]).toBe("KI-0001");
|
||||
expect(codes.sort()[24]).toBe("KI-0025");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user