18
18
import { expect , use } from 'chai' ;
19
19
import chaiAsPromised from 'chai-as-promised' ;
20
20
import * as sinon from 'sinon' ;
21
+ import sinonChai from 'sinon-chai' ;
21
22
22
23
import { dcFetch , initializeFetch } from '../../src/network/fetch' ;
23
24
import { CallerSdkType , CallerSdkTypeEnum } from '../../src/network/transport' ;
24
25
use ( chaiAsPromised ) ;
26
+ use ( sinonChai ) ;
25
27
function mockFetch ( json : object , reject : boolean ) : sinon . SinonStub {
26
28
const fakeFetchImpl = sinon . stub ( ) . returns (
27
29
Promise . resolve ( {
@@ -57,7 +59,8 @@ describe('fetch', () => {
57
59
null ,
58
60
null ,
59
61
false ,
60
- CallerSdkTypeEnum . Base
62
+ CallerSdkTypeEnum . Base ,
63
+ false
61
64
)
62
65
) . to . eventually . be . rejectedWith ( message ) ;
63
66
} ) ;
@@ -81,7 +84,8 @@ describe('fetch', () => {
81
84
null ,
82
85
null ,
83
86
false ,
84
- CallerSdkTypeEnum . Base
87
+ CallerSdkTypeEnum . Base ,
88
+ false
85
89
)
86
90
) . to . eventually . be . rejectedWith ( JSON . stringify ( json ) ) ;
87
91
} ) ;
@@ -112,7 +116,8 @@ describe('fetch', () => {
112
116
null ,
113
117
null ,
114
118
false ,
115
- CallerSdkTypeEnum . Base
119
+ CallerSdkTypeEnum . Base ,
120
+ false
116
121
)
117
122
) . to . eventually . be . rejected . then ( error => {
118
123
expect ( error . response . data ) . to . eq ( json . data ) ;
@@ -143,7 +148,8 @@ describe('fetch', () => {
143
148
null ,
144
149
null ,
145
150
false , // _isUsingGen is false
146
- callerSdkType as CallerSdkType
151
+ callerSdkType as CallerSdkType ,
152
+ false
147
153
) ;
148
154
149
155
let expectedHeaderRegex : RegExp ;
@@ -191,7 +197,8 @@ describe('fetch', () => {
191
197
null ,
192
198
null ,
193
199
true , // _isUsingGen is true
194
- callerSdkType as CallerSdkType
200
+ callerSdkType as CallerSdkType ,
201
+ false
195
202
) ;
196
203
197
204
let expectedHeaderRegex : RegExp ;
@@ -215,4 +222,30 @@ describe('fetch', () => {
215
222
}
216
223
}
217
224
} ) ;
225
+ it ( 'should call credentials include if using emulator on cloud workstation' , async ( ) => {
226
+ const json = {
227
+ code : 200 ,
228
+ message1 : 'success'
229
+ } ;
230
+ const fakeFetchImpl = mockFetch ( json , false ) ;
231
+ await dcFetch (
232
+ 'https://abc.cloudworkstations.dev' ,
233
+ {
234
+ name : 'n' ,
235
+ operationName : 'n' ,
236
+ variables : { }
237
+ } ,
238
+ { } as AbortController ,
239
+ null ,
240
+ null ,
241
+ null ,
242
+ true , // _isUsingGen is true
243
+ CallerSdkTypeEnum . Base ,
244
+ true
245
+ ) ;
246
+ expect ( fakeFetchImpl ) . to . have . been . calledWithMatch (
247
+ 'https://abc.cloudworkstations.dev' ,
248
+ { credentials : 'include' }
249
+ ) ;
250
+ } ) ;
218
251
} ) ;
0 commit comments