package mapatest import ( "net/http" "net/url" "strings" "testing" ) // Make team page from the editor (level-up §6.7): with Accept JSON the // POST answers the new page and the note as it now stands, so the // editor takes that text and revision; a taken title is the sentence, // as JSON, and nothing is written. func TestMakeTeamPageAnswersTheEditor(t *testing.T) { rig := newRig(t) day := "/d/2026-11-12" rig.post(t, Ana, day, url.Values{"body": {"Mine.\n\nShare this."}}) note := between(rig.page(t, Ana, day), `href="/p/`, `/share"`) revision := revisionAs(t, rig, Ana, day) rig.createPage(t, Bo, "Taken", "Already here.") pages := rig.count(t, "pages") code, refused := rig.postJSON(Ana, "/p/"+note+"/share", url.Values{ "title": {"Taken"}, "block": {"1"}, "revision": {revision}}) if code != http.StatusUnprocessableEntity || refused["error"] == "" || refused["taken"] == "" || rig.count(t, "pages") != pages { t.Fatalf("a taken title: %d %v", code, refused) } code, reply := rig.postJSON(Ana, "/p/"+note+"/share", url.Values{ "title": {"Shared"}, "block": {"1"}, "revision": {revision}}) if code != http.StatusOK || reply["body"] != "Mine.\n\n[[Shared]]" || reply["revision"] == revision || reply["revision"] == "" { t.Fatalf("Make team page answered %d %v", code, reply) } if reply["revision"] != revisionAs(t, rig, Ana, day) { t.Fatal("the answer's revision is not the note's") } if got := rig.page(t, Bo, reply["href"].(string)); !strings.Contains( got, "Share this.") { t.Fatal("the new team page does not hold the blocks") } } // New team page's popover (level-up §4.7, build note 77): with Accept // JSON, POST /pages answers the new page's address, and a refused title // is the sentence, as JSON, with nothing written. func TestNewTeamPageAnswersThePopover(t *testing.T) { rig := newRig(t) taken := rig.createPage(t, Bo, "Taken", "") pages := rig.count(t, "pages") for _, title := range []string{"Taken", " "} { code, refused := rig.postJSON(Ana, "/pages", url.Values{"title": {title}}) if code != http.StatusUnprocessableEntity || refused["error"] == "" || rig.count(t, "pages") != pages { t.Fatalf("%q: %d %v", title, code, refused) } if title == "Taken" && refused["taken"] != taken { t.Fatalf("a taken title points to %v, not %s", refused["taken"], taken) } } code, reply := rig.postJSON(Ana, "/pages", url.Values{"title": {"Fresh"}}) href, _ := reply["href"].(string) if code != http.StatusOK || !strings.HasPrefix(href, "/p/") || !strings.Contains(rig.page(t, Bo, href), "Fresh") { t.Fatalf("POST /pages answered %d %v", code, reply) } }