-
Notifications
You must be signed in to change notification settings - Fork 1
/
authors_test.go
198 lines (185 loc) · 4.83 KB
/
authors_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package dmm
import (
"fmt"
"net/http"
"reflect"
"testing"
"github.com/kylelemons/godebug/pretty"
)
const testAuthorsRequest = `{
"request": {
"parameters": {
"Author": null,
"api_id": "sample",
"affiliate_id": "affiliate-990",
"floor_id": "27",
"hits": "10",
"offset": "5000",
"output": "json"
}
},
"result": {
"status": "200",
"result_count": 10,
"total_count": "99852",
"first_position": 5000,
"site_name": "DMM.com(一般)",
"site_code": "DMM.com",
"service_name": "通販",
"service_code": "mono",
"floor_id": "27",
"floor_name": "本・コミック",
"floor_code": "book",
"author": [
{
"author_id": "217780",
"name": "安藤美華代",
"ruby": "あんどうみかよ"
},
{
"author_id": "217781",
"name": "安東みきえ",
"ruby": "あんどうみきえ"
},
{
"author_id": "180054",
"name": "安東実",
"ruby": "あんどうみのる"
}
]
}
}`
func TestAuthors_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(`/`+AuthorBasePath, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, testAuthorsRequest)
})
actual, r, err := client.Authors.List(ctx, nil)
if err != nil {
t.Fatalf("Authors.List returned error: %v; response: %#v", err, r)
}
expected := []Author{
{
AuthorID: "217780",
Name: "安藤美華代",
Ruby: "あんどうみかよ",
SiteName: "DMM.com(一般)",
SiteCode: "DMM.com",
ServiceName: "通販",
ServiceCode: "mono",
FloorID: "27",
FloorName: "本・コミック",
FloorCode: "book",
},
{
AuthorID: "217781",
Name: "安東みきえ",
Ruby: "あんどうみきえ",
SiteName: "DMM.com(一般)",
SiteCode: "DMM.com",
ServiceName: "通販",
ServiceCode: "mono",
FloorID: "27",
FloorName: "本・コミック",
FloorCode: "book",
},
{
AuthorID: "180054",
Name: "安東実",
Ruby: "あんどうみのる",
SiteName: "DMM.com(一般)",
SiteCode: "DMM.com",
ServiceName: "通販",
ServiceCode: "mono",
FloorID: "27",
FloorName: "本・コミック",
FloorCode: "book",
},
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Authors.List returned %+v, expected %+v", actual, expected)
}
re := Response{
Parameters: &AuthorOptions{
APIID: "sample",
AffiliateID: "affiliate-990",
FloorID: `27`,
Initial: ``,
Hits: 10,
Offset: 5000,
Output: `json`,
Callback: ``,
},
ResultCount: 10,
TotalCount: 99852,
FirstPosition: 5000,
}
if !reflect.DeepEqual(re.Parameters, r.Parameters) {
t.Errorf("Response.Parameters is not correct; %s", pretty.Compare(r.Parameters, re.Parameters))
}
if r.ResultCount != re.ResultCount {
t.Errorf("Response.ResultCount returned %+v, expected %+v", r.ResultCount, re.ResultCount)
}
if r.TotalCount != re.TotalCount {
t.Errorf("Response.TotalCount returned %+v, expected %+v", r.TotalCount, re.TotalCount)
}
if r.FirstPosition != re.FirstPosition {
t.Errorf("Response.FirstPosition returned %+v, expected %+v", r.FirstPosition, re.FirstPosition)
}
}
func TestAuthors_First(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc(`/`+AuthorBasePath, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, testAuthorsRequest)
})
actual, r, err := client.Authors.First(ctx, nil)
if err != nil {
t.Errorf("Authors.First returned error: %v", err)
}
expected := Author{
AuthorID: "217780",
Name: "安藤美華代",
Ruby: "あんどうみかよ",
SiteName: "DMM.com(一般)",
SiteCode: "DMM.com",
ServiceName: "通販",
ServiceCode: "mono",
FloorID: "27",
FloorName: "本・コミック",
FloorCode: "book",
}
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Authors.First returned %+v, expected %+v", actual, expected)
}
re := Response{
Parameters: &AuthorOptions{
APIID: "sample",
AffiliateID: "affiliate-990",
FloorID: `27`,
Initial: ``,
Hits: 10,
Offset: 5000,
Output: `json`,
Callback: ``,
},
ResultCount: 10,
TotalCount: 99852,
FirstPosition: 5000,
}
if !reflect.DeepEqual(re.Parameters, r.Parameters) {
t.Errorf("Response.Parameters is not correct; %s", pretty.Compare(r.Parameters, re.Parameters))
}
if r.ResultCount != re.ResultCount {
t.Errorf("Response.ResultCount returned %+v, expected %+v", r.ResultCount, re.ResultCount)
}
if r.TotalCount != re.TotalCount {
t.Errorf("Response.TotalCount returned %+v, expected %+v", r.TotalCount, re.TotalCount)
}
if r.FirstPosition != re.FirstPosition {
t.Errorf("Response.FirstPosition returned %+v, expected %+v", r.FirstPosition, re.FirstPosition)
}
}