import {describe, it} from 'node:test'; import assert from 'node:assert/strict'; import {CATEGORY, Key} from './category'; describe('Key', () => { describe('return shape', () => { it('returns an object with exactly the keys id, label, value and url', () => { const result = Key('Accounting / Auditing / Taxation', 'accounting'); assert.deepStrictEqual(Object.keys(result).sort(), ['id', 'label', 'url', 'value']); }); it('passes label and url through unchanged', () => { const result = Key('Some Label', 'some-url'); assert.strictEqual(result.label, 'Some Label'); assert.strictEqual(result.url, 'some-url'); }); it('sets value equal to label', () => { const result = Key('Some Label', 'some-url'); assert.strictEqual(result.value, result.label); assert.strictEqual(result.value, 'Some Label'); }); }); describe('properties', () => { it('is deterministic: identical inputs produce identical results', () => { assert.deepStrictEqual(Key('Design', 'design'), Key('Design', 'design')); }); it('is pure: each call returns a new, independently mutable object', () => { const first = Key('Design', 'design'); const second = Key('Design', 'design'); assert.notStrictEqual(first, second); first.id = 'mutated'; assert.strictEqual(second.id, 'design'); }); }); describe('CATEGORY data safeguard', () => { const expectedIds: Record = { accounting: 'accounting', admin: 'admin', advertising: 'advertising', architecture: 'architecture', 'banking-finance': 'banking_finance', 'building-construction': 'building_construction', consulting: 'consulting', 'customer-service': 'customer_service', design: 'design', 'education-training': 'education_training', engineering: 'engineering', entertainment: 'entertainment', environment: 'environment', events: 'events', 'food-and-beverage': 'food_and_beverage', 'general-management': 'general_management', 'general-work': 'general_work', healthcare: 'healthcare', hospitality: 'hospitality', 'human-resources': 'human_resources', 'information-technology': 'information_technology', insurance: 'insurance', legal: 'legal', logistics: 'logistics', manufacturing: 'manufacturing', marketing: 'marketing', medical: 'medical', others: 'others', 'personal-care': 'personal_care', 'professional-services': 'professional_services', public: 'public', purchasing: 'purchasing', 'real-estate': 'real_estate', 'repair-maintenance': 'repair_maintenance', 'risk-management': 'risk_management', sales: 'sales', sciences: 'sciences', security: 'security', 'social-services': 'social_services', telecommunications: 'telecommunications', travel: 'travel', 'wholesale-trade': 'wholesale_trade', 'precision-engineering': 'precision_engineering', }; Object.values(CATEGORY).forEach((entry) => { it(`derives id "${expectedIds[entry.url]}" for CATEGORY url "${entry.url}"`, () => { assert.strictEqual(entry.id, expectedIds[entry.url]); }); it(`reconstructs the full CATEGORY entry for url "${entry.url}" from Key`, () => { assert.deepStrictEqual(Key(entry.label, entry.url), entry); }); }); it('covers every CATEGORY url with an expected id assertion', () => { const categoryUrls = Object.values(CATEGORY) .map((entry) => entry.url) .sort(); const expectedUrls = Object.keys(expectedIds).sort(); assert.deepStrictEqual(categoryUrls, expectedUrls); }); }); });