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
77 lines
2.9 KiB
TypeScript
77 lines
2.9 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => ({ apiGet: mocks.apiGet, apiPost: mocks.apiPost }));
|
|
|
|
import {
|
|
adminWarrantyPhotoUrl, approveWarrantyClaim, getWarrantyClaim, listWarrantyClaims, rejectWarrantyClaim,
|
|
} from "./adminWarranty";
|
|
|
|
beforeEach(() => {
|
|
mocks.apiGet.mockReset();
|
|
mocks.apiPost.mockReset();
|
|
});
|
|
|
|
describe("listWarrantyClaims", () => {
|
|
it("GETs the list route with status and default pagination", async () => {
|
|
const page = { content: [], totalElements: 0, number: 0, size: 20, totalPages: 0 };
|
|
mocks.apiGet.mockResolvedValue(page);
|
|
await expect(listWarrantyClaims({ status: "P" })).resolves.toBe(page);
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/warranty-claims?status=P&page=0&size=20");
|
|
});
|
|
|
|
it("omits empty text filters", async () => {
|
|
mocks.apiGet.mockResolvedValue({});
|
|
await listWarrantyClaims({ documentNo: "", invoiceNo: "", member: "" });
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/warranty-claims?page=0&size=20");
|
|
});
|
|
|
|
it("forwards all filter params", async () => {
|
|
mocks.apiGet.mockResolvedValue({});
|
|
await listWarrantyClaims({
|
|
status: "P", documentNo: "WC1", invoiceNo: "IN2", member: "MY1",
|
|
from: "2024-01-01", to: "2024-12-31", page: 1, size: 10,
|
|
});
|
|
expect(mocks.apiGet).toHaveBeenCalledWith(
|
|
"/api/warranty-claims?status=P&documentNo=WC1&invoiceNo=IN2&member=MY1&from=2024-01-01&to=2024-12-31&page=1&size=10",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("getWarrantyClaim", () => {
|
|
it("GETs the detail route", async () => {
|
|
const claim = { uuid: "W-1" };
|
|
mocks.apiGet.mockResolvedValue(claim);
|
|
await expect(getWarrantyClaim("W-1")).resolves.toBe(claim);
|
|
expect(mocks.apiGet).toHaveBeenCalledWith("/api/warranty-claims/W-1");
|
|
});
|
|
});
|
|
|
|
describe("approveWarrantyClaim", () => {
|
|
it("POSTs an empty body without a note", async () => {
|
|
mocks.apiPost.mockResolvedValue({ uuid: "W-1", status: "A" });
|
|
await approveWarrantyClaim("W-1");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/warranty-claims/W-1/approve", {});
|
|
});
|
|
|
|
it("POSTs the note", async () => {
|
|
mocks.apiPost.mockResolvedValue({ uuid: "W-1", status: "A" });
|
|
await approveWarrantyClaim("W-1", { note: "Send to service centre" });
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/warranty-claims/W-1/approve", { note: "Send to service centre" });
|
|
});
|
|
});
|
|
|
|
describe("rejectWarrantyClaim", () => {
|
|
it("POSTs the reason", async () => {
|
|
mocks.apiPost.mockResolvedValue({ uuid: "W-1", status: "R" });
|
|
await rejectWarrantyClaim("W-1", "Out of warranty");
|
|
expect(mocks.apiPost).toHaveBeenCalledWith("/api/warranty-claims/W-1/reject", { reason: "Out of warranty" });
|
|
});
|
|
});
|
|
|
|
describe("adminWarrantyPhotoUrl", () => {
|
|
it("points at the portal photo proxy", () => {
|
|
expect(adminWarrantyPhotoUrl("W-1", 2)).toBe("/api/warranty-claims/W-1/photos/2");
|
|
});
|
|
});
|