| 57 | } |
| 58 | |
| 59 | func TestUpgradeDiff_Classes(t *testing.T) { |
| 60 | t.Parallel() |
| 61 | old := diffBase() |
| 62 | |
| 63 | same, err := diffUpgrade(old, clone(old), diffDigests, diffFresh("r1", "n1")) |
| 64 | if err != nil || len(same.Entries) != 0 || same.ReviewRequired { |
| 65 | t.Fatalf("an identical manifest diffed: %+v %v", same, err) |
| 66 | } |
| 67 | |
| 68 | // Removals and narrowing only: auto, no review. |
| 69 | n := clone(old) |
| 70 | n.Events = nil |
| 71 | n.ItemActions = nil |
| 72 | n.Scopes.Service.Access = "read" |
| 73 | n.CompanionPack.Collections = nil |
| 74 | d, err := diffUpgrade(old, n, diffDigests, diffFresh("r1", "n1")) |
| 75 | if err != nil { |
| 76 | t.Fatal(err) |
| 77 | } |
| 78 | if d.ReviewRequired { |
| 79 | t.Errorf("removals and narrowing required review: %+v", d.Entries) |
| 80 | } |
| 81 | if e := entryOf(t, d, "collection", "tickets"); e.Change != "released" || !strings.Contains(e.Detail, "data kept") { |
| 82 | t.Errorf("removed companion: %+v", e) |
| 83 | } |
| 84 | if len(d.Released) != 1 || d.Released[0] != "portal-tickets" { |
| 85 | t.Errorf("released %v", d.Released) |
| 86 | } |
| 87 | if e := entryOf(t, d, "access", "service"); e.Change != "narrowed" || e.Class != upgradeAuto { |
| 88 | t.Errorf("narrowing: %+v", e) |
| 89 | } |
| 90 | |
| 91 | // Each of these alone needs review. |
| 92 | for name, mut := range map[string]func(m *appmanifest.Manifest){ |
| 93 | "widen service": func(m *appmanifest.Manifest) { m.Scopes.Service.Access = "write"; old.Scopes.Service.Access = "read" }, |
| 94 | "widen delegated": func(m *appmanifest.Manifest) { m.Scopes.Delegated.Access = "write" }, |
| 95 | "add event": func(m *appmanifest.Manifest) { m.Events = append(m.Events, appmanifest.Event{Name: "comment.created"}) }, |
| 96 | "widen event": func(m *appmanifest.Manifest) { m.Events[0].Collections = []string{"tickets", "other"} }, |
| 97 | "change action": func(m *appmanifest.Manifest) { m.ItemActions[0].Path = "/elsewhere" }, |
| 98 | "redirect uris": func(m *appmanifest.Manifest) { m.RedirectURIs = []string{"https://portal.example/cb2"} }, |
| 99 | "webhook url": func(m *appmanifest.Manifest) { m.WebhookURL = "https://portal.example/hooks2" }, |
| 100 | "prose": func(m *appmanifest.Manifest) { m.Description = "now with more" }, |
| 101 | "add collection": func(m *appmanifest.Manifest) { |
| 102 | m.CompanionPack.Collections = append(m.CompanionPack.Collections, appmanifest.Collection{Key: "faq", Slug: "portal-faq"}) |
| 103 | }, |
| 104 | } { |
| 105 | t.Run(name, func(t *testing.T) { |
| 106 | base := diffBase() |
| 107 | old = base |
| 108 | n := clone(base) |
| 109 | mut(n) |
| 110 | d, err := diffUpgrade(old, n, diffDigests, diffFresh("r1", "n1")) |
| 111 | if err != nil { |
| 112 | t.Fatal(err) |
| 113 | } |
| 114 | if !d.ReviewRequired { |
| 115 | t.Fatalf("%s did not require review: %+v", name, d.Entries) |
| 116 | } |