Split the job tracker out of web_server into its own app
The applications tracker, leads inbox, email pipeline and capture userscript move here from web_server's backend, Python service and Vue app, as one Go binary that serves its own Vue SPA under /jobs/. - The Go services, resolvers and tests move over almost unchanged. - The three Claude calls are ported from Python to Go (internal/claude), with the same prompts, per-model request shaping and error messages. - There is no login: internal/auth asks the site backend's /auth/validate-admin with the visitor's cookies, and relays refreshed cookies back. - A Settings page replaces the admin-panel capture token card and adds the Microsoft sign-in link and a manual email sync. - The userscript is 2.0.0, at /jobs/, and migrates a saved API base. - Dockerfile, a standalone compose with Postgres, Makefile, and a Gitea CI workflow that tests and publishes the image. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package services
|
||||
|
||||
import "testing"
|
||||
|
||||
// These tests cover the status progression rule only — StatusAdvances, the
|
||||
// predicate extracted out of updateJobApplication. The rest of
|
||||
// updateJobApplication (note appending, the DB.Save, the returned counters)
|
||||
// needs a live *gorm.DB and the only driver in go.mod is postgres, so it is
|
||||
// deliberately not exercised here. Nothing in this file touches the classifier
|
||||
// or the Graph API either; see email_classify_test.go for the former.
|
||||
|
||||
func TestStatusAdvances(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
current string
|
||||
next string
|
||||
want bool
|
||||
}{
|
||||
{"one step forward is the normal case", "applied", "screening", true},
|
||||
{"skipping intermediate stages still advances", "applied", "offer", true},
|
||||
{"adjacent step backwards is refused", "interviewing", "assessment", false},
|
||||
{"a long way backwards is refused", "offer", "applied", false},
|
||||
{"same status is not progression, so a duplicate email is a no-op", "screening", "screening", false},
|
||||
|
||||
// rejected and withdrawn sit at the top of statusOrder: once an
|
||||
// application lands there, no later email may move it.
|
||||
{"rejected cannot fall back to interviewing", "rejected", "interviewing", false},
|
||||
{"rejected cannot fall back to offer", "rejected", "offer", false},
|
||||
{"rejected cannot repeat", "rejected", "rejected", false},
|
||||
{"withdrawn cannot fall back to offer", "withdrawn", "offer", false},
|
||||
{"withdrawn cannot fall back to rejected", "withdrawn", "rejected", false},
|
||||
{"withdrawn cannot repeat", "withdrawn", "withdrawn", false},
|
||||
// The one ordering asymmetry between the two terminals: withdrawn
|
||||
// ranks above rejected, so this single pair is allowed.
|
||||
{"rejected may still become withdrawn because withdrawn ranks higher", "rejected", "withdrawn", true},
|
||||
|
||||
// saved is a browser capture that has not been applied to yet.
|
||||
{"a saved posting advances once the application is confirmed", "saved", "applied", true},
|
||||
{"an applied row cannot fall back to saved", "applied", "saved", false},
|
||||
|
||||
{"an unknown new status is never applied", "applied", "hired", false},
|
||||
{"an empty new status is never applied", "applied", "", false},
|
||||
{"an unknown new status cannot escape a terminal state either", "rejected", "ghosted", false},
|
||||
{"a recognised status takes over from an unknown current status", "ghosted", "applied", true},
|
||||
{"a recognised status takes over from an empty current status", "", "offer", true},
|
||||
{"unknown to unknown stays put", "ghosted", "hired", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := StatusAdvances(c.current, c.next); got != c.want {
|
||||
t.Errorf("StatusAdvances(%q, %q) = %v, want %v", c.current, c.next, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Guards the claim the other tests rest on: rejected and withdrawn really are
|
||||
// the top of the ranking, so adding a stage below them cannot silently make
|
||||
// them non-terminal.
|
||||
func TestTerminalStatusesRankHighest(t *testing.T) {
|
||||
for status, order := range statusOrder {
|
||||
if status == "rejected" || status == "withdrawn" {
|
||||
continue
|
||||
}
|
||||
if order >= statusOrder["rejected"] {
|
||||
t.Errorf("%q ranks %d, at or above rejected (%d)", status, order, statusOrder["rejected"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizeStatus is the guard that keeps Claude's occasional casing drift
|
||||
// ("Interview", "on hold") out of the status column: an unrecognised value
|
||||
// stored verbatim makes StatusAdvances treat the row's current status as
|
||||
// unknown, which switches the forward-only rule off for that row entirely.
|
||||
func TestNormalizeStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"a tracked status passes through", "interviewing", "interviewing"},
|
||||
{"saved is tracked, so a capture keeps it", "saved", "saved"},
|
||||
{"casing drift is lowered, not rejected", "Interviewing", "interviewing"},
|
||||
{"surrounding whitespace is trimmed", " offer ", "offer"},
|
||||
{"an untracked status falls back to the pipeline default", "on hold", "applied"},
|
||||
{"the UI's old Title Case value is recognised once lowered", "Rejected", "rejected"},
|
||||
{"a value the UI once allowed but the pipeline never had is rejected", "Interview", "applied"},
|
||||
{"empty falls back rather than storing a blank status", "", "applied"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := NormalizeStatus(c.in); got != c.want {
|
||||
t.Errorf("NormalizeStatus(%q) = %q, want %q", c.in, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user