-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocations_test.go
106 lines (96 loc) · 4.62 KB
/
locations_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
package openaq
const locations = `{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":2178,"name":"Del Norte","locality":"Albuquerque","timezone":"America/Denver","country":{"id":13,"code":"US","name":"United States of America"},"owner":{"id":4,"name":"Unknown Governmental Organization"},"provider":{"id":119,"name":"AirNow"},"isMobile":false,"isMonitor":true,"instruments":[{"id":2,"name":"Government Monitor"}],"sensors":[{"id":25227,"name":"co ppm","parameter":{"id":8,"name":"co","units":"ppm","displayName":"CO"}},{"id":3916,"name":"no2 ppm","parameter":{"id":7,"name":"no2","units":"ppm","displayName":"NO₂"}},{"id":4272226,"name":"no ppm","parameter":{"id":35,"name":"no","units":"ppm","displayName":"NO"}},{"id":3917,"name":"o3 ppm","parameter":{"id":10,"name":"o3","units":"ppm","displayName":"O₃"}},{"id":3918,"name":"so2 ppm","parameter":{"id":9,"name":"so2","units":"ppm","displayName":"SO₂"}},{"id":3919,"name":"pm10 µg/m³","parameter":{"id":1,"name":"pm10","units":"µg/m³","displayName":"PM10"}},{"id":4272103,"name":"nox ppm","parameter":{"id":19840,"name":"nox","units":"ppm","displayName":"NOx"}},{"id":3920,"name":"pm25 µg/m³","parameter":{"id":2,"name":"pm25","units":"µg/m³","displayName":"PM2.5"}}],"coordinates":{"latitude":35.1353,"longitude":-106.584702},"bounds":[-106.584702,35.1353,-106.584702,35.1353],"distance":null,"datetimeFirst":{"utc":"2016-03-06T19:00:00+00:00","local":"2016-03-06T12:00:00-07:00"},"datetimeLast":{"utc":"2023-08-16T18:00:00+00:00","local":"2023-08-16T12:00:00-06:00"}}]}`
// func createLocationArgs(page int64, limit int64, monitor bool, providers *Providers, countries *Countries) LocationArgs {
// baseArgs := BaseArgs{
// Limit: limit,
// Page: page,
// }
// return LocationArgs{
// BaseArgs: &baseArgs,
// Monitor: &monitor,
// Providers: providers,
// Countries: countries,
// }
// }
// func TestLocationArgsQueryParams(t *testing.T) {
// tests := map[string]struct {
// input LocationArgs
// want url.Values
// }{
// "simple": {input: createLocationArgs(nil), want: url.Values{"countries_id": []string{"6,7"}, "limit": []string{"1000"}, "page": []string{"1"}, "providers_id": []string{"1,2"}}},
// }
// for name, tc := range tests {
// t.Run(name, func(t *testing.T) {
// got, _ := tc.input.QueryParams()
// diff := cmp.Diff(tc.want, got)
// if diff != "" {
// t.Fatalf(diff)
// }
// })
// }
// baseArgs := BaseArgs{
// Limit: 1000,
// Page: 1,
// }
// isMonitor := true
// locationArgs := LocationArgs{
// BaseArgs: &baseArgs,
// Monitor: &isMonitor,
// Mobile: false,
// }
// providers := Providers{IDs: []int64{1, 2}}
// countries := Countries{IDs: []int64{6, 7}}
// locationArgs.Providers = &providers
// locationArgs.Countries = &countries
// queryParams, _ := locationArgs.QueryParams()
// expected := url.Values{"countries_id": []string{"6,7"}, "limit": []string{"1000"}, "page": []string{"1"}, "providers_id": []string{"1,2"}}
// equals(t, expected, queryParams)
// }
// func TestGetLocation(t *testing.T) {
// client := NewTestClient(func(req *http.Request) *http.Response {
// // Test request parameters
// equals(t, req.URL.String(), "https://api.openaq.org/v3/locations/2178")
// return &http.Response{
// StatusCode: 200,
// Body: io.NopCloser(strings.NewReader(locations)),
// Header: make(http.Header),
// }
// })
// config := &Config{
// Client: client,
// }
// openAQClient, err := NewClient(*config)
// ok(t, err)
// ctx := context.Background()
// body, err := openAQClient.GetLocation(ctx, 2178)
// ok(t, err)
// var locationsResponse LocationsResponse
// err = json.Unmarshal([]byte(locations), &locationsResponse)
// ok(t, err)
// equals(t, body, locationsResponse)
// equals(t, body.Results[len(body.Results)-1].ID, int64(2178))
// }
// func TestGetLocations(t *testing.T) {
// client := NewTestClient(func(req *http.Request) *http.Response {
// // Test request parameters
// equals(t, req.URL.String(), "https://api.openaq.org/v3/locations")
// return &http.Response{
// StatusCode: 200,
// Body: io.NopCloser(strings.NewReader(locations)),
// Header: make(http.Header),
// }
// })
// config := &Config{
// Client: client,
// }
// openAQClient, err := NewClient(*config)
// ok(t, err)
// ctx := context.Background()
// body, err := openAQClient.GetLocations(ctx, LocationArgs{})
// ok(t, err)
// var locationsResponse LocationsResponse
// err = json.Unmarshal([]byte(locations), &locationsResponse)
// ok(t, err)
// equals(t, body, locationsResponse)
// equals(t, body.Results[len(body.Results)-1].ID, int64(2178))
// }