chore: auto-fix Biome formatting and configure lint rules
All checks were successful
CI / ci (push) Successful in 15s

Run biome check --write --unsafe to fix tabs, import ordering, and
non-null assertions across entire codebase. Disable a11y rules not
applicable to this single-user app. Exclude auto-generated routeTree.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 19:51:34 +01:00
parent 4d0452b7b3
commit b496462df5
63 changed files with 4752 additions and 4672 deletions

View File

@@ -1,79 +1,79 @@
import { describe, it, expect, beforeEach } from "bun:test";
import { createTestDb } from "../helpers/db.ts";
import { createItem } from "../../src/server/services/item.service.ts";
import { beforeEach, describe, expect, it } from "bun:test";
import { createCategory } from "../../src/server/services/category.service.ts";
import { createItem } from "../../src/server/services/item.service.ts";
import {
getCategoryTotals,
getGlobalTotals,
getCategoryTotals,
getGlobalTotals,
} from "../../src/server/services/totals.service.ts";
import { createTestDb } from "../helpers/db.ts";
describe("Totals Service", () => {
let db: ReturnType<typeof createTestDb>;
let db: ReturnType<typeof createTestDb>;
beforeEach(() => {
db = createTestDb();
});
beforeEach(() => {
db = createTestDb();
});
describe("getCategoryTotals", () => {
it("returns weight sum, cost sum, item count per category", () => {
const shelter = createCategory(db, { name: "Shelter", icon: "tent" });
createItem(db, {
name: "Tent",
weightGrams: 1200,
priceCents: 35000,
categoryId: shelter!.id,
});
createItem(db, {
name: "Tarp",
weightGrams: 300,
priceCents: 8000,
categoryId: shelter!.id,
});
describe("getCategoryTotals", () => {
it("returns weight sum, cost sum, item count per category", () => {
const shelter = createCategory(db, { name: "Shelter", icon: "tent" });
createItem(db, {
name: "Tent",
weightGrams: 1200,
priceCents: 35000,
categoryId: shelter?.id,
});
createItem(db, {
name: "Tarp",
weightGrams: 300,
priceCents: 8000,
categoryId: shelter?.id,
});
const totals = getCategoryTotals(db);
expect(totals).toHaveLength(1); // Only Shelter has items
expect(totals[0].categoryName).toBe("Shelter");
expect(totals[0].totalWeight).toBe(1500);
expect(totals[0].totalCost).toBe(43000);
expect(totals[0].itemCount).toBe(2);
});
const totals = getCategoryTotals(db);
expect(totals).toHaveLength(1); // Only Shelter has items
expect(totals[0].categoryName).toBe("Shelter");
expect(totals[0].totalWeight).toBe(1500);
expect(totals[0].totalCost).toBe(43000);
expect(totals[0].itemCount).toBe(2);
});
it("excludes empty categories (no items)", () => {
createCategory(db, { name: "Shelter", icon: "tent" });
// No items added
const totals = getCategoryTotals(db);
expect(totals).toHaveLength(0);
});
});
it("excludes empty categories (no items)", () => {
createCategory(db, { name: "Shelter", icon: "tent" });
// No items added
const totals = getCategoryTotals(db);
expect(totals).toHaveLength(0);
});
});
describe("getGlobalTotals", () => {
it("returns overall weight, cost, count", () => {
createItem(db, {
name: "Tent",
weightGrams: 1200,
priceCents: 35000,
categoryId: 1,
});
createItem(db, {
name: "Spork",
weightGrams: 20,
priceCents: 500,
categoryId: 1,
});
describe("getGlobalTotals", () => {
it("returns overall weight, cost, count", () => {
createItem(db, {
name: "Tent",
weightGrams: 1200,
priceCents: 35000,
categoryId: 1,
});
createItem(db, {
name: "Spork",
weightGrams: 20,
priceCents: 500,
categoryId: 1,
});
const totals = getGlobalTotals(db);
expect(totals).toBeDefined();
expect(totals!.totalWeight).toBe(1220);
expect(totals!.totalCost).toBe(35500);
expect(totals!.itemCount).toBe(2);
});
const totals = 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);
expect(totals).toBeDefined();
expect(totals!.totalWeight).toBe(0);
expect(totals!.totalCost).toBe(0);
expect(totals!.itemCount).toBe(0);
});
});
it("returns zeros when no items exist", () => {
const totals = getGlobalTotals(db);
expect(totals).toBeDefined();
expect(totals?.totalWeight).toBe(0);
expect(totals?.totalCost).toBe(0);
expect(totals?.itemCount).toBe(0);
});
});
});