-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch_page_test.go
More file actions
84 lines (77 loc) · 1.64 KB
/
search_page_test.go
File metadata and controls
84 lines (77 loc) · 1.64 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package picnic
import (
"net/http"
"testing"
)
func TestSearchPage(t *testing.T) {
c, s := testClientFile(http.StatusOK, "test/search-page.json")
defer s.Close()
res, err := c.SearchArticles("melk")
if err != nil {
t.Fatal(err)
}
if len(res) != 78 {
t.Error("Invalid result length")
}
idMap := make(map[string]bool)
for _, item := range res {
if _, exists := idMap[item.Id]; exists {
t.Error("duplicate id")
}
if item.Name == "" {
t.Error("Invalid Item Name")
}
if item.ImageId == "" {
t.Error("Invalid Item Image Id")
}
if item.DisplayPrice == 0 {
t.Error("Invalid Display Price")
}
idMap[item.Id] = true
}
}
func TestSearchPage_Error(t *testing.T) {
c, s := testClientFile(http.StatusUnauthorized, "test/error.json")
defer s.Close()
res, err := c.SearchArticles("pepper")
if res != nil {
t.Error("Unexpected result")
}
if err == nil {
t.Error("No error produced")
}
}
func TestSearchPage_RequiresAuth(t *testing.T) {
c := &Client{
http: http.DefaultClient,
token: "",
}
res, err := c.SearchArticles("query")
if res != nil {
t.Error("Unexpected response")
}
if err.Error() != authenticationError().Error() {
t.Error("Incorrect error")
}
}
func TestSearchPage_RequiresTerm(t *testing.T) {
c, s := testClientFile(http.StatusOK, "test/search-page.json")
defer s.Close()
res, err := c.Search(" ")
if res != nil {
t.Error("Unexpected response")
}
if err == nil {
t.Error("Error missing")
}
}
func Test_Integration_SearchPage(t *testing.T) {
c := intClient(t)
res, err := c.SearchArticles("melk")
if err != nil {
t.Fatal(err)
}
if len(res) == 0 {
t.Error("no results found")
}
}