Files
jobtrackingapp/JobTrackerApi.Tests/RulesEngineProspectTests.cs
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

83 lines
2.6 KiB
C#

using System;
using JobTrackerApi.Models;
using JobTrackerApi.Services;
using Xunit;
namespace JobTrackerApi.Tests;
/// <summary>
/// Guards the rule that matters most after Phase 0 added pre-application stages: a job the user
/// has not applied to must never be chased for a reply or auto-ghosted. Nothing was submitted,
/// so there is nobody to follow up with and nobody to be ghosted by.
/// </summary>
public sealed class RulesEngineProspectTests
{
private static readonly RuleSettings AggressiveSettings = new()
{
Id = 1,
AppliedFollowUpDays = 1,
AppliedGhostDays = 2,
OfferFollowUpDays = 1,
OfferGhostDays = 2,
FeedbackFollowUpDays = 1,
FeedbackGhostDays = 2,
};
private static readonly DateTime Now = new(2026, 7, 17, 12, 0, 0, DateTimeKind.Utc);
[Theory]
[InlineData("Saved")]
[InlineData("Interested")]
[InlineData("Preparing")]
public void A_prospect_is_never_followed_up_or_ghosted_however_old(string status)
{
// Saved a year ago with thresholds of 1-2 days: an unguarded rule would ghost this.
var job = new JobApplication
{
Status = status,
DateApplied = null,
SavedAt = Now.AddDays(-365),
};
var decision = RulesEngine.Evaluate(AggressiveSettings, job, Now, lastMessageAt: null);
Assert.False(decision.NeedsFollowUp);
Assert.False(decision.ShouldGhost);
}
[Fact]
public void An_applied_job_with_no_applied_date_is_not_ghosted()
{
// Shouldn't happen (SyncAppliedDate stamps on the way into Applied), but a null must fail
// safe rather than be read as "infinitely old" and silently ghost the job.
var job = new JobApplication
{
Status = "Applied",
DateApplied = null,
SavedAt = Now.AddDays(-365),
};
var decision = RulesEngine.Evaluate(AggressiveSettings, job, Now, lastMessageAt: null);
Assert.False(decision.NeedsFollowUp);
Assert.False(decision.ShouldGhost);
}
[Fact]
public void An_applied_job_past_the_threshold_still_ghosts()
{
// The guards above must not have disabled the actual rule.
var job = new JobApplication
{
Status = "Applied",
DateApplied = Now.AddDays(-30),
SavedAt = Now.AddDays(-31),
};
var decision = RulesEngine.Evaluate(AggressiveSettings, job, Now, lastMessageAt: null);
Assert.True(decision.NeedsFollowUp);
Assert.True(decision.ShouldGhost);
}
}