@@ -9,10 +9,10 @@ suite('client-test', () => {
9
9
const config = {
10
10
domain : 'sendmecats.myshopify.com' ,
11
11
storefrontAccessToken : 'abc123' ,
12
- apiVersion : '2019-10 '
12
+ apiVersion : '2020-01 '
13
13
} ;
14
14
15
- test ( 'it instantiates a GraphQL client with the given config and without custom source header when no source config is provided ' , ( ) => {
15
+ test ( 'it instantiates a GraphQL client with the given config' , ( ) => {
16
16
let passedTypeBundle ;
17
17
let passedUrl ;
18
18
let passedFetcherOptions ;
@@ -28,7 +28,7 @@ suite('client-test', () => {
28
28
new Client ( new Config ( config ) , FakeGraphQLJSClient ) ; // eslint-disable-line no-new
29
29
30
30
assert . deepEqual ( passedTypeBundle , types ) ;
31
- assert . equal ( passedUrl , `https://sendmecats.myshopify.com /api/${ config . apiVersion } /graphql` ) ;
31
+ assert . equal ( passedUrl , `https://${ config . domain } /api/${ config . apiVersion } /graphql` ) ;
32
32
assert . deepEqual ( passedFetcherOptions , {
33
33
headers : {
34
34
'X-SDK-Variant' : 'javascript' ,
@@ -51,26 +51,55 @@ suite('client-test', () => {
51
51
}
52
52
}
53
53
54
- const withSourceConfig = {
55
- domain : 'sendmecats.myshopify.com' ,
56
- storefrontAccessToken : 'abc123' ,
54
+ const withSourceConfig = Object . assign ( { } , config , {
57
55
source : 'buy-button-js'
58
- } ;
56
+ } ) ;
59
57
60
58
new Client ( new Config ( withSourceConfig ) , FakeGraphQLJSClient ) ; // eslint-disable-line no-new
61
59
62
60
assert . deepEqual ( passedTypeBundle , types ) ;
63
- assert . equal ( passedUrl , `https://sendmecats.myshopify.com /api/${ config . apiVersion } /graphql` ) ;
61
+ assert . equal ( passedUrl , `https://${ withSourceConfig . domain } /api/${ withSourceConfig . apiVersion } /graphql` ) ;
64
62
assert . deepEqual ( passedFetcherOptions , {
65
63
headers : {
66
64
'X-SDK-Variant' : 'javascript' ,
67
65
'X-SDK-Version' : version ,
68
- 'X-Shopify-Storefront-Access-Token' : config . storefrontAccessToken ,
66
+ 'X-Shopify-Storefront-Access-Token' : withSourceConfig . storefrontAccessToken ,
69
67
'X-SDK-Variant-Source' : withSourceConfig . source
70
68
}
71
69
} ) ;
72
70
} ) ;
73
71
72
+ test ( 'it instantiates a GraphQL client with the given config and language header when a language config is provided' , ( ) => {
73
+ let passedTypeBundle ;
74
+ let passedUrl ;
75
+ let passedFetcherOptions ;
76
+
77
+ class FakeGraphQLJSClient {
78
+ constructor ( typeBundle , { url, fetcherOptions} ) {
79
+ passedTypeBundle = typeBundle ;
80
+ passedUrl = url ;
81
+ passedFetcherOptions = fetcherOptions ;
82
+ }
83
+ }
84
+
85
+ const withLanguageConfig = Object . assign ( { } , config , {
86
+ language : 'ja-JP'
87
+ } ) ;
88
+
89
+ new Client ( new Config ( withLanguageConfig ) , FakeGraphQLJSClient ) ; // eslint-disable-line no-new
90
+
91
+ assert . deepEqual ( passedTypeBundle , types ) ;
92
+ assert . equal ( passedUrl , `https://${ withLanguageConfig . domain } /api/${ withLanguageConfig . apiVersion } /graphql` ) ;
93
+ assert . deepEqual ( passedFetcherOptions , {
94
+ headers : {
95
+ 'X-SDK-Variant' : 'javascript' ,
96
+ 'X-SDK-Version' : version ,
97
+ 'X-Shopify-Storefront-Access-Token' : withLanguageConfig . storefrontAccessToken ,
98
+ 'Accept-Language' : withLanguageConfig . language
99
+ }
100
+ } ) ;
101
+ } ) ;
102
+
74
103
test ( 'it creates a fetcher from the fetch function provided' , ( ) => {
75
104
let passedFetcher ;
76
105
let passedUrl ;
@@ -98,7 +127,7 @@ suite('client-test', () => {
98
127
new Client ( new Config ( config ) , FakeGraphQLJSClient , fetchFunction ) ; // eslint-disable-line no-new
99
128
100
129
return passedFetcher ( { data : 'body' } ) . then ( ( ) => {
101
- assert . equal ( passedUrl , `https://sendmecats.myshopify.com /api/${ config . apiVersion } /graphql` ) ;
130
+ assert . equal ( passedUrl , `https://${ config . domain } /api/${ config . apiVersion } /graphql` ) ;
102
131
assert . equal ( passedBody , JSON . stringify ( { data : 'body' } ) ) ;
103
132
assert . equal ( passedMethod , 'POST' ) ;
104
133
assert . equal ( passedMode , 'cors' ) ;
0 commit comments