oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package equipotest
2
3import (
4 "net/url"
5 "regexp"
6 "strings"
7 "testing"
8)
9
10func TestQuestionDefaultSubmissionSendsAnswer(t *testing.T) {
11 f, q := questionFixture(t)
12 server, c := taskPageServer(t, f.connectionFixture, false)
13 path := "/tasks/" + f.a.TaskID + "/questions/" + q.ID
14 body := taskGet(t, c, server.URL, path, 200)
15 first := regexp.MustCompile(`<button[^>]*name="behavior"[^>]*value="([^"]+)"`).FindStringSubmatch(body)
16 if len(first) != 2 || first[1] != "allow" || !strings.Contains(body, `value="deny"`) {
17 t.Fatal("default action does not send answer")
18 }
19 res := clientPost(t, c, server.URL+path+"/answer", testOrigin, url.Values{"revision": {"1"}, "behavior": {first[1]}, "answer_0": {"Blue"}})
20 res.Body.Close()
21 if res.StatusCode != 303 {
22 t.Fatal("default answer refused", res.StatusCode)
23 }
24 if scalar(t, f.d, `SELECT count(*) FROM questions WHERE answer LIKE '%Blue%'`) != 1 {
25 t.Fatal("typed answer lost")
26 }
27}
28func TestQuestionDeclineRejectsTypedAnswer(t *testing.T) {
29 f, q := questionFixture(t)
30 server, c := taskPageServer(t, f.connectionFixture, false)
31 path := "/tasks/" + f.a.TaskID + "/questions/" + q.ID + "/answer"
32 res := clientPost(t, c, server.URL+path, testOrigin, url.Values{"revision": {"1"}, "behavior": {"deny"}, "answer_0": {"Blue"}})
33 res.Body.Close()
34 if res.StatusCode != 422 {
35 t.Fatal("decline discarded typed answer", res.StatusCode)
36 }
37 if scalar(t, f.d, "SELECT count(*) FROM questions WHERE state='answered'") != 0 {
38 t.Fatal("decline persisted")
39 }
40}
41