The order list and order sprint pages were rendering the rep column with a raw PocketBase record id, which the operator could not recognize. The data layer now resolves the rep through the user's name: - New `resolveRepDisplayName` helper (`src/lib/order-rep.ts`) takes the customer record's `expand.rep`, the `customer.rep` relation id, the legacy `orders.rep` text snapshot, and an admin-resolved user map, and returns a name (or empty when only an unresolved PB id is present). - The orders service now fetches the user list alongside the order page/counts query and resolves the rep on the way out, so the client receives a `repName` per row. New endpoints `/api/v1/orders/list` and `/api/v1/orders/[id]/review` expose the read model; the page and sprint calls go through them. - The list card and the sprint table + mobile card render the resolved name. An opaque PB id is never displayed. Migrates `/orders` off `pb-helpers.ts` per the data-layer discipline, and adds a shared browser-session helper for `Authorization: Bearer <PB token>` validation in route handlers that serve the dashboard UI (vs. the agent API). Co-authored-by: Orca <help@stably.ai>
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { resolveRepDisplayName } from "./order-rep";
|
|
|
|
describe("resolveRepDisplayName", () => {
|
|
const users = new Map([
|
|
["rep-id-1", { id: "rep-id-1", name: "Ava Smith", email: "ava@example.com" }],
|
|
]);
|
|
|
|
it("prefers the expanded customer rep name", () => {
|
|
expect(
|
|
resolveRepDisplayName({
|
|
expandedCustomerRep: { id: "rep-id-1", name: "Ava Smith" },
|
|
orderRep: "rep-id-1",
|
|
usersById: users,
|
|
}),
|
|
).toBe("Ava Smith");
|
|
});
|
|
|
|
it("resolves a customer rep id when the expand is unavailable", () => {
|
|
expect(
|
|
resolveRepDisplayName({ customerRepId: "rep-id-1", usersById: users }),
|
|
).toBe("Ava Smith");
|
|
});
|
|
|
|
it("resolves legacy order.rep ids instead of displaying the id", () => {
|
|
expect(
|
|
resolveRepDisplayName({ orderRep: "rep-id-1", usersById: users }),
|
|
).toBe("Ava Smith");
|
|
});
|
|
|
|
it("keeps a manually entered rep name as the fallback", () => {
|
|
expect(resolveRepDisplayName({ orderRep: "Jordan Lee" })).toBe("Jordan Lee");
|
|
});
|
|
|
|
it("hides an unresolved PocketBase id", () => {
|
|
expect(resolveRepDisplayName({ orderRep: "abcdefghijklmno" })).toBe("");
|
|
});
|
|
});
|