forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 262
/
asset_test.go
107 lines (91 loc) · 2.41 KB
/
asset_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
package goshopify
import (
"context"
"fmt"
"reflect"
"testing"
"github.com/jarcoal/httpmock"
)
func TestAssetList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder(
"GET",
fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", client.pathPrefix),
httpmock.NewStringResponder(
200,
`{"assets": [{"key":"assets\/1.liquid"},{"key":"assets\/2.liquid"}]}`,
),
)
assets, err := client.Asset.List(context.Background(), 1, nil)
if err != nil {
t.Errorf("Asset.List returned error: %v", err)
}
expected := []Asset{{Key: "assets/1.liquid"}, {Key: "assets/2.liquid"}}
if !reflect.DeepEqual(assets, expected) {
t.Errorf("Asset.List returned %+v, expected %+v", assets, expected)
}
}
func TestAssetGet(t *testing.T) {
setup()
defer teardown()
params := map[string]string{
"asset[key]": "foo/bar.liquid",
"theme_id": "1",
}
httpmock.RegisterResponderWithQuery(
"GET",
fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", client.pathPrefix),
params,
httpmock.NewStringResponder(
200,
`{"asset": {"key":"foo\/bar.liquid"}}`,
),
)
asset, err := client.Asset.Get(context.Background(), 1, "foo/bar.liquid")
if err != nil {
t.Errorf("Asset.Get returned error: %v", err)
}
expected := &Asset{Key: "foo/bar.liquid"}
if !reflect.DeepEqual(asset, expected) {
t.Errorf("Asset.Get returned %+v, expected %+v", asset, expected)
}
}
func TestAssetUpdate(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder(
"PUT",
fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", client.pathPrefix),
httpmock.NewBytesResponder(
200,
loadFixture("asset.json"),
),
)
asset := Asset{
Key: "templates/index.liquid",
Value: "content",
}
returnedAsset, err := client.Asset.Update(context.Background(), 1, asset)
if err != nil {
t.Errorf("Asset.Update returned error: %v", err)
}
if returnedAsset == nil {
t.Errorf("Asset.Update returned nil")
}
}
func TestAssetDelete(t *testing.T) {
setup()
defer teardown()
params := map[string]string{"asset[key]": "foo/bar.liquid"}
httpmock.RegisterResponderWithQuery(
"DELETE",
fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", client.pathPrefix),
params,
httpmock.NewStringResponder(200, "{}"),
)
err := client.Asset.Delete(context.Background(), 1, "foo/bar.liquid")
if err != nil {
t.Errorf("Asset.Delete returned error: %v", err)
}
}