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
69 lines
3.0 KiB
TypeScript
69 lines
3.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const api = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn() }));
|
|
vi.mock("@/app/lib/clientApi", () => api);
|
|
|
|
import { getSalesItem, getSku, listSkus, saveCatalog, searchSkuVariations, findSkuVariationsByCode } from "./adminCatalogSetup";
|
|
|
|
beforeEach(() => {
|
|
api.apiGet.mockReset();
|
|
api.apiPost.mockReset();
|
|
});
|
|
|
|
describe("adminCatalogSetup", () => {
|
|
it("saves through POST /api/products", async () => {
|
|
api.apiPost.mockResolvedValue({ sku: { id: 70 } });
|
|
const body = { sku: { code: "BA-010", name: "Romper", status: "Y", variations: [] } };
|
|
|
|
await saveCatalog(body as never);
|
|
|
|
expect(api.apiPost).toHaveBeenCalledWith("/api/products", body);
|
|
});
|
|
|
|
it("reads a Sales Item, a SKU, the SKU list and the variant options", async () => {
|
|
api.apiGet.mockResolvedValue({ content: [{ id: 1 }], totalElements: 3 });
|
|
|
|
await getSalesItem(26);
|
|
await getSku(16);
|
|
const page = await listSkus({ page: 0, pageSize: 50 });
|
|
await searchSkuVariations("a&b");
|
|
|
|
expect(api.apiGet).toHaveBeenNthCalledWith(1, "/api/products/26");
|
|
expect(api.apiGet).toHaveBeenNthCalledWith(2, "/api/products/skus/16");
|
|
expect(api.apiGet).toHaveBeenNthCalledWith(3, "/api/products/skus?page=0&size=50");
|
|
expect(api.apiGet).toHaveBeenNthCalledWith(4, "/api/products/sku-variation-options?q=a%26b");
|
|
expect(page).toEqual({ items: [{ id: 1 }], total: 3 });
|
|
});
|
|
|
|
it("sends sortBy and sortDir to the SKU list only when set", async () => {
|
|
api.apiGet.mockResolvedValue({ content: [], totalElements: 0 });
|
|
await listSkus({ page: 0, pageSize: 20, sortBy: "skuCode", sortDir: "desc" } as never);
|
|
expect(api.apiGet).toHaveBeenLastCalledWith("/api/products/skus?page=0&size=20&sortBy=skuCode&sortDir=desc");
|
|
await listSkus({ page: 0, pageSize: 20 });
|
|
expect(api.apiGet).toHaveBeenLastCalledWith("/api/products/skus?page=0&size=20");
|
|
});
|
|
|
|
it("sends the SKU status filter", async () => {
|
|
api.apiGet.mockResolvedValue({ content: [], totalElements: 0 });
|
|
await listSkus({ page: 0, pageSize: 20, q: "ba", status: "N" });
|
|
expect(api.apiGet).toHaveBeenLastCalledWith("/api/products/skus?page=0&size=20&q=ba&status=N");
|
|
});
|
|
|
|
it("sends the QianYi link filter only when set", async () => {
|
|
api.apiGet.mockResolvedValue({ content: [], totalElements: 0 });
|
|
await listSkus({ page: 0, pageSize: 20, qyLink: "UNLINKED" });
|
|
expect(api.apiGet).toHaveBeenLastCalledWith("/api/products/skus?page=0&size=20&qyLink=UNLINKED");
|
|
await listSkus({ page: 0, pageSize: 20, qyLink: "" });
|
|
expect(api.apiGet).toHaveBeenLastCalledWith("/api/products/skus?page=0&size=20");
|
|
});
|
|
|
|
it("looks up SKU variants by exact scan code, encoded as one value", async () => {
|
|
api.apiGet.mockResolvedValue([{ skuVariationId: 9 }]);
|
|
|
|
const found = await findSkuVariationsByCode("TEST-003&BLUE x");
|
|
|
|
expect(api.apiGet).toHaveBeenCalledWith("/api/products/sku-variations-by-code?code=TEST-003%26BLUE%20x");
|
|
expect(found).toEqual([{ skuVariationId: 9 }]);
|
|
});
|
|
});
|