Files
jobtrackingapp/job-tracker-ui/src/pipeline.test.ts
T
cesnimda eac34705e3 feat: Phase 0 foundation — Job entity, expanded pipeline, AI service lockdown, DateApplied history
Unblocks the documented core workflow and closes the AI-service exposure,
without changing existing behaviour.

Job/JobApplication split (additive; see ADR-002):
- New Job entity (the opportunity) with owner-scoped query filter; nullable
  JobApplication.JobId FK. Nothing reads Job yet.
- Migration AddJobEntityAndProspectStages, hand-edited to drop reconciler-owned
  tables the scaffolder re-emitted; verified against the real dev DB.

Pipeline: 10 internal stages across three concerns kept separate —
PipelineStage (workflow) / PipelineGroup (UI: NotApplied/Active/Closed) /
PipelineCategory (analytics). Adds Saved/Interested/Preparing/Withdrawn;
keeps Waiting and Ghosted. Kanban shows 3 grouped columns; cards keep a stage
chip and full transitions; drag applies only safe transitions (never infers
Ghosted/Withdrawn).

DateApplied nullable + SavedAt. Cleared when leaving Applied so analytics stay
accurate; the discarded date is preserved as an AppliedDateCleared JobEvent.

AI service lockdown: no host port; private ai_internal network (backend is the
only other member); X-Ai-Service-Token required on all non-/health endpoints;
AI_SERVICE_TOKEN mandatory via compose. Verified backend-only against the live
stack.

Also carries two pre-existing working-tree files (views/ProfilePage.tsx,
views/CareerWorkspacePage.tsx) so the tree is clean for the branch integration.

Tests: +40 backend (247 total), +5 sidecar (16), +15 frontend.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 17:05:25 +02:00

110 lines
4.3 KiB
TypeScript

import {
GROUP_ENTRY_STATUS,
PIPELINE_GROUPS,
PIPELINE_STATUSES,
groupOf,
isProspect,
normalizeStatus,
statusLabel,
statusTone,
} from './pipeline';
describe('pipeline', () => {
test('normalizeStatus canonicalizes casing and synonyms', () => {
expect(normalizeStatus('applied')).toBe('Applied');
expect(normalizeStatus(' OFFER ')).toBe('Offer');
expect(normalizeStatus('Interviewing')).toBe('Interview');
expect(normalizeStatus('declined')).toBe('Rejected');
});
test('normalizeStatus preserves unknown as Other and empty as Applied', () => {
expect(normalizeStatus('Take-home')).toBe('Other');
expect(normalizeStatus('')).toBe('Applied');
expect(normalizeStatus(null)).toBe('Applied');
});
test('statusTone maps stages to palette keys', () => {
expect(statusTone('Offer')).toBe('success');
expect(statusTone('Rejected')).toBe('error');
expect(statusTone('Waiting')).toBe('warning');
expect(statusTone('Ghosted')).toBe('warning');
expect(statusTone('Interview')).toBe('info');
expect(statusTone('Applied')).toBe('primary');
expect(statusTone('Take-home')).toBe('default');
});
test('statusLabel localizes canonical and passes through custom', () => {
const t = (key: string) => ({ statusApplied: 'Applied', statusOffer: 'Offer' } as Record<string, string>)[key] ?? key;
expect(statusLabel(t, 'Applied')).toBe('Applied');
expect(statusLabel(t, 'Interviewing')).toBe('statusInterview'); // maps to canonical key
expect(statusLabel(t, 'Take-home assignment')).toBe('Take-home assignment');
});
test('canonical stage list is stable and ordered', () => {
// Mirrors the backend JobPipeline.Stages. Waiting and Ghosted are retained deliberately:
// Ghosted is where the rules engine parks an unanswered job, and Waiting has its own
// follow-up rule.
expect(PIPELINE_STATUSES).toEqual([
'Saved',
'Interested',
'Preparing',
'Applied',
'Waiting',
'Interview',
'Offer',
'Rejected',
'Ghosted',
'Withdrawn',
]);
});
test('normalizeStatus canonicalizes the new stage synonyms', () => {
expect(normalizeStatus('bookmarked')).toBe('Saved');
expect(normalizeStatus('shortlisted')).toBe('Interested');
expect(normalizeStatus('drafting')).toBe('Preparing');
expect(normalizeStatus('withdrew')).toBe('Withdrawn');
expect(normalizeStatus('cancelled')).toBe('Withdrawn');
// Opposite directions: the employer declined you vs you pulled out.
expect(normalizeStatus('declined')).toBe('Rejected');
});
test('board groups match the agreed layout', () => {
expect(PIPELINE_GROUPS.map((g) => g.key)).toEqual(['NotApplied', 'Active', 'Closed']);
expect(PIPELINE_GROUPS[0].statuses).toEqual(['Saved', 'Interested', 'Preparing']);
expect(PIPELINE_GROUPS[1].statuses).toEqual(['Applied', 'Waiting', 'Interview', 'Offer']);
expect(PIPELINE_GROUPS[2].statuses).toEqual(['Rejected', 'Ghosted', 'Withdrawn']);
});
test('every stage belongs to exactly one group, and groups agree with the backend', () => {
const grouped = PIPELINE_GROUPS.flatMap((g) => g.statuses);
expect(grouped.slice().sort()).toEqual(PIPELINE_STATUSES.slice().sort());
expect(new Set(grouped).size).toBe(grouped.length);
});
test('groupOf and isProspect classify stages', () => {
expect(groupOf('Saved')).toBe('NotApplied');
expect(groupOf('Offer')).toBe('Active');
expect(groupOf('Withdrawn')).toBe('Closed');
expect(groupOf('Take-home assignment')).toBeNull();
expect(isProspect('Preparing')).toBe(true);
expect(isProspect('Applied')).toBe(false);
// Custom statuses predate the split and have always counted as applied.
expect(isProspect('Take-home assignment')).toBe(false);
});
test('drag entry stages never infer Ghosted or Withdrawn', () => {
// A coarse drag must not claim the rules engine's conclusion (Ghosted) or the user's own
// action (Withdrawn).
expect(GROUP_ENTRY_STATUS).toEqual({ NotApplied: 'Saved', Active: 'Applied', Closed: 'Rejected' });
});
test('statusTone covers every stage', () => {
expect(statusTone('Saved')).toBe('default');
expect(statusTone('Withdrawn')).toBe('error');
for (const s of PIPELINE_STATUSES) {
expect(typeof statusTone(s)).toBe('string');
}
});
});