Skip to content
quarry Artifact [3abc75665a]
Login

Artifact [3abc75665a]

Artifact 3abc75665a1f9891711a8bc270b8d6e49f9832d19f00f0fbe51c16acfdde7b15:


package web

import (
	"strings"
	"testing"
)

// /me draws your agents' requests for sign-off only when there are
// any: a waiting one answers with two POSTed buttons (never a link, so
// nothing that deletes a repository runs from a GET), a decided one
// says how it ended.
func TestMeShowsRequestsForSignOff(t *testing.T) {
	render := func(reqs []meSignOff) string {
		var b strings.Builder
		me := meView{Name: "ann", Notify: &prefsView{}, SignOffs: reqs}
		if err := noHooks.template(mePageTmpl).ExecuteTemplate(&b, "content", pageData{Title: "ann", User: "ann", Me: &me}); err != nil {
			t.Fatal(err)
		}
		return b.String()
	}
	if got := render(nil); strings.Contains(got, `id="signoffs"`) || strings.Contains(got, `href="#signoffs"`) {
		t.Errorf("FAIL: an empty sign-off section is drawn")
	}
	got := render([]meSignOff{
		{ID: "abc", Agent: "ann-bot", Repo: "r", Summary: "delete r", State: "pending", Requested: "2026-10-21T10:00:00Z"},
		{ID: "def", Agent: "ann-bot", Repo: "s", Summary: "stop serving s", State: "denied", Requested: "2026-10-20T10:00:00Z"},
	})
	for what, want := range map[string]string{
		"the rail reaches it":   `href="#signoffs"`,
		"approve is a post":     `<form method="post" action="/me/signoffs/abc"><input type="hidden" name="approve" value="true">`,
		"deny is a post":        `<form method="post" action="/me/signoffs/abc"><input type="hidden" name="approve" value="false">`,
		"a decided one is kept": `data-hook="signoff" data-state="denied"`,
	} {
		if !strings.Contains(got, want) {
			t.Errorf("FAIL: %s (%q)", what, want)
		}
	}
	if strings.Contains(got, `action="/me/signoffs/def"`) {
		t.Errorf("FAIL: a decided request can still be answered")
	}
}