← back to Rentv Adintel
test/classification.test.js
85 lines
'use strict';
/**
* Tests for the classification guard (spec §6.16, §2, §21).
* The module is being written concurrently by a teammate; import it
* defensively and t.skip() every case if it isn't present yet so
* `node --test` never hard-crashes.
*
* Rule under test: a SPEAKER_OR_PANELIST_ONLY relationship may NOT be promoted
* to a verified sponsor/advertiser status without separate sponsor evidence
* (§6.16 "Do not treat a panelist as a sponsor without sponsor evidence"; the
* CoStar content-partner seed in §21 must not be mislabeled either).
*/
const test = require('node:test');
const assert = require('node:assert');
let classification;
try {
classification = require('../lib/classification');
} catch (_e) {
classification = null;
}
test('promoting panelist -> verified sponsor WITHOUT evidence throws', (t) => {
if (!classification || !classification.assertNotPanelistMislabeledAsSponsor) {
return t.skip('classification not present yet');
}
assert.throws(() =>
classification.assertNotPanelistMislabeledAsSponsor(
'SPEAKER_OR_PANELIST_ONLY',
'VERIFIED_CONFERENCE_SPONSOR',
false // hasSponsorEvidence
)
);
});
test('promoting panelist -> verified sponsor WITH evidence does not throw', (t) => {
if (!classification || !classification.assertNotPanelistMislabeledAsSponsor) {
return t.skip('classification not present yet');
}
assert.doesNotThrow(() =>
classification.assertNotPanelistMislabeledAsSponsor(
'SPEAKER_OR_PANELIST_ONLY',
'VERIFIED_CONFERENCE_SPONSOR',
true // hasSponsorEvidence
)
);
});
test('promoting panelist -> verified ADVERTISER without evidence throws', (t) => {
if (!classification || !classification.assertNotPanelistMislabeledAsSponsor) {
return t.skip('classification not present yet');
}
assert.throws(() =>
classification.assertNotPanelistMislabeledAsSponsor(
'SPEAKER_OR_PANELIST_ONLY',
'VERIFIED_ADVERTISER',
false
)
);
});
test('a non-panelist starting status is not blocked by the guard', (t) => {
if (!classification || !classification.assertNotPanelistMislabeledAsSponsor) {
return t.skip('classification not present yet');
}
// A RESEARCH_NEEDED -> VERIFIED_CONFERENCE_SPONSOR transition is out of scope
// of the panelist rule; it should not throw for lack of sponsor evidence here.
assert.doesNotThrow(() =>
classification.assertNotPanelistMislabeledAsSponsor(
'RESEARCH_NEEDED',
'VERIFIED_CONFERENCE_SPONSOR',
false
)
);
});
test('statusLabel returns a plain-English label', (t) => {
if (!classification || !classification.statusLabel) {
return t.skip('classification.statusLabel not present yet');
}
assert.strictEqual(typeof classification.statusLabel('VERIFIED_ADVERTISER'), 'string');
assert.ok(classification.statusLabel('VERIFIED_ADVERTISER').length > 0);
});