← back to Dw Gemini Skip TK11321

test/mfr-gate.test.js

70 lines

'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const { mfrGate } = require('../lib/mfr-gate.js');

// KNOWN-GOOD: a real Carnegie code with a real color name in staging → PASS.
test('passes a real mfr code with a real staging color name', () => {
  assert.deepEqual(
    mfrGate({ vendor: 'Carnegie', mfr: '24121-windows', reusedAcrossVendors: false, stagingColorName: 'Oatmeal' }),
    { ok: true, reasons: [] });
});

// A real code with no staging row consulted still PASSes (fail-open on the fabricated dim).
test('passes a present code when no staging row is available', () => {
  assert.deepEqual(
    mfrGate({ vendor: 'Thibaut', mfr: 'T10958', reusedAcrossVendors: false, stagingColorName: null }),
    { ok: true, reasons: [] });
});

// KNOWN-FABRICATED: the Carnegie "Grain 6300 → 63002" member with a placeholder "Color 2".
test('BLOCKS the Carnegie fabricated <base>+<seq> code (placeholder color)', () => {
  const r = mfrGate({ vendor: 'Carnegie', mfr: '63002', reusedAcrossVendors: false, stagingColorName: 'Color 2' });
  assert.equal(r.ok, false);
  assert.ok(r.reasons.includes('mfr-sku-fabricated-placeholder-color'));
});

test('placeholder color regex tolerates casing / spacing / British spelling', () => {
  for (const c of ['Color 1', 'color 10', 'COLOR 12', 'Colour 3', 'colour10']) {
    const r = mfrGate({ vendor: 'Carnegie', mfr: '6300' + c.replace(/\D/g, ''), reusedAcrossVendors: false, stagingColorName: c });
    assert.equal(r.ok, false, `${c} should be treated as placeholder`);
  }
});

// (a) blank / null / 'unknown' → BLOCK.
test('BLOCKS a blank / null / unknown mfr code', () => {
  for (const mfr of ['', '   ', null, undefined, 'Unknown', 'UNKNOWN']) {
    const r = mfrGate({ vendor: 'Elitis', mfr, reusedAcrossVendors: false, stagingColorName: 'Chartreuse' });
    assert.equal(r.ok, false, `${String(mfr)} should block`);
    assert.ok(r.reasons.includes('mfr-sku-blank'));
  }
});

// (b) reused across vendors → BLOCK (internal-counter bug class).
test('BLOCKS a code reused across >1 vendor', () => {
  const r = mfrGate({ vendor: 'IKSEL', mfr: '800010', reusedAcrossVendors: true, stagingColorName: 'Ivory' });
  assert.equal(r.ok, false);
  assert.ok(r.reasons.includes('mfr-sku-reused-across-vendors'));
});

// by-colour exempt line (Novasuede) is never a mfr FAIL even with a blank code.
test('exempts by-colour lines (Novasuede) from the blank-code block', () => {
  assert.deepEqual(
    mfrGate({ vendor: 'Novasuede', mfr: '', reusedAcrossVendors: false, stagingColorName: null }),
    { ok: true, reasons: [] });
});

// a real color name on a present unique code → PASS even for Carnegie.
test('passes a Carnegie code whose staging color is a real name', () => {
  assert.deepEqual(
    mfrGate({ vendor: 'Carnegie', mfr: '62901-upholstery', reusedAcrossVendors: false, stagingColorName: 'Espresso' }),
    { ok: true, reasons: [] });
});

// defensive: garbage ctx never throws, fails closed on a blank.
test('handles a non-object ctx without throwing (fails closed)', () => {
  const r = mfrGate(null);
  assert.equal(r.ok, false);
  assert.ok(r.reasons.includes('mfr-sku-blank'));
});