Add application workflow and lead analytics
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user