~bigbes/sr-ht-spec

ref: 8374a1ef0826d0422d3db4685cfea15842c2096d sr-ht-spec/web/inbox_test.go -rw-r--r-- 2.3 KiB
8374a1ef — Eugene Blikh feat(graph): GraphQL-native webhook surface (Phase 5a) 25 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)
	}
}