| index 1f5a5a6f7..c8d90d83e 100644 |
| --- a/internal/console/platformlinked_test.go |
| +++ b/internal/console/platformlinked_test.go |
| @@ -940,3 +940,77 @@ func TestPlatformOwnerNoticeCountsForAfterGraceDue(t *testing.T) { |
| t.Fatalf("row %+v %v, want no notice and nothing due", row, ok) |
| } |
| } |
| + |
| +// customerOwnerSeesWarnings has owner, an owner of the linked account acct |
| +// (over a cap), browse its account page and use a declaring CLI on it: both |
| +// still show the warning, and neither may record notice (spec §8: only a |
| +// delivery to the platform's owners counts). |
| +func customerOwnerSeesWarnings(t *testing.T, fx *consoleFixture, acct *Account, owner, code string) { |
| + t.Helper() |
| + if err := fx.st.AddMember(acct.ID, owner, RoleOwner, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + c := newBrowser(t) |
| + fx.setUser(owner) |
| + signUp(t, fx, c, code+"-browser") |
| + // storageOver's usage, as the banner words it. |
| + if _, _, body := get(t, c, fx.ts.URL+"/a/"+acct.Sqid+"/"); !strings.Contains(body, "2.1 GB of 1.1 GB object storage") { |
| + t.Fatalf("the customer's owner sees no banner on %s", acct.Sqid) |
| + } |
| + if st, _ := capRow(t, fx, acct, capStorage); !st.NoticeAt.IsZero() { |
| + t.Fatalf("the customer owner's page view recorded notice: %v", st.NoticeAt) |
| + } |
| + tok := cliToken(t, fx, owner, code+"-cli") |
| + req, err := http.NewRequest(http.MethodGet, fx.ts.URL+"/api/cli/apps/"+acct.Sqid+"/list", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Header.Set("Authorization", "Bearer "+tok) |
| + req.Header.Set(planWarningsAccept, "1") |
| + resp, err := http.DefaultClient.Do(req) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + resp.Body.Close() |
| + if resp.StatusCode != http.StatusOK || len(resp.Header.Values(planWarningHeader)) != 1 { |
| + t.Fatalf("CLI list on %s = %d, warnings %q, want 200 and the warning", acct.Sqid, resp.StatusCode, resp.Header.Values(planWarningHeader)) |
| + } |
| + if st, _ := capRow(t, fx, acct, capStorage); !st.NoticeAt.IsZero() { |
| + t.Fatalf("the customer owner's CLI recorded notice: %v", st.NoticeAt) |
| + } |
| +} |
| + |
| +func TestLinkedCustomerOwnerWarningsEarnNoNotice(t *testing.T) { |
| + fx, _, shop, mail := noticeWorld(t) |
| + ctx := context.Background() |
| + // The real clock: page views and CLI requests record at time.Now(). |
| + st := storageOver(t, fx, shop, time.Now().Add(-time.Hour)) |
| + customerOwnerSeesWarnings(t, fx, shop, "claimer@example.com", "code-linked-warn") |
| + if err := fx.srv.notifyPlanOwners(ctx, shop, []capState{st}, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := len(mail.sentCopy()); n != 1 { |
| + t.Fatalf("sent %d notices, want one to the platform's owner", n) |
| + } |
| + if row, _ := capRow(t, fx, shop, capStorage); row.NoticeAt.IsZero() { |
| + t.Fatal("the platform owner's delivered email recorded no notice") |
| + } |
| + |
| + // A platform with no owners here: the customer's owner still earns none. |
| + orphan := testAccountID() |
| + if _, err := fx.st.EnsureLinkedAccount(orphan, domains.Sqid(orphan), "orphan", "zzzz", "", strings.Repeat("ef", 16), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + o, err := fx.st.AccountBySqid(domains.Sqid(orphan)) |
| + if err != nil || o == nil { |
| + t.Fatal(o, err) |
| + } |
| + ost := storageOver(t, fx, o, time.Now().Add(-time.Hour)) |
| + customerOwnerSeesWarnings(t, fx, o, "orphanowner@example.com", "code-orphan-warn") |
| + if err := fx.srv.notifyPlanOwners(ctx, o, []capState{ost}, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if row, _ := capRow(t, fx, o, capStorage); !row.NoticeAt.IsZero() { |
| + t.Fatalf("no platform owners, yet notice %v", row.NoticeAt) |
| + } |
| +} |