forked from sonirico/go-hyperliquid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiresponse_test.go
More file actions
45 lines (41 loc) · 1.01 KB
/
apiresponse_test.go
File metadata and controls
45 lines (41 loc) · 1.01 KB
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
package hyperliquid
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAPIResponse_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
jsonData string
want *APIResponse[OrderResponse]
}{
{
name: "CreateOrderRequest Response",
jsonData: `{"status":"ok","response":{"type":"order","data":{"statuses":[{"resting":{"oid":12345678901,"cloid":"0x00000000000000000000000000000000"}}]}}}`,
want: &APIResponse[OrderResponse]{
Status: "ok",
Ok: true,
Type: "order",
Data: OrderResponse{
Statuses: []OrderStatus{
{
Resting: &OrderStatusResting{
Oid: 12345678901,
ClientID: "0x00000000000000000000000000000000",
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res := &APIResponse[OrderResponse]{}
err := res.UnmarshalJSON([]byte(tt.jsonData))
require.NoError(t, err)
assert.Equal(t, tt.want, res)
})
}
}