Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
62 lines
2.8 KiB
TypeScript
62 lines
2.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const api = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", async (orig) => ({
|
|
...(await orig<typeof import("@/app/lib/clientApi")>()),
|
|
apiGet: api.apiGet,
|
|
apiPost: api.apiPost,
|
|
}));
|
|
import * as svc from "./adminMessages";
|
|
|
|
// BABYBOO-56 broadcast read count. Page is 1-based in, 0-based on the wire (like listAdminConversations).
|
|
const parts = (url: string) => {
|
|
const [path, qs = ""] = url.split("?");
|
|
return { path, sp: new URLSearchParams(qs) };
|
|
};
|
|
|
|
beforeEach(() => api.apiGet.mockReset().mockResolvedValue({ items: [], page: 0, size: 20, total: 0 }));
|
|
|
|
describe("broadcast read helpers", () => {
|
|
it("listAdminBroadcasts({ q }, page, size) GETs the summaries", async () => {
|
|
await svc.listAdminBroadcasts({ q: "raya" }, 2, 20);
|
|
const { path, sp } = parts(api.apiGet.mock.calls.at(-1)![0]);
|
|
expect(path).toBe("/api/admin/member-messages/broadcasts");
|
|
expect([sp.get("q"), sp.get("page"), sp.get("size")]).toEqual(["raya", "1", "20"]);
|
|
});
|
|
|
|
it("listAdminBroadcasts omits an empty q", async () => {
|
|
await svc.listAdminBroadcasts({ q: "" }, 1, 20);
|
|
const { sp } = parts(api.apiGet.mock.calls.at(-1)![0]);
|
|
expect(sp.has("q")).toBe(false);
|
|
expect([sp.get("page"), sp.get("size")]).toEqual(["0", "20"]);
|
|
});
|
|
|
|
it("listAdminBroadcasts sends sortBy and sortDir when set, omits them otherwise", async () => {
|
|
await svc.listAdminBroadcasts({ q: "", sortBy: "read", sortDir: "desc" }, 1, 20);
|
|
let { sp } = parts(api.apiGet.mock.calls.at(-1)![0]);
|
|
expect([sp.get("sortBy"), sp.get("sortDir")]).toEqual(["read", "desc"]);
|
|
await svc.listAdminBroadcasts({ q: "" }, 1, 20);
|
|
({ sp } = parts(api.apiGet.mock.calls.at(-1)![0]));
|
|
expect(sp.has("sortBy")).toBe(false);
|
|
expect(sp.has("sortDir")).toBe(false);
|
|
});
|
|
|
|
it("listAdminBroadcastRecipients(uuid, { unreadOnly }, page, size) GETs the recipients", async () => {
|
|
await svc.listAdminBroadcastRecipients("b 1", { unreadOnly: true }, 3, 20);
|
|
const { path, sp } = parts(api.apiGet.mock.calls.at(-1)![0]);
|
|
expect(path).toBe("/api/admin/member-messages/broadcasts/b%201/recipients");
|
|
expect([sp.get("unreadOnly"), sp.get("page"), sp.get("size")]).toEqual(["true", "2", "20"]);
|
|
});
|
|
|
|
it("listAdminBroadcastRecipients omits unreadOnly when false", async () => {
|
|
await svc.listAdminBroadcastRecipients("b1", { unreadOnly: false }, 1, 20);
|
|
expect(parts(api.apiGet.mock.calls.at(-1)![0]).sp.has("unreadOnly")).toBe(false);
|
|
});
|
|
|
|
it("getAdminBroadcast(uuid) GETs the single summary with the id encoded", async () => {
|
|
await svc.getAdminBroadcast("b 1");
|
|
const { path } = parts(api.apiGet.mock.calls.at(-1)![0]);
|
|
expect(path).toBe("/api/admin/member-messages/broadcasts/b%201");
|
|
});
|
|
});
|