- Add `writeSupplierWorkbook` function to create Excel workbooks for supplier analysis results. - Introduce `SupplierExportSummary` type for summarizing export data. - Create tests for `writeSupplierWorkbook` to ensure correct sheet creation and data population. - Implement supplier scoring logic in `supplier-scoring.ts` to evaluate product profitability and demand. - Add tests for supplier scoring to validate scoring logic and verdict determination. - Enhance UPC file analysis to integrate supplier scoring and export results to Excel. - Update database writing logic to accommodate new supplier analysis results. - Refactor types to include supplier-specific data structures and scoring metrics. - Ensure proper cleanup of temporary files after tests.
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { parseCatalogUpcLookupResponse } from "./sp-api.ts";
|
|
|
|
test("parseCatalogUpcLookupResponse resolves one ASIN", () => {
|
|
const detail = parseCatalogUpcLookupResponse("012345678901", {
|
|
items: [{ asin: "b000found1" }],
|
|
});
|
|
|
|
expect(detail.status).toBe("found");
|
|
expect(detail.asin).toBe("B000FOUND1");
|
|
expect(detail.candidateAsins).toEqual(["B000FOUND1"]);
|
|
});
|
|
|
|
test("parseCatalogUpcLookupResponse marks no match", () => {
|
|
const detail = parseCatalogUpcLookupResponse("012345678901", {
|
|
payload: { items: [] },
|
|
});
|
|
|
|
expect(detail.status).toBe("not_found");
|
|
expect(detail.asin).toBeNull();
|
|
});
|
|
|
|
test("parseCatalogUpcLookupResponse marks multiple ASINs", () => {
|
|
const detail = parseCatalogUpcLookupResponse("012345678901", {
|
|
payload: {
|
|
items: [{ asin: "B000000001" }, { asin: "B000000002" }],
|
|
},
|
|
});
|
|
|
|
expect(detail.status).toBe("multiple_asins");
|
|
expect(detail.candidateAsins).toEqual(["B000000001", "B000000002"]);
|
|
});
|
|
|
|
test("parseCatalogUpcLookupResponse marks invalid UPCs", () => {
|
|
const detail = parseCatalogUpcLookupResponse("123", { items: [] });
|
|
|
|
expect(detail.status).toBe("invalid_upc");
|
|
});
|
|
|
|
test("parseCatalogUpcLookupResponse marks malformed response as failed", () => {
|
|
const detail = parseCatalogUpcLookupResponse("012345678901", {
|
|
unexpected: true,
|
|
});
|
|
|
|
expect(detail.status).toBe("request_failed");
|
|
});
|