Skip to content
quarry Artifact [bbeef773d6]
Login

Artifact [bbeef773d6]

Artifact bbeef773d6f7870a0b22c66e2013deb02b81bce850d765a36b10ec74d1b2d471:


package web

import (
	"strings"
	"testing"
)

// The page a person opens to ask about themselves could not answer the
// question they came with. /me listed no repositories, no roles and no
// teams; the dashboard drew a Reader repository and an Admin one
// identically; and account.explain refused you your own letters. This
// is the last of those three (ticket f44e0c66).
func TestMeSaysWhatYouMayReach(t *testing.T) {
	me := meView{Name: "jva", Created: "2026-06-01T00:00:00Z",
		Access: []meAccessRow{
			{Repo: "quarry", Role: "Reader"},
			{Repo: "dantest-sandbox", Role: "Admin"},
		},
		Teams:  []string{"dantest-crew"},
		Notify: &prefsView{},
	}
	var b strings.Builder
	if err := mePageTmpl.ExecuteTemplate(&b, "content",
		pageData{Title: "jva", User: "jva", Me: &me}); err != nil {
		t.Fatal(err)
	}
	got := b.String()
	for what, want := range map[string]string{
		"names the repository":       "dantest-sandbox",
		"says the role on it":        "Admin",
		"distinguishes the other":    "Reader",
		"lists the team":             "dantest-crew",
		"is reachable from the rail": `href="#access"`,
	} {
		if !strings.Contains(got, want) {
			t.Errorf("FAIL: /me no longer %s (%q)", what, want)
		} else {
			t.Logf("ok: /me %s", what)
		}
	}

	// Somebody with no grants is told so plainly, and told what they can
	// still do — an empty table would read as a bug.
	var none strings.Builder
	if err := mePageTmpl.ExecuteTemplate(&none, "content",
		pageData{Title: "jan", User: "jan", Me: &meView{Name: "jan", Notify: &prefsView{}}}); err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(none.String(), "No repository has given you a role") {
		t.Error("FAIL: an account with no grants is shown an empty table and no explanation")
	} else {
		t.Log("ok: no role is stated rather than left blank")
	}

	// A site admin reaches everything, so a table that lists two
	// repositories would be telling them something false by omission.
	var admin strings.Builder
	if err := mePageTmpl.ExecuteTemplate(&admin, "content",
		pageData{Title: "dmestas", User: "dmestas", Me: &meView{Name: "dmestas", Admin: true, Notify: &prefsView{}}}); err != nil {
		t.Fatal(err)
	}
	if !strings.Contains(admin.String(), "site admin") {
		t.Error("FAIL: a site admin is not told the table does not bound them")
	} else {
		t.Log("ok: a site admin is told the table is not the whole answer")
	}
}