-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema_test.go
114 lines (103 loc) · 2.61 KB
/
schema_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
107
108
109
110
111
112
113
114
package atomicasset
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/eosswedenorg-go/unixtime"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetSchemas(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
assert.Equal(t, "/atomicassets/v1/schemas?limit=1", req.URL.String())
payload := `{
"success": true,
"data": [
{
"contract": "atomicassets",
"schema_name": "myschema",
"format": [
{
"name": "name",
"type": "string"
},
{
"name": "img",
"type": "image"
},
{
"name": "video",
"type": "string"
}
],
"collection": {
"collection_name": "mycollection",
"name": "Some Cool Collection Name ",
"img": "QmYUtzfGWAYrQ43eo1nNRfrYKpUS1cvCWmceCQYxjP7CkS",
"author": "es2fwuiv5eyf",
"allow_notify": true,
"authorized_accounts": [
"es2fwuiv5eyf"
],
"notify_accounts": [
"d11dqs2fnh2v",
"fg2ng2izgkvl"
],
"market_fee": 0.06,
"created_at_block": "18683993",
"created_at_time": "1427545955000"
},
"created_at_time": "1440686620500",
"created_at_block": "18684000",
"assets": 22
}
],
"query_time": 986850311000
}`
res.Header().Add("Content-type", "application/json; charset=utf-8")
_, err := res.Write([]byte(payload))
assert.NoError(t, err)
}))
client := New(srv.URL)
res, err := client.GetSchemas(SchemasRequestParams{Limit: 1})
require.NoError(t, err)
assert.Equal(t, 200, res.HTTPStatusCode)
assert.True(t, res.Success)
assert.Equal(t, time.Date(2001, time.April, 9, 21, 5, 11, 0, time.UTC), res.QueryTime.Time())
expected := []Schema{
{
Name: "myschema",
Contract: "atomicassets",
Format: []SchemaFormat{
{
Name: "name",
Type: "string",
},
{
Name: "img",
Type: "image",
},
{
Name: "video",
Type: "string",
},
},
Collection: Collection{
CollectionName: "mycollection",
Name: "Some Cool Collection Name ",
Image: "QmYUtzfGWAYrQ43eo1nNRfrYKpUS1cvCWmceCQYxjP7CkS",
Author: "es2fwuiv5eyf",
AllowNotify: true,
AuthorizedAccounts: []string{"es2fwuiv5eyf"},
NotifyAccounts: []string{"d11dqs2fnh2v", "fg2ng2izgkvl"},
MarketFee: 0.06,
CreatedAtBlock: "18683993",
CreatedAtTime: unixtime.Time(1427545955000),
},
CreatedAtBlock: "18684000",
CreatedAtTime: unixtime.Time(1440686620500),
},
}
assert.Equal(t, expected, res.Data)
}