39 lines
1.2 KiB
TypeScript
39 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("");
|
||
|
|
});
|
||
|
|
});
|