Add application workflow and lead analytics
Test and publish / test (push) Successful in 2m33s
Test and publish / publish (push) Successful in 11m9s

This commit is contained in:
2026-10-23 20:45:48 +01:00
parent d0074aea46
commit 1147bc5697
35 changed files with 4337 additions and 131 deletions
+41
View File
@@ -0,0 +1,41 @@
package services
import (
"testing"
"time"
"adam-french.co.uk/job-tracker/internal/models"
)
func TestAggregateAnalyticsCountsFunnelAndTransitions(t *testing.T) {
base := time.Date(2026, 1, 1, 9, 0, 0, 0, time.UTC)
applied := base.Add(24 * time.Hour)
apps := []*models.JobApplication{{ID: 1, Status: "interviewing", AppliedAt: &applied}, {ID: 2, Status: "saved"}, {ID: 3, Status: "offer", AppliedAt: &applied}}
note := func(value string) *string { return &value }
events := []*models.JobApplicationEvent{
{JobApplicationID: 1, Kind: "status_changed", OccurredAt: base.Add(3 * 24 * time.Hour), Note: note("applied -> screening")},
{JobApplicationID: 1, Kind: "interview", OccurredAt: base.Add(5 * 24 * time.Hour)},
{JobApplicationID: 3, Kind: "status_changed", OccurredAt: base.Add(4 * 24 * time.Hour), Note: note("applied -> offer")},
}
got := AggregateAnalytics(apps, events)
if got.TotalApplications != 3 || got.ResponseCount != 2 || got.InterviewCount != 2 || got.OfferCount != 1 {
t.Fatalf("counts = %+v", got)
}
if got.ResponseRate != 2.0/3.0 || got.OfferRate != 1.0/3.0 {
t.Fatalf("rates = %+v", got)
}
if len(got.Transitions) != 2 || got.Transitions[0].Count != 1 {
t.Fatalf("transitions = %+v", got.Transitions)
}
if got.AverageDaysToResponse == nil || *got.AverageDaysToResponse != 2.5 {
t.Fatalf("response days = %v", got.AverageDaysToResponse)
}
}
func TestAggregateAnalyticsLeavesUnsupportedTimeMetricsNil(t *testing.T) {
apps := []*models.JobApplication{{ID: 1, Status: "saved"}}
got := AggregateAnalytics(apps, nil)
if got.AverageDaysToResponse != nil || got.AverageDaysToInterview != nil || got.AverageDaysToOffer != nil {
t.Fatalf("metrics = %+v", got)
}
}