oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapatest
2
3import (
4 "net/http"
5 "net/url"
6 "strings"
7 "testing"
8)
9
10// Make team page from the editor (level-up §6.7): with Accept JSON the
11// POST answers the new page and the note as it now stands, so the
12// editor takes that text and revision; a taken title is the sentence,
13// as JSON, and nothing is written.
14func TestMakeTeamPageAnswersTheEditor(t *testing.T) {
15 rig := newRig(t)
16 day := "/d/2026-11-12"
17 rig.post(t, Ana, day, url.Values{"body": {"Mine.\n\nShare this."}})
18 note := between(rig.page(t, Ana, day), `href="/p/`, `/share"`)
19 revision := revisionAs(t, rig, Ana, day)
20 rig.createPage(t, Bo, "Taken", "Already here.")
21 pages := rig.count(t, "pages")
22 code, refused := rig.postJSON(Ana, "/p/"+note+"/share", url.Values{
23 "title": {"Taken"}, "block": {"1"}, "revision": {revision}})
24 if code != http.StatusUnprocessableEntity || refused["error"] == "" ||
25 refused["taken"] == "" || rig.count(t, "pages") != pages {
26 t.Fatalf("a taken title: %d %v", code, refused)
27 }
28 code, reply := rig.postJSON(Ana, "/p/"+note+"/share", url.Values{
29 "title": {"Shared"}, "block": {"1"}, "revision": {revision}})
30 if code != http.StatusOK || reply["body"] != "Mine.\n\n[[Shared]]" ||
31 reply["revision"] == revision || reply["revision"] == "" {
32 t.Fatalf("Make team page answered %d %v", code, reply)
33 }
34 if reply["revision"] != revisionAs(t, rig, Ana, day) {
35 t.Fatal("the answer's revision is not the note's")
36 }
37 if got := rig.page(t, Bo, reply["href"].(string)); !strings.Contains(
38 got, "Share this.") {
39 t.Fatal("the new team page does not hold the blocks")
40 }
41}
42
43// New team page's popover (level-up §4.7, build note 77): with Accept
44// JSON, POST /pages answers the new page's address, and a refused title
45// is the sentence, as JSON, with nothing written.
46func TestNewTeamPageAnswersThePopover(t *testing.T) {
47 rig := newRig(t)
48 taken := rig.createPage(t, Bo, "Taken", "")
49 pages := rig.count(t, "pages")
50 for _, title := range []string{"Taken", " "} {
51 code, refused := rig.postJSON(Ana, "/pages",
52 url.Values{"title": {title}})
53 if code != http.StatusUnprocessableEntity || refused["error"] == "" ||
54 rig.count(t, "pages") != pages {
55 t.Fatalf("%q: %d %v", title, code, refused)
56 }
57 if title == "Taken" && refused["taken"] != taken {
58 t.Fatalf("a taken title points to %v, not %s", refused["taken"],
59 taken)
60 }
61 }
62 code, reply := rig.postJSON(Ana, "/pages", url.Values{"title": {"Fresh"}})
63 href, _ := reply["href"].(string)
64 if code != http.StatusOK || !strings.HasPrefix(href, "/p/") ||
65 !strings.Contains(rig.page(t, Bo, href), "Fresh") {
66 t.Fatalf("POST /pages answered %d %v", code, reply)
67 }
68}
69