chore: auto-fix Biome formatting and configure lint rules
All checks were successful
CI / ci (push) Successful in 15s
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:
@@ -1,98 +1,98 @@
|
||||
import { describe, it, expect, beforeEach } from "bun:test";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
import { beforeEach, describe, expect, it } from "bun:test";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { items } from "../../src/db/schema.ts";
|
||||
import {
|
||||
getAllCategories,
|
||||
createCategory,
|
||||
updateCategory,
|
||||
deleteCategory,
|
||||
createCategory,
|
||||
deleteCategory,
|
||||
getAllCategories,
|
||||
updateCategory,
|
||||
} from "../../src/server/services/category.service.ts";
|
||||
import { createItem } from "../../src/server/services/item.service.ts";
|
||||
import { items } from "../../src/db/schema.ts";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
describe("Category Service", () => {
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
});
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
});
|
||||
|
||||
describe("createCategory", () => {
|
||||
it("creates with name and icon", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
describe("createCategory", () => {
|
||||
it("creates with name and icon", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
|
||||
expect(cat).toBeDefined();
|
||||
expect(cat!.id).toBeGreaterThan(0);
|
||||
expect(cat!.name).toBe("Shelter");
|
||||
expect(cat!.icon).toBe("tent");
|
||||
});
|
||||
expect(cat).toBeDefined();
|
||||
expect(cat?.id).toBeGreaterThan(0);
|
||||
expect(cat?.name).toBe("Shelter");
|
||||
expect(cat?.icon).toBe("tent");
|
||||
});
|
||||
|
||||
it("uses default icon if not provided", () => {
|
||||
const cat = createCategory(db, { name: "Cooking" });
|
||||
it("uses default icon if not provided", () => {
|
||||
const cat = createCategory(db, { name: "Cooking" });
|
||||
|
||||
expect(cat).toBeDefined();
|
||||
expect(cat!.icon).toBe("package");
|
||||
});
|
||||
});
|
||||
expect(cat).toBeDefined();
|
||||
expect(cat?.icon).toBe("package");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getAllCategories", () => {
|
||||
it("returns all categories", () => {
|
||||
createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
createCategory(db, { name: "Cooking", icon: "cooking-pot" });
|
||||
describe("getAllCategories", () => {
|
||||
it("returns all categories", () => {
|
||||
createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
createCategory(db, { name: "Cooking", icon: "cooking-pot" });
|
||||
|
||||
const all = getAllCategories(db);
|
||||
// Includes seeded Uncategorized + 2 new
|
||||
expect(all.length).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
});
|
||||
const all = getAllCategories(db);
|
||||
// Includes seeded Uncategorized + 2 new
|
||||
expect(all.length).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("updateCategory", () => {
|
||||
it("renames category", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
const updated = updateCategory(db, cat!.id, { name: "Sleep System" });
|
||||
describe("updateCategory", () => {
|
||||
it("renames category", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
const updated = updateCategory(db, cat?.id, { name: "Sleep System" });
|
||||
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated!.name).toBe("Sleep System");
|
||||
expect(updated!.icon).toBe("tent");
|
||||
});
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated?.name).toBe("Sleep System");
|
||||
expect(updated?.icon).toBe("tent");
|
||||
});
|
||||
|
||||
it("changes icon", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
const updated = updateCategory(db, cat!.id, { icon: "home" });
|
||||
it("changes icon", () => {
|
||||
const cat = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
const updated = updateCategory(db, cat?.id, { icon: "home" });
|
||||
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated!.icon).toBe("home");
|
||||
});
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated?.icon).toBe("home");
|
||||
});
|
||||
|
||||
it("returns null for non-existent id", () => {
|
||||
const result = updateCategory(db, 9999, { name: "Ghost" });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
it("returns null for non-existent id", () => {
|
||||
const result = updateCategory(db, 9999, { name: "Ghost" });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("deleteCategory", () => {
|
||||
it("reassigns items to Uncategorized (id=1) then deletes", () => {
|
||||
const shelter = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
createItem(db, { name: "Tent", categoryId: shelter!.id });
|
||||
createItem(db, { name: "Tarp", categoryId: shelter!.id });
|
||||
describe("deleteCategory", () => {
|
||||
it("reassigns items to Uncategorized (id=1) then deletes", () => {
|
||||
const shelter = createCategory(db, { name: "Shelter", icon: "tent" });
|
||||
createItem(db, { name: "Tent", categoryId: shelter?.id });
|
||||
createItem(db, { name: "Tarp", categoryId: shelter?.id });
|
||||
|
||||
const result = deleteCategory(db, shelter!.id);
|
||||
expect(result.success).toBe(true);
|
||||
const result = deleteCategory(db, shelter?.id);
|
||||
expect(result.success).toBe(true);
|
||||
|
||||
// Items should now be in Uncategorized (id=1)
|
||||
const reassigned = db
|
||||
.select()
|
||||
.from(items)
|
||||
.where(eq(items.categoryId, 1))
|
||||
.all();
|
||||
expect(reassigned).toHaveLength(2);
|
||||
expect(reassigned.map((i) => i.name).sort()).toEqual(["Tarp", "Tent"]);
|
||||
});
|
||||
// Items should now be in Uncategorized (id=1)
|
||||
const reassigned = db
|
||||
.select()
|
||||
.from(items)
|
||||
.where(eq(items.categoryId, 1))
|
||||
.all();
|
||||
expect(reassigned).toHaveLength(2);
|
||||
expect(reassigned.map((i) => i.name).sort()).toEqual(["Tarp", "Tent"]);
|
||||
});
|
||||
|
||||
it("cannot delete Uncategorized (id=1)", () => {
|
||||
const result = deleteCategory(db, 1);
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toBeDefined();
|
||||
});
|
||||
});
|
||||
it("cannot delete Uncategorized (id=1)", () => {
|
||||
const result = deleteCategory(db, 1);
|
||||
expect(result.success).toBe(false);
|
||||
expect(result.error).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user