package api
import (
"strings"
"testing"
)
// 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)
}
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)
}
}
}