-
Notifications
You must be signed in to change notification settings - Fork 0
/
devices_test.go
81 lines (63 loc) · 1.81 KB
/
devices_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
package igcclient
/*
func TestDevicesService_Devices(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/devices", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("{\"Data\":[{\"DeviceTypeId\":1},{\"DeviceTypeId\":2}],\"Success\":true,\"Errors\":[]}"))
})
response, err := client.Devices.Devices()
if err != nil {
t.Errorf(err.Error())
}
if len(*response.Data) != 2 {
t.Errorf("Expected 2 devices")
}
}
func TestDevicesService_DevicesByID(t *testing.T) {
teardown := setup()
defer teardown()
mux.HandleFunc("/devices/1", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
w.Write([]byte("{\"Data\":{\"DeviceTypeId\":1},\"Success\":true,\"Errors\":[]}"))
})
response, err := client.Devices.DevicesByID(1)
if err != nil {
t.Errorf(err.Error())
}
if *response.Data.DeviceTypeID != 1 {
t.Errorf("Expected device type ID to be 1")
}
}
func TestDevicesService_GetPlatform(t *testing.T) {
teardown := setup()
defer teardown()
userAgent := "userAgent"
mux.HandleFunc("/devices/getplatform", func(w http.ResponseWriter, r *http.Request) {
s := true
success := &s
model := new(models.DevicesDetectionModel)
json.NewDecoder(r.Body).Decode(model)
if *model.UserAgent != userAgent {
t.Errorf("Wrong UserAgent")
*success = false
}
w.WriteHeader(200)
w.Write([]byte("{\"Data\":{\"PlatformName\":\"" + *model.UserAgent + "\"},\"Success\":" + strconv.FormatBool(*success) + ",\"Errors\":[]}"))
})
model := models.DevicesDetectionModel{
UserAgent: &userAgent,
}
response, err := client.Devices.GetPlatform(model)
if err != nil {
t.Errorf(err.Error())
}
if !*response.Success {
t.Errorf("Expected true")
}
if *response.Data.PlatformName != userAgent {
t.Errorf("Expected user agent to be: " + userAgent)
}
}
*/