package web import ( "net/http" "strings" "testing" "sourcecraft.dev/bigbes/sr-ht-spec/core" "sourcecraft.dev/bigbes/sr-ht-spec/service" ) // TestInboxListsOpenAndDigest proves the review queue lists open proposals under // "waiting on you" and policy-merged ones under the digest, each linking to its // review page. func TestInboxListsOpenAndDigest(t *testing.T) { r := newFakeReader() seedProposal(r, service.Proposal{ ID: 3, Space: demoSpace, Title: "Open one", State: core.StateOpen, Agent: "claude-code/a", }, nil) seedProposal(r, service.Proposal{ ID: 4, Space: demoSpace, Title: "Auto-merged one", State: core.StateMerged, Approval: core.ApprovalPolicy, Agent: "claude-code/b", }, nil) // A human-merged proposal is neither waiting nor part of the digest. seedProposal(r, service.Proposal{ ID: 5, Space: demoSpace, Title: "Human-merged", State: core.StateMerged, Approval: core.ApprovalHuman, }, nil) h, _, _ := testServerWith(t, r) rec := get(t, h, "/inbox", "bigbes") if rec.Code != http.StatusOK { t.Fatalf("status = %d, want 200; body:\n%s", rec.Code, rec.Body) } body := rec.Body.String() if !strings.Contains(body, "/~bigbes/rfcs/p/3") || !strings.Contains(body, "Open one") { t.Errorf("open proposal missing from the queue; body:\n%s", body) } if !strings.Contains(body, "/~bigbes/rfcs/p/4") || !strings.Contains(body, "Auto-merged one") { t.Errorf("policy-merged proposal missing from the digest; body:\n%s", body) } if strings.Contains(body, "Human-merged") { t.Errorf("a human-merged proposal leaked into the review queue") } } // TestInboxEmpty proves the page renders with no proposals rather than erroring. func TestInboxEmpty(t *testing.T) { h, _, _ := testServerWith(t, newFakeReader()) rec := get(t, h, "/inbox", "bigbes") if rec.Code != http.StatusOK { t.Fatalf("status = %d, want 200", rec.Code) } if !strings.Contains(rec.Body.String(), "queue is clear") { t.Errorf("empty inbox does not say the queue is clear") } } // TestInboxAnonymousRedirected proves a viewer with no read authority is sent to // login rather than shown the queue. func TestInboxAnonymousRedirected(t *testing.T) { h, _, _ := testServerWith(t, newFakeReader()) rec := get(t, h, "/inbox", "") if rec.Code != http.StatusSeeOther && rec.Code != http.StatusFound { t.Fatalf("status = %d, want a login redirect", rec.Code) } }