forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storefrontaccesstoken_test.go
87 lines (67 loc) · 2.99 KB
/
storefrontaccesstoken_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
package goshopify
import (
"fmt"
"testing"
"time"
"github.com/jarcoal/httpmock"
)
func storefrontAccessTokenTests(t *testing.T, StorefrontAccessToken StorefrontAccessToken) {
expectedStr := "API Client Extension"
if StorefrontAccessToken.Title != expectedStr {
t.Errorf("StorefrontAccessToken.Title returned %+v, expected %+v", StorefrontAccessToken.Title, expectedStr)
}
expectedStr = "378d95641257a4ab3feff967ee234f4d"
if StorefrontAccessToken.AccessToken != expectedStr {
t.Errorf("StorefrontAccessToken.AccessToken returned %+v, expected %+v", StorefrontAccessToken.AccessToken, expectedStr)
}
expectedStr = "unauthenticated_read_product_listings"
if StorefrontAccessToken.AccessScope != expectedStr {
t.Errorf("StorefrontAccessToken.AccessScope returned %+v, expected %+v", StorefrontAccessToken.AccessScope, expectedStr)
}
expectedStr = "gid://shopify/StorefrontAccessToken/755357713"
if StorefrontAccessToken.AdminGraphqlAPIID != expectedStr {
t.Errorf("StorefrontAccessToken.AdminGraphqlAPIID returned %+v, expected %+v", StorefrontAccessToken.AdminGraphqlAPIID, expectedStr)
}
d := time.Date(2016, time.June, 1, 14, 10, 44, 0, time.UTC)
if !d.Equal(*StorefrontAccessToken.CreatedAt) {
t.Errorf("StorefrontAccessToken.CreatedAt returned %+v, expected %+v", StorefrontAccessToken.CreatedAt, d)
}
}
func TestStorefrontAccessTokenList(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("storefront_access_tokens.json")))
storefrontAccessTokens, err := client.StorefrontAccessToken.List(nil)
if err != nil {
t.Errorf("StorefrontAccessToken.List returned error: %v", err)
}
if len(storefrontAccessTokens) != 1 {
t.Errorf("StorefrontAccessToken.List got %v storefront access tokens, expected: 1", len(storefrontAccessTokens))
}
storefrontAccessTokenTests(t, storefrontAccessTokens[0])
}
func TestStorefrontAccessTokenCreate(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("storefront_access_token.json")))
storefrontAccessToken := StorefrontAccessToken{
Title: "API Client Extension",
}
returnedStorefrontAccessToken, err := client.StorefrontAccessToken.Create(storefrontAccessToken)
if err != nil {
t.Errorf("StorefrontAccessToken.Create returned error: %v", err)
}
storefrontAccessTokenTests(t, *returnedStorefrontAccessToken)
}
func TestStorefrontAccessTokenDelete(t *testing.T) {
setup()
defer teardown()
httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens/755357713.json", client.pathPrefix),
httpmock.NewStringResponder(200, "{}"))
err := client.StorefrontAccessToken.Delete(755357713)
if err != nil {
t.Errorf("StorefrontAccessToken.Delete returned error: %v", err)
}
}