| 1 | package plan3test |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/library" |
| 5 | "amadan.net/oficina/equipo/internal/taskplan" |
| 6 | "encoding/json" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func TestFinalFixSpecialistCounts(t *testing.T) { |
| 12 | for _, kind := range []string{"recommendation", "investigation", "feature", "copy", "design"} { |
| 13 | t.Run(kind, func(t *testing.T) { |
| 14 | f := newFixture(t) |
| 15 | p := proposed(t, f) |
| 16 | f.exec(t, "DELETE FROM tasks WHERE id<>?", p.TaskID) |
| 17 | specialist, action := "product", "recommend" |
| 18 | if kind == "feature" { |
| 19 | specialist, action = "engineering", "implement" |
| 20 | } |
| 21 | if kind == "copy" || kind == "design" { |
| 22 | specialist, action = kind, kind |
| 23 | } |
| 24 | p.Steps = []taskplan.Step{{Key: "one", Specialist: specialist, Action: action}, {Key: "two", Specialist: specialist, Action: action}, {Key: "person", Action: "person"}} |
| 25 | if kind == "feature" { |
| 26 | p.Steps = append(p.Steps[:1], p.Steps[2:]...) |
| 27 | } |
| 28 | raw, err := json.Marshal(p) |
| 29 | must(t, err) |
| 30 | f.exec(t, "UPDATE plan_revisions SET plan=? WHERE task_id=?", string(raw), p.TaskID) |
| 31 | upgradeRow(t, f, "jobs", map[string]any{"id": 1, "account": f.TeamID, "state": "running"}) |
| 32 | f.exec(t, "UPDATE tasks SET job_id=1,state='queued' WHERE id=?", p.TaskID) |
| 33 | keys := []string{"one", "two"} |
| 34 | if kind == "feature" { |
| 35 | keys = keys[:1] |
| 36 | } |
| 37 | for i, key := range keys { |
| 38 | upgradeRow(t, f, "steps", map[string]any{"id": i + 1, "job_id": 1, "key": key, "state": "pending", "capability": "implement"}) |
| 39 | } |
| 40 | for _, state := range []string{"pending", "running", "succeeded"} { |
| 41 | f.exec(t, "UPDATE steps SET state=?", state) |
| 42 | counts, err := library.Counts(f.DB.G, f.TeamID, time.Now()) |
| 43 | must(t, err) |
| 44 | for key, v := range counts { |
| 45 | total := v.Working + v.Queued + v.Finished + v.Waiting |
| 46 | if key != specialist && total != 0 { |
| 47 | t.Errorf("non-participating %s counted: %+v", key, v) |
| 48 | } |
| 49 | if key == specialist && (total != 1 || state == "succeeded" && v.Finished != 1 || state == "running" && v.Working != 1 || state == "pending" && v.Queued != 1) { |
| 50 | t.Errorf("%s %s count: %+v", key, state, v) |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | }) |
| 55 | } |
| 56 | } |
| 57 | |