Skip to content
quarry Artifact [dfa7e50860]
Login

Artifact [dfa7e50860]

Artifact dfa7e50860adb18d33c4ae92442d9e664c76f0cffe7080e3cee4c370439fc89c:


package api

import (
	"strings"
	"testing"

	"craftdesign.group/quarry/internal/markup"
)

// A local-tier ticket is not in the index, and a reference to it read as
// plain text. It is described now, marked local, and linked to its page.
func TestALocalTicketIsDescribedAndMarkedLocal(t *testing.T) {
	id := "54dc6a4148" + strings.Repeat("0", 30)
	d := Deps{Local: &tierLocal{id: id}}
	old := ticketFacts.Load()
	defer ticketFacts.Store(old)
	facts := func(repo, prefix string) (ticketFact, bool) { return d.ticketFactOf(repo, prefix, 0) }
	ticketFacts.Store(&facts)

	tr, ok := TicketRefOf("tk", "54dc6a4148")
	if !ok {
		t.Fatal("FAIL: a local ticket is not described")
	}
	if !tr.Local || tr.URL != "/r/tk/ticket/"+id || tr.State != "open" {
		t.Fatalf("FAIL: described as %+v", tr)
	}
	// The preview card reaches it too: a ticket token resolves to its
	// page, and the card names it local.
	if href, ok := (resolver{repo: "tk"}).ResolveToken(markup.RefToken{Kind: markup.RefTicket, ID: id[:10]}); !ok || href != "/r/tk/ticket/"+id {
		t.Errorf("FAIL: a local ticket's card link = %q, %v", href, ok)
	}
	if _, ok := TicketRefOf("tk", "0123456789"); ok {
		t.Error("FAIL: an id that names no ticket was described")
	}
	if !t.Failed() {
		t.Log("ok: a local ticket is linked, open, and marked local")
	}
}

// The state a reference shows follows the listings' closed rule.
func TestTicketStateFollowsTheListingsRule(t *testing.T) {
	for status, want := range map[string]string{"Open": "open", "Review": "review", "Fixed": "closed",
		"closed": "closed", "Deferred": "closed", "wontfix": "closed", "": "open"} {
		if got := ticketStateOf(status); got != want {
			t.Errorf("FAIL: %q reads as %s, want %s", status, got, want)
		}
	}
}