Skip to content
quarry Artifact [8de99a8785]
Login

Artifact [8de99a8785]

Artifact 8de99a878555d82115279d4d1fc0a542f6d5a2efc15e6bd71f2b5f7fb034138f:


package web

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

// A LOOKING aid for the two surfaces a password reset adds: the row's
// new control on the People tab beside the one that shuts an account,
// and the banner handing the operator a link. Off unless
// QUARRY_SHOT_RESET is set.
func TestWriteResetShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_RESET")
	if out == "" {
		t.Skip("QUARRY_SHOT_RESET unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	data := pageData{Title: "People", SheetURL: "quarry.css", User: "root",
		InviteLink:  "https://zeitforge.app/invite/" + strings.Repeat("cd", 32),
		InviteReset: true,
		Accounts: []betaAccount{
			{Name: "jva", Live: 1, LastLogin: "2026-09-16T00:37:32Z", Created: "2026-08-01T00:00:00Z"},
			{Name: "lou", Email: "[email protected]", LastLogin: "2026-09-15T08:00:00Z", Created: "2026-07-01T00:00:00Z"},
			{Name: "newbie", Email: "[email protected]", Pending: true, Created: "2026-09-14T00:00:00Z"},
			{Name: "eve", Disabled: "2026-09-10T00:00:00Z", Created: "2026-06-01T00:00:00Z"},
		},
	}
	var buf strings.Builder
	if err := noHooks.template(fleetPeoplePage).Execute(&buf, data); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
	t.Logf("ok: wrote %s", out)
}

// And the page the link opens, in its reset words.
func TestWriteResetLinkShot(t *testing.T) {
	out := os.Getenv("QUARRY_SHOT_RESETLINK")
	if out == "" {
		t.Skip("QUARRY_SHOT_RESETLINK unset")
	}
	if err := os.WriteFile(filepath.Join(filepath.Dir(out), "quarry.css"),
		[]byte(sheet), 0o644); err != nil {
		t.Fatal(err)
	}
	var buf strings.Builder
	if err := noHooks.template(invitePage).Execute(&buf, pageData{Title: "New password", SheetURL: "quarry.css",
		InviteToken: strings.Repeat("cd", 32), InviteName: "jva", InviteReset: true}); err != nil {
		t.Fatal(err)
	}
	if err := os.WriteFile(out, []byte(buf.String()), 0o644); err != nil {
		t.Fatal(err)
	}
}