oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package plan3test
2
3import (
4 "strconv"
5 "strings"
6 "testing"
7
8 "amadan.net/oficina/equipo/internal/equipo"
9 "amadan.net/oficina/equipo/internal/equipo/library"
10 "amadan.net/oficina/equipo/internal/taskplan"
11)
12
13func TestPlaybookForms(t *testing.T) {
14 f := newFixture(t)
15 base := f.createTask(t)
16 w := formPost(t, f, owner, "/playbooks", playbookForm(playbookInput("Browser saved"), "browser", 0))
17 expectHTTP(t, w, 303)
18 path := w.Header().Get("Location")
19 id := strings.TrimSuffix(strings.TrimPrefix(path, "/playbooks/"), "/edit")
20 row, err := f.Store.Playbook(ctx, owner, id)
21 must(t, err)
22 in := library.PlaybookFields(row)
23 in.Steps[0].Instructions = "Browser edit"
24 expectHTTP(t, formPost(t, f, owner, path, playbookForm(in, "edit", 1)), 303)
25 expectHTTP(t, formPost(t, f, owner, path, playbookForm(in, "edit", 1)), 303)
26 expectHTTP(t, formPost(t, f, owner, path, playbookForm(in, "stale", 1)), 409)
27 v := actionForm("default", 0)
28 v.Set("project_id", strconv.FormatInt(base.ProjectID, 10))
29 v.Set("kind", "bug")
30 v.Set("playbook_id", row.ID)
31 expectHTTP(t, formPost(t, f, owner, "/playbooks/defaults", v), 303)
32 f.exec(t, "UPDATE members SET role='member' WHERE address=?", peer.Address)
33 w = f.get(t, peer, "/playbooks/"+id)
34 expectHTTP(t, w, 200)
35 if !strings.Contains(w.Body.String(), "<fieldset disabled rst-stack>") || strings.Contains(w.Body.String(), "/archive") {
36 t.Fatal("noncreator has editing controls")
37 }
38 expectHTTP(t, formPost(t, f, peer, path, playbookForm(in, "steal", 2)), 403)
39 expectHTTP(t, formPost(t, f, owner, "/playbooks/"+id+"/archive", actionForm("default-archive", 2)), 409)
40 v = actionForm("install", 0)
41 v.Del("revision")
42 v.Set("version", "1")
43 expectHTTP(t, formPost(t, f, owner, "/playbook-templates/playbook_bug/install", v), 303)
44 var installed library.Playbook
45 must(t, f.DB.G.Where("template_id='playbook_bug'").First(&installed).Error)
46 expectHTTP(t, f.get(t, owner, "/playbooks/"+installed.ID+"/template-diff"), 200)
47 // Recommendations retain their no-publication exception even with defaults.
48 recommendation := taskplan.Plan{ProjectID: base.ProjectID, Kind: taskplan.Recommendation, Steps: []taskplan.Step{{Key: "research", Specialist: "product", Action: "recommend"}, {Key: "merge", Action: "person"}}}
49 p, err := f.Store.ProposePlan(ctx, owner, recommendation, equipo.Mutation{RequestID: "recommend"})
50 must(t, err)
51 if p.PlaybookID != "" {
52 t.Fatal("recommendation acquired publishing playbook")
53 }
54 if _, err = f.Store.InstantiatePlaybook(ctx, owner, id, p.TaskID); err == nil {
55 t.Fatal("recommendation accepted publishing playbook")
56 }
57}
58
59func TestPlaybookRecommendationCannotReuseSnapshot(t *testing.T) {
60 f := newFixture(t)
61 task := f.createTask(t)
62 row, err := f.Store.SavePlaybook(ctx, owner, playbookInput("Saved bug"), equipo.Mutation{RequestID: "save"})
63 must(t, err)
64 _, err = f.Store.InstantiatePlaybook(ctx, owner, row.ID, task.ID)
65 must(t, err)
66 p, err := f.Store.TaskPlan(ctx, owner, task.ID)
67 must(t, err)
68 p.Kind = taskplan.Recommendation
69 p.PlaybookID = ""
70 p.PlaybookRevision = 0
71 p.Steps = []taskplan.Step{{Key: "research", Specialist: "product", Action: "recommend"}, {Key: "merge", Action: "person"}}
72 _, err = f.Store.EditPlan(ctx, owner, p, equipo.Mutation{RequestID: "recommend", Revision: p.Revision})
73 must(t, err)
74 if _, err = f.Store.InstantiatePlaybook(ctx, owner, row.ID, task.ID); err == nil {
75 t.Fatal("recommendation reused publishing snapshot")
76 }
77}
78