83 lines
4.1 KiB
JavaScript
83 lines
4.1 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import test from 'node:test';
|
|
import {
|
|
counterModeForRuntime,
|
|
resolveCounterConfig,
|
|
} from '../src/utils/counter-mode.ts';
|
|
import {
|
|
formAPreviewEnabled,
|
|
formModeForRuntime,
|
|
formRouteMapping,
|
|
logicalFormForRoute,
|
|
resolveFormMode,
|
|
resolveMockFormResult,
|
|
} from '../src/utils/form-integration.ts';
|
|
|
|
test('counter configuration defaults off and requires explicit approval', () => {
|
|
assert.deepEqual(resolveCounterConfig(undefined, undefined, undefined), { mode: 'off', reason: 'default-off' });
|
|
assert.equal(resolveCounterConfig('invalid', 'https://api.example.test', 'true').mode, 'off');
|
|
assert.equal(resolveCounterConfig('live', 'https://api.example.test', 'false').mode, 'off');
|
|
assert.equal(resolveCounterConfig('live', 'https://api.example.test', 'true').mode, 'live');
|
|
assert.equal(resolveCounterConfig('live', 'http://api.example.test', 'true').mode, 'off');
|
|
assert.equal(counterModeForRuntime(resolveCounterConfig('live', 'https://api.example.test', 'true')), 'off');
|
|
assert.equal(resolveCounterConfig('mock', undefined, undefined).mode, 'mock');
|
|
});
|
|
|
|
test('forms default live while native fixtures stay off and invalid settings throw', () => {
|
|
assert.deepEqual(resolveFormMode(undefined), { mode: 'live', reason: 'default-live' });
|
|
assert.throws(() => resolveFormMode('invalid'), /PUBLIC_AIA_FORMS_MODE/);
|
|
assert.equal(resolveFormMode('live').mode, 'live');
|
|
assert.equal(formModeForRuntime(resolveFormMode('live')), 'off');
|
|
assert.equal(resolveFormMode('off').mode, 'off');
|
|
assert.equal(resolveFormMode('mock').mode, 'mock');
|
|
assert.equal(resolveMockFormResult(undefined), 'success');
|
|
assert.equal(resolveMockFormResult('failed'), 'failed');
|
|
assert.equal(resolveMockFormResult('unavailable'), 'unavailable');
|
|
assert.equal(resolveMockFormResult('anything-else'), 'success');
|
|
});
|
|
|
|
test('Form A meeting preview requires explicit mock mode and remains staging-only', () => {
|
|
assert.equal(formAPreviewEnabled(undefined, 'false', 'mock'), false);
|
|
assert.equal(formAPreviewEnabled('true', undefined, 'off'), false);
|
|
assert.equal(formAPreviewEnabled('true', 'true', 'mock'), false);
|
|
assert.equal(formAPreviewEnabled('true', 'false', 'mock'), true);
|
|
assert.equal(formAPreviewEnabled('TRUE', 'FALSE', 'mock'), true);
|
|
});
|
|
|
|
test('form mapping covers eleven native instances and five landing journeys', () => {
|
|
assert.equal(formRouteMapping.filter((entry) => entry.kind === 'native-instance').length, 11);
|
|
assert.equal(formRouteMapping.filter((entry) => entry.kind === 'landing-journey').length, 5);
|
|
assert.equal(logicalFormForRoute('/contact'), 'general');
|
|
assert.equal(logicalFormForRoute('/es/client-consultation'), 'service');
|
|
assert.equal(logicalFormForRoute('/referrals'), undefined);
|
|
for (const route of ['/es/aba-therapy', '/es/autism-evaluations', '/es/learner-social-club']) {
|
|
assert.equal(logicalFormForRoute(route), 'service');
|
|
}
|
|
for (const route of ['/lp/aba-therapy', '/lp/aba-insurance', '/lp/aba-ahcccs', '/lp/aba-private-pay']) {
|
|
assert.equal(logicalFormForRoute(route), 'general');
|
|
}
|
|
assert.equal(logicalFormForRoute('/lp/early-intervention'), 'general');
|
|
assert.equal(logicalFormForRoute('/ar/contact'), undefined);
|
|
});
|
|
|
|
test('inactive source has no native form or live vendor destination', () => {
|
|
const sources = [
|
|
'src/components/ContactForm.astro',
|
|
'src/components/FormShell.astro',
|
|
'src/components/ServiceInquiryDrawer.astro',
|
|
].map((file) => fs.readFileSync(file, 'utf8')).join('\n');
|
|
assert.doesNotMatch(sources, /<form\b/);
|
|
assert.doesNotMatch(sources, /250727122848156/);
|
|
assert.doesNotMatch(sources, /jotform\.com/i);
|
|
assert.match(sources, /data-form-mode/);
|
|
});
|
|
|
|
test('counter source has no implicit production fallback or credentialed fetch', () => {
|
|
const source = fs.readFileSync('src/components/LikeViewCounter.astro', 'utf8');
|
|
assert.doesNotMatch(source, /api\.azinstitute4autism\.com/);
|
|
assert.doesNotMatch(source, /credentials:\s*['"]include/);
|
|
assert.doesNotMatch(source, /method:\s*['"](?:POST|DELETE)/);
|
|
assert.match(source, /data-counter-mode/);
|
|
});
|