package plan3test import ( "amadan.net/oficina/equipo/internal/equipo/library" "amadan.net/oficina/equipo/internal/taskplan" "encoding/json" "testing" "time" ) func TestFinalFixSpecialistCounts(t *testing.T) { for _, kind := range []string{"recommendation", "investigation", "feature", "copy", "design"} { t.Run(kind, func(t *testing.T) { f := newFixture(t) p := proposed(t, f) f.exec(t, "DELETE FROM tasks WHERE id<>?", p.TaskID) specialist, action := "product", "recommend" if kind == "feature" { specialist, action = "engineering", "implement" } if kind == "copy" || kind == "design" { specialist, action = kind, kind } p.Steps = []taskplan.Step{{Key: "one", Specialist: specialist, Action: action}, {Key: "two", Specialist: specialist, Action: action}, {Key: "person", Action: "person"}} if kind == "feature" { p.Steps = append(p.Steps[:1], p.Steps[2:]...) } raw, err := json.Marshal(p) must(t, err) f.exec(t, "UPDATE plan_revisions SET plan=? WHERE task_id=?", string(raw), p.TaskID) upgradeRow(t, f, "jobs", map[string]any{"id": 1, "account": f.TeamID, "state": "running"}) f.exec(t, "UPDATE tasks SET job_id=1,state='queued' WHERE id=?", p.TaskID) keys := []string{"one", "two"} if kind == "feature" { keys = keys[:1] } for i, key := range keys { upgradeRow(t, f, "steps", map[string]any{"id": i + 1, "job_id": 1, "key": key, "state": "pending", "capability": "implement"}) } for _, state := range []string{"pending", "running", "succeeded"} { f.exec(t, "UPDATE steps SET state=?", state) counts, err := library.Counts(f.DB.G, f.TeamID, time.Now()) must(t, err) for key, v := range counts { total := v.Working + v.Queued + v.Finished + v.Waiting if key != specialist && total != 0 { t.Errorf("non-participating %s counted: %+v", key, v) } if key == specialist && (total != 1 || state == "succeeded" && v.Finished != 1 || state == "running" && v.Working != 1 || state == "pending" && v.Queued != 1) { t.Errorf("%s %s count: %+v", key, state, v) } } } }) } }