-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries_test.go
76 lines (72 loc) · 2.02 KB
/
queries_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
package up
import (
"net/url"
"reflect"
"testing"
"time"
)
func Test_setupQueries(t *testing.T) {
tests := map[string]struct {
options interface{}
want url.Values
}{
"setup queries for ListAccounts": {
options: []ListAccountsOption{
ListAccountsOptionPageSize(1),
ListAccountsOptionFilterAccountOwnershipType(AccountOwnershipTypeIndividual),
ListAccountsOptionFilterAccountType(AccountTypeTransactional),
},
want: url.Values{
"page[size]": []string{"1"},
"filter[ownershipType]": []string{"INDIVIDUAL"},
"filter[accountType]": []string{"TRANSACTIONAL"},
},
},
"setup queries for ListTags": {
options: []ListTagsOption{
ListTagsOptionPageSize(30),
},
want: url.Values{
"page[size]": []string{"30"},
},
},
"setup queries for ListTransactions": {
options: []ListTransactionsOption{
ListTransactionsOptionPageSize(10000),
ListTransactionsOptionStatus(TransactionStatusHeld),
ListTransactionsOptionSince(time.Date(2022, 1, 10, 0, 0, 0, 0, location)),
ListTransactionsOptionUntil(time.Date(2023, 12, 6, 0, 0, 0, 0, location)),
ListTransactionsOptionCategory("hello"),
ListTransactionsOptionTag("world"),
},
want: url.Values{
"page[size]": []string{"10000"},
"filter[status]": []string{"HELD"},
"filter[since]": []string{"2022-01-10T00:00:00+11:00"},
"filter[until]": []string{"2023-12-06T00:00:00+11:00"},
"filter[category]": []string{"hello"},
"filter[tag]": []string{"world"},
},
},
"check queries defaults page size": {
options: []ListTagsOption{},
want: url.Values{
"page[size]": []string{"100"},
},
},
}
for name, tt := range tests {
// run tests.
t.Run(name, func(t *testing.T) {
got := setupQueries(tt.options)
// is there a mismatch from what we're expecting vs what we've got?
if !reflect.DeepEqual(got, tt.want) {
t.Errorf(
"setupQueries() returned unexpected configuration;\nwant=%+v\ngot=%+v\n",
tt.want,
got,
)
}
})
}
}