-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurements_test.go
49 lines (43 loc) · 1.43 KB
/
measurements_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
package openaq
import (
"context"
"io"
"net/http"
"net/url"
"strings"
"testing"
"time"
)
func TestMeasurementsArgQueryParams(t *testing.T) {
baseArgs := BaseArgs{}
measurementArgs := MeasurementsArgs{
BaseArgs: baseArgs,
DatetimeFrom: time.Date(2021, 8, 15, 14, 30, 45, 100, time.UTC),
DatetimeTo: time.Date(2021, 8, 15, 14, 30, 45, 100, time.UTC),
Parameters: &Parameters{IDs: []int64{1, 2, 3}},
PeriodName: "hour",
}
queryString, err := measurementArgs.QueryParams()
ok(t, err)
equals(t, url.Values{"date_from": []string{"2021-08-15T14:30:45Z"}, "date_to": []string{"2021-08-15T14:30:45Z"}, "limit": []string{"100"}, "page": []string{"1"}, "parameters_id": []string{"1,2,3"}, "period_name": []string{"hour"}}, queryString)
}
func TestGetLocationMeasurments(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/measurements?limit=1&page=1")
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(parameters)),
Header: make(http.Header),
}
})
config := &Config{
Client: client,
}
openAQClient, err := NewClient(*config)
ok(t, err)
ctx := context.Background()
openAQClient.GetLocationMeasurements(ctx, 2178, MeasurementsArgs{BaseArgs: BaseArgs{Limit: 1, Page: 1}})
ok(t, err)
//equals(t, body.Results[len(body.Results)-1].ID, int64(11))
}