This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 325
/
asset_test.go
106 lines (88 loc) · 2.27 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
package goshopify
import (
"reflect"
"testing"
"gopkg.in/jarcoal/httpmock.v1"
)
func assetTests(t *testing.T, asset Asset) {
expectedKey := "templates/index.liquid"
if asset.Key != expectedKey {
t.Errorf("Asset.Key returned %+v, expected %+v", asset.Key, expectedKey)
}
}
func TestAssetList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder(
"GET",
"https://fooshop.myshopify.com/admin/themes/1/assets.json",
httpmock.NewStringResponder(
200,
`{"assets": [{"key":"assets\/1.liquid"},{"key":"assets\/2.liquid"}]}`,
),
)
assets, err := client.Asset.List(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()
httpmock.RegisterResponder(
"GET",
"https://fooshop.myshopify.com/admin/themes/1/assets.json?asset%5Bkey%5D=foo%2Fbar.liquid&theme_id=1",
httpmock.NewStringResponder(
200,
`{"asset": {"key":"foo\/bar.liquid"}}`,
),
)
asset, err := client.Asset.Get(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",
"https://fooshop.myshopify.com/admin/themes/1/assets.json",
httpmock.NewBytesResponder(
200,
loadFixture("asset.json"),
),
)
asset := Asset{
Key: "templates/index.liquid",
Value: "content",
}
returnedAsset, err := client.Asset.Update(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()
httpmock.RegisterResponder(
"DELETE",
"https://fooshop.myshopify.com/admin/themes/1/assets.json?asset[key]=foo/bar.liquid",
httpmock.NewStringResponder(200, "{}"),
)
err := client.Asset.Delete(1, "foo/bar.liquid")
if err != nil {
t.Errorf("Asset.Delete returned error: %v", err)
}
}