← back to Tk 10965 Zero Price Analysis

prevention/inventory-stamp-guard.test.mjs

57 lines

// TK-10965 — Fix B guard unit test. Pure/offline. Run: node prevention/inventory-stamp-guard.test.mjs
// exit 0 = all pass, exit 1 = a case regressed. $0 (local).
import assert from 'node:assert/strict';
import { safeStampQuantity, isZeroPriceOrderableRisk, isPriceSuppressed } from './inventory-stamp-guard.mjs';

let pass = 0;
const t = (name, fn) => { fn(); pass++; console.log(`  ✓ ${name}`); };

// --- The defect classes the guard MUST neutralize (stamp 0, not 2026) ---
t('PR quote-only $0 Full Roll → 0', () => {
  const product = { vendor: 'Phillipe Romano', tags: ['quote-only', 'contract-vinyl'] };
  const variant = { title: 'Full Roll', price: '0.00' };
  assert.equal(isZeroPriceOrderableRisk(variant, product), true);
  assert.equal(safeStampQuantity(variant, product), 0);
});

t('Fentucci UNTAGGED (canary blind spot) $0 → 0 via vendor fallback', () => {
  const product = { vendor: 'Fentucci Naturals', tags: ['quotes', 'Needs-Price'] };
  const variant = { title: 'Full Roll', price: '0.00' };
  assert.equal(isPriceSuppressed(product), true);
  assert.equal(safeStampQuantity(variant, product), 0);
});

t('price-suppressed even if price were nonzero → 0', () => {
  // Belt-and-suspenders: a quote-only line should never advertise stock regardless of price.
  const product = { vendor: 'X', tags: ['contact-for-price'] };
  assert.equal(safeStampQuantity({ title: 'Full Roll', price: '12.00' }, product), 0);
});

t('NaN/missing price on sellable variant → 0 (fail safe)', () => {
  assert.equal(safeStampQuantity({ title: 'Full Roll', price: undefined }, { vendor: 'X', tags: [] }), 0);
});

t('tags as comma-string (Shopify REST shape) still detected → 0', () => {
  const product = { vendor: 'X', tags: 'contract-vinyl, quote_only, new' };
  assert.equal(safeStampQuantity({ title: 'Full Roll', price: '0.00' }, product), 0);
});

// --- The rows the guard MUST NOT touch (still stamp 2026) ---
t('normal priced line (De Gournay-style) → 2026', () => {
  const product = { vendor: 'De Gournay', tags: ['hand-painted'] };
  assert.equal(safeStampQuantity({ title: 'Full Roll', price: '480.00' }, product), 2026);
});

t('Sample variant is never the sellable one → untouched (2026)', () => {
  // The $4.25 Sample variant is not the sellable variant; guard is a no-op on it.
  const product = { vendor: 'Phillipe Romano', tags: ['quote-only'] };
  assert.equal(isZeroPriceOrderableRisk({ title: 'Sample', price: '4.25' }, product), false);
  assert.equal(safeStampQuantity({ title: 'Sample', price: '4.25' }, product), 2026);
});

t('custom desired value is honored for safe rows', () => {
  assert.equal(safeStampQuantity({ title: 'Full Roll', price: '99.00' }, { tags: [] }, 100), 100);
});

console.log(`\nALL ${pass} CASES PASS ✅  — guard stamps 0 on the $0-orderable class, 2026 otherwise.`);