import { describe, expect, it } from "vitest"; import { aggregateDriverStatus } from "@/app/(app)/collection-map/pin-model"; describe("aggregateDriverStatus", () => { it("returns zeros for an empty array", () => { expect(aggregateDriverStatus([])).toEqual({ total: 0, collected: 0, ready: 0, waiting: 0, }); }); it("counts every item as collected when every item is collected", () => { const items = [ { item_status: "collected" as const, ready_for_collection: true }, { item_status: "collected" as const, ready_for_collection: true }, { item_status: "collected" as const, ready_for_collection: false }, ]; expect(aggregateDriverStatus(items)).toEqual({ total: 3, collected: 3, ready: 0, waiting: 0, }); }); it("counts every item as waiting when nothing is ready or collected", () => { const items = [ { item_status: "collection_pool" as const, ready_for_collection: false }, { item_status: "assigned" as const, ready_for_collection: false }, ]; expect(aggregateDriverStatus(items)).toEqual({ total: 2, collected: 0, ready: 0, waiting: 2, }); }); it("rolls up mixed states (collected + ready + waiting)", () => { const items = [ { item_status: "collected" as const, ready_for_collection: true }, { item_status: "collected" as const, ready_for_collection: true }, { item_status: "assigned" as const, ready_for_collection: true }, { item_status: "assigned" as const, ready_for_collection: true }, { item_status: "assigned" as const, ready_for_collection: true }, { item_status: "collection_pool" as const, ready_for_collection: false }, ]; expect(aggregateDriverStatus(items)).toEqual({ total: 6, collected: 2, ready: 3, waiting: 1, }); }); it("treats undefined ready_for_collection as waiting", () => { const items = [ { item_status: "assigned" as const }, { item_status: "collection_pool" as const }, ]; expect(aggregateDriverStatus(items).waiting).toBe(2); expect(aggregateDriverStatus(items).ready).toBe(0); expect(aggregateDriverStatus(items).collected).toBe(0); expect(aggregateDriverStatus(items).total).toBe(2); }); it("treats null ready_for_collection as waiting", () => { const items = [ { item_status: "assigned" as const, ready_for_collection: null }, { item_status: "collection_pool" as const, ready_for_collection: null }, ]; expect(aggregateDriverStatus(items).waiting).toBe(2); expect(aggregateDriverStatus(items).ready).toBe(0); expect(aggregateDriverStatus(items).collected).toBe(0); }); });