feat: add isRepUser helper for rep-scoped list filtering
This commit is contained in:
parent
392a76fef7
commit
d23c811b91
2 changed files with 44 additions and 0 deletions
31
src/lib/rep-visibility.test.ts
Normal file
31
src/lib/rep-visibility.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { isRepUser } from "./rep-visibility";
|
||||
|
||||
describe("isRepUser", () => {
|
||||
it("returns true when user_type includes REP", () => {
|
||||
expect(isRepUser(["REP"])).toBe(true);
|
||||
});
|
||||
|
||||
it("is case-insensitive", () => {
|
||||
expect(isRepUser(["rep"])).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true when REP is combined with other roles", () => {
|
||||
expect(isRepUser(["BUYER", "REP"])).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for other roles", () => {
|
||||
expect(isRepUser(["BUYER"])).toBe(false);
|
||||
expect(isRepUser(["ADMIN", "QUOTER"])).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for null, undefined, or non-array input", () => {
|
||||
expect(isRepUser(null)).toBe(false);
|
||||
expect(isRepUser(undefined)).toBe(false);
|
||||
expect(isRepUser("REP")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for an empty array", () => {
|
||||
expect(isRepUser([])).toBe(false);
|
||||
});
|
||||
});
|
||||
13
src/lib/rep-visibility.ts
Normal file
13
src/lib/rep-visibility.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* `users.user_type` is a PB multi-select. "REP" is the existing
|
||||
* convention for marking a sales rep — see the identical pattern in
|
||||
* `src/lib/server/tv-dashboard-service.ts` (`TV_REP_ROLES` / `isRep`).
|
||||
*/
|
||||
export const REP_USER_TYPE = "REP";
|
||||
|
||||
export function isRepUser(userType: unknown): boolean {
|
||||
if (!Array.isArray(userType)) return false;
|
||||
return userType.some(
|
||||
(value) => typeof value === "string" && value.toUpperCase() === REP_USER_TYPE,
|
||||
);
|
||||
}
|
||||
Loading…
Reference in a new issue