fix
This commit is contained in:
1 parent
176b1fe47f
commit
3bfeb6b61e
8 files changed
+264
-32
No files matched your search
@@ -24,6 +24,8 @@ import {
|
||||
sortFeedListRows,
|
||||
statusBadgeLabel,
|
||||
statusBadgeTone,
|
||||
syncJobDiagnostic,
|
||||
syncJobDisplayStatus,
|
||||
syncJobProductsLabel,
|
||||
syncJobStatusTone,
|
||||
type FeedListRow
|
||||
@@ -117,6 +119,31 @@ describe("syncJobStatusTone", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("sync history diagnostics", () => {
|
||||
it("marks historical all-skipped completed jobs as invalid", () => {
|
||||
const bad = { status: "completed", products_synced: 0, products_unchanged: 0, products_total: 127, products_skipped: 127 };
|
||||
assert.equal(syncJobDisplayStatus(bad), "skipped all");
|
||||
assert.match(syncJobDiagnostic(bad), /All 127 rows were skipped/);
|
||||
assert.match(syncJobStatusTone(syncJobDisplayStatus(bad)), /destructive/);
|
||||
});
|
||||
|
||||
it("shows backend skip details for failed and partial jobs", () => {
|
||||
const failed = { status: "failed", error: "Missing GTIN in rows 1, 2" };
|
||||
assert.equal(syncJobDisplayStatus(failed), "failed");
|
||||
assert.equal(syncJobDiagnostic(failed), failed.error);
|
||||
const partial = { status: "completed", products_synced: 10, products_total: 12, products_skipped: 2, error: "2 rows missing GTIN" };
|
||||
assert.equal(syncJobDisplayStatus(partial), "partial");
|
||||
assert.equal(syncJobDiagnostic(partial), partial.error);
|
||||
assert.match(syncJobStatusTone(syncJobDisplayStatus(partial)), /amber/);
|
||||
});
|
||||
|
||||
it("a successful identical feed reports unchanged products, not zero", () => {
|
||||
const ok = { status: "completed", products_synced: 0, products_total: 127, products_unchanged: 127 };
|
||||
assert.equal(syncJobDisplayStatus(ok), "completed");
|
||||
assert.equal(syncJobProductsLabel(ok), "0 / 127 · 127 unchanged");
|
||||
});
|
||||
});
|
||||
|
||||
describe("syncJobProductsLabel", () => {
|
||||
it("formats synced/total and optional deltas", () => {
|
||||
assert.equal(syncJobProductsLabel({ products_synced: 3 }), "3");
|
||||
|
||||
@@ -23,6 +23,8 @@ export type FeedListRow = {
|
||||
};
|
||||
|
||||
export type FeedSyncJobLike = {
|
||||
status?: string | null;
|
||||
error?: string | null;
|
||||
products_synced?: number | null;
|
||||
products_total?: number | null;
|
||||
products_skipped?: number | null;
|
||||
@@ -143,15 +145,40 @@ export function sortFeedListRows(
|
||||
return [...list].sort((a, b) => compareFeedListRows(a, b, field, direction));
|
||||
}
|
||||
|
||||
/** Report historical bad 0/N completed syncs as a problem, never a success. */
|
||||
export function syncJobDisplayStatus(job: FeedSyncJobLike): string {
|
||||
const status = String(job.status ?? "unknown").toLowerCase();
|
||||
if (status === "completed" && Number(job.products_synced ?? 0) === 0 &&
|
||||
Number(job.products_unchanged ?? 0) === 0) {
|
||||
if (Number(job.products_skipped ?? 0) > 0) return "skipped all";
|
||||
return "empty";
|
||||
}
|
||||
if (status === "completed" && Number(job.products_skipped ?? 0) > 0) return "partial";
|
||||
return status;
|
||||
}
|
||||
|
||||
export function syncJobDiagnostic(job: FeedSyncJobLike): string {
|
||||
const explicit = String(job.error ?? "").trim();
|
||||
if (explicit) return explicit;
|
||||
const status = syncJobDisplayStatus(job);
|
||||
if (status === "skipped all") {
|
||||
return `All ${Number(job.products_skipped ?? 0)} rows were skipped. Check that GTIN is mapped and the source CSV header is recognized.`;
|
||||
}
|
||||
if (status === "empty") {
|
||||
return "No products were imported. Check the CSV source and field mappings.";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function syncJobStatusTone(status: string | null | undefined): string {
|
||||
const s = String(status ?? "").toLowerCase();
|
||||
if (s === "completed" || s === "success" || s === "ok") {
|
||||
return "border-chart-green/40 bg-card-green text-foreground";
|
||||
}
|
||||
if (s === "failed" || s === "error") {
|
||||
if (s === "failed" || s === "error" || s === "skipped all" || s === "empty") {
|
||||
return "border-destructive/40 bg-card-red text-foreground";
|
||||
}
|
||||
if (s === "running" || s === "pending" || s === "queued" || s === "processing") {
|
||||
if (s === "partial" || s === "running" || s === "pending" || s === "queued" || s === "processing") {
|
||||
return "border-chart-amber/50 bg-chart-amber/15 text-foreground";
|
||||
}
|
||||
return "border-border bg-muted text-foreground";
|
||||
|
||||
Reference in new issue
Block a user