gunk-dev/the-valley

batch_test.go

source30e24c82839bmain's published tip history
1.7 KiB
1package github
2
3import "testing"
4
5// TestParseSnapshots: a PR GraphQL reports NOT_FOUND reads NOACCESS, one
6// with another error on it or a field is left out to keep its last status,
7// and a bot's
8// login gets back the "[bot]" suffix trusted_reviewers names it by.
9func TestParseSnapshots(t *testing.T) {
10 body := `{"data": {"viewer": {"login": "op"}, "repository": {
11 "pr1": {"state": "OPEN", "mergeable": "CONFLICTING", "headRefOid": "h1", "baseRef": {"target": {"oid": "b"}},
12 "commits": {"nodes": [{"commit": {"statusCheckRollup": {"state": "FAILURE"}}}]},
13 "author": {"__typename": "User", "login": "op"},
14 "reviews": {"nodes": [{"databaseId": 7, "author": {"__typename": "Bot", "login": "gemini-code-assist"}, "state": "COMMENTED"}]}},
15 "pr2": null, "pr3": null, "pr4": {"state": "OPEN", "commits": {"nodes": [{"commit": {"statusCheckRollup": null}}]}}}},
16 "errors": [{"type": "NOT_FOUND", "path": ["repository", "pr2"]}, {"type": "INTERNAL", "path": ["repository", "pr3"]},
17 {"type": "INTERNAL", "path": ["repository", "pr4", "commits", "nodes", 0, "commit", "statusCheckRollup"]}]}`
18 got, err := parseSnapshots([]byte(body), []int{1, 2, 3, 4})
19 if err != nil {
20 t.Fatal(err)
21 }
22 if s := got[1]; s == nil || s.CI != "failing" || s.Conflicts != "yes" || s.BaseSHA != "b" ||
23 s.Activity == nil || s.Activity.Operator != "op" || s.Activity.Reviews[0].Author != "gemini-code-assist[bot]" {
24 t.Errorf("PR 1 = %+v", got[1])
25 }
26 if s := got[2]; s == nil || s.State != StateNoAccess {
27 t.Errorf("NOT_FOUND PR 2 = %+v, want NOACCESS", got[2])
28 }
29 if s, ok := got[3]; ok {
30 t.Errorf("PR 3, null for an internal error, = %+v, want left out", s)
31 }
32 if s, ok := got[4]; ok {
33 t.Errorf("PR 4, whose check rollup failed, = %+v, want left out", s)
34 }
35}