feat(14-06): convert all 9 service test files to async PGlite
- All beforeEach now use async/await createTestDb() - All service calls in tests now awaited - All direct DB calls (.run()/.all()) replaced with await - All test callbacks made async - Fixed PostgreSQL GROUP BY strictness in totals.service.ts (categories.name and categories.icon added to groupBy) - db type changed to 'any' to accommodate PGlite type differences Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,29 +8,29 @@ import {
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
describe("Totals Service", () => {
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: any;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
beforeEach(async () => {
|
||||
db = await createTestDb();
|
||||
});
|
||||
|
||||
describe("getCategoryTotals", () => {
|
||||
it("returns weight sum, cost sum, item count per category", () => {
|
||||
const shelter = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
createItem(db, {
|
||||
it("returns weight sum, cost sum, item count per category", async () => {
|
||||
const shelter = await createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
await createItem(db, {
|
||||
name: "Tent",
|
||||
weightGrams: 1200,
|
||||
priceCents: 35000,
|
||||
categoryId: shelter?.id,
|
||||
});
|
||||
createItem(db, {
|
||||
await createItem(db, {
|
||||
name: "Tarp",
|
||||
weightGrams: 300,
|
||||
priceCents: 8000,
|
||||
categoryId: shelter?.id,
|
||||
});
|
||||
|
||||
const totals = getCategoryTotals(db);
|
||||
const totals = await getCategoryTotals(db);
|
||||
expect(totals).toHaveLength(1); // Only Shelter has items
|
||||
expect(totals[0].categoryName).toBe("Shelter");
|
||||
expect(totals[0].totalWeight).toBe(1500);
|
||||
@@ -38,38 +38,38 @@ describe("Totals Service", () => {
|
||||
expect(totals[0].itemCount).toBe(2);
|
||||
});
|
||||
|
||||
it("excludes empty categories (no items)", () => {
|
||||
createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
it("excludes empty categories (no items)", async () => {
|
||||
await createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
// No items added
|
||||
const totals = getCategoryTotals(db);
|
||||
const totals = await getCategoryTotals(db);
|
||||
expect(totals).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getGlobalTotals", () => {
|
||||
it("returns overall weight, cost, count", () => {
|
||||
createItem(db, {
|
||||
it("returns overall weight, cost, count", async () => {
|
||||
await createItem(db, {
|
||||
name: "Tent",
|
||||
weightGrams: 1200,
|
||||
priceCents: 35000,
|
||||
categoryId: 1,
|
||||
});
|
||||
createItem(db, {
|
||||
await createItem(db, {
|
||||
name: "Spork",
|
||||
weightGrams: 20,
|
||||
priceCents: 500,
|
||||
categoryId: 1,
|
||||
});
|
||||
|
||||
const totals = getGlobalTotals(db);
|
||||
const totals = await getGlobalTotals(db);
|
||||
expect(totals).toBeDefined();
|
||||
expect(totals?.totalWeight).toBe(1220);
|
||||
expect(totals?.totalCost).toBe(35500);
|
||||
expect(totals?.itemCount).toBe(2);
|
||||
});
|
||||
|
||||
it("returns zeros when no items exist", () => {
|
||||
const totals = getGlobalTotals(db);
|
||||
it("returns zeros when no items exist", async () => {
|
||||
const totals = await getGlobalTotals(db);
|
||||
expect(totals).toBeDefined();
|
||||
expect(totals?.totalWeight).toBe(0);
|
||||
expect(totals?.totalCost).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user