erratademo_test.gno
1.77 Kb · 45 lines
1package erratademo
2
3import (
4 "strings"
5 "testing"
6
7 "gno.land/r/g132vz03ycpaagtef4jmxjakstkppgyc5wn3r807/erratabank/v0"
8)
9
10func TestEmbedAcceptedErrata(cur realm, t *testing.T) {
11 if BookID() != 0 || !strings.Contains(Render(""), "No errata yet.") {
12 t.Fatal("an unlinked guide should render its empty state")
13 }
14 // The unit-test loader has no deployment transaction or creator.
15 owner = address("g1dmt3sa5ucvecxuhf3j6ne5r0e3z4x7h6c03xc0")
16 reader := address("g1akeqsvhucjt8gf5yupyzjxsjd29wv8fayng37c")
17 testing.SetRealm(testing.NewUserRealm(owner))
18 id := erratabank.CreateBook(cross(cur), "Quickstart", "First", "https://example.org/guide", 0)
19 testing.SetRealm(testing.NewUserRealm(reader))
20 reportID := erratabank.Submit(cross(cur), id, "Section 1", "Use the new endpoint.")
21 if got := revive(func() { SetBook(cross(cur), id) }); got != "demo deployer only" {
22 t.Fatalf("unexpected unauthorized result: %v", got)
23 }
24
25 testing.SetRealm(testing.NewUserRealm(owner))
26 if got := revive(func() { SetBook(cross(cur), 0) }); got != "book not found" {
27 t.Fatalf("unexpected missing book result: %v", got)
28 }
29 SetBook(cross(cur), id)
30 if got := revive(func() { SetBook(cross(cur), id) }); got != "demo book already set" {
31 t.Fatalf("unexpected second link result: %v", got)
32 }
33 if BookID() != id || strings.Contains(Render(""), "Use the new endpoint") {
34 t.Fatal("pending reports should stay out of the embedded section")
35 }
36
37 erratabank.Accept(cross(cur), reportID, "Confirmed")
38 rendered := Render("")
39 if !strings.Contains(rendered, "## Errata") || !strings.Contains(rendered, "Use the new endpoint") {
40 t.Fatalf("accepted correction missing from guide: %s", rendered)
41 }
42 if got := Render("?page=2"); !strings.Contains(got, "Errata page not found.") {
43 t.Fatalf("unexpected out-of-range page: %s", got)
44 }
45}