forked from royalrick/weapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_submit_pages_test.go
69 lines (57 loc) · 1.28 KB
/
search_submit_pages_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package weapp
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestSearchSubmitPages(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
t.Fatalf("Expect 'POST' get '%s'", r.Method)
}
path := r.URL.EscapedPath()
if path != apiSearchSubmitPages {
t.Fatalf("Except to path '%s',get '%s'", apiSearchSubmitPages, path)
}
if err := r.ParseForm(); err != nil {
t.Fatal(err)
}
if r.Form.Get("access_token") == "" {
t.Fatalf("access_token can not be empty")
}
params := struct {
Pages []struct {
Path string `json:"path"`
Query string `json:"query"`
} `json:"pages"`
}{}
if err := json.NewDecoder(r.Body).Decode(¶ms); err != nil {
t.Fatal(err)
}
if len(params.Pages) != 1 {
t.Fatal("param pages can not be empty")
}
w.WriteHeader(http.StatusOK)
raw := `{
"errcode": 0,
"errmsg": "ok"
}`
if _, err := w.Write([]byte(raw)); err != nil {
t.Fatal(err)
}
}))
defer ts.Close()
sender := SearchSubmitPages{
[]SearchSubmitPage{
{
Path: "/pages/index/index",
Query: "id=test",
},
},
}
_, err := sender.send(ts.URL+apiSearchSubmitPages, "mock-access-token")
if err != nil {
t.Fatal(err)
}
}