56 lines
2 KiB
TypeScript
56 lines
2 KiB
TypeScript
|
|
import { describe, expect, it } from 'vitest';
|
||
|
|
import { evaluateVisibility, normalizeRoleKey, schemaIdFromInput } from './onboarding-flow';
|
||
|
|
|
||
|
|
describe('normalizeRoleKey', () => {
|
||
|
|
it('normalizes case and separators', () => {
|
||
|
|
expect(normalizeRoleKey('job seeker')).toBe('JOB_SEEKER');
|
||
|
|
expect(normalizeRoleKey('job-seeker')).toBe('JOB_SEEKER');
|
||
|
|
expect(normalizeRoleKey(' photographer ')).toBe('PHOTOGRAPHER');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('schemaIdFromInput', () => {
|
||
|
|
it('maps major role schemas', () => {
|
||
|
|
expect(schemaIdFromInput('CUSTOMER', '')).toBe('customer_onboarding_v1');
|
||
|
|
expect(schemaIdFromInput('COMPANY', '')).toBe('company_onboarding_v1');
|
||
|
|
expect(schemaIdFromInput('JOB_SEEKER', '')).toBe('jobseeker_onboarding_v1');
|
||
|
|
expect(schemaIdFromInput('jobseeker', '')).toBe('jobseeker_onboarding_v1');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('maps professional schema with profession key', () => {
|
||
|
|
expect(schemaIdFromInput('PROFESSIONAL', 'Photographer')).toBe('photographer_onboarding_v1');
|
||
|
|
expect(schemaIdFromInput('professional', 'Social Media Manager')).toBe('social_media_manager_onboarding_v1');
|
||
|
|
expect(schemaIdFromInput('PROFESSIONAL', 'Fitness-Trainer')).toBe('fitness_trainer_onboarding_v1');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('falls back for generic professional when no profession', () => {
|
||
|
|
expect(schemaIdFromInput('PROFESSIONAL', '')).toBe('professional_onboarding_v1');
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('evaluateVisibility', () => {
|
||
|
|
it('supports equals conditions', () => {
|
||
|
|
const visible = evaluateVisibility(
|
||
|
|
[{ field: 'profession', equals: 'photographer' }],
|
||
|
|
{ profession: 'photographer' },
|
||
|
|
);
|
||
|
|
expect(visible).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('supports in conditions', () => {
|
||
|
|
const visible = evaluateVisibility(
|
||
|
|
[{ field: 'service_mode', in: ['remote', 'hybrid'] }],
|
||
|
|
{ service_mode: 'hybrid' },
|
||
|
|
);
|
||
|
|
expect(visible).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('returns false when condition mismatches', () => {
|
||
|
|
const visible = evaluateVisibility(
|
||
|
|
[{ field: 'profession', equals: 'developer' }],
|
||
|
|
{ profession: 'tutor' },
|
||
|
|
);
|
||
|
|
expect(visible).toBe(false);
|
||
|
|
});
|
||
|
|
});
|