1818import { expect , use } from 'chai' ;
1919import chaiAsPromised from 'chai-as-promised' ;
2020import * as sinon from 'sinon' ;
21+ import sinonChai from 'sinon-chai' ;
2122
2223import { dcFetch , initializeFetch } from '../../src/network/fetch' ;
2324import { CallerSdkType , CallerSdkTypeEnum } from '../../src/network/transport' ;
2425use ( chaiAsPromised ) ;
26+ use ( sinonChai ) ;
2527function mockFetch ( json : object , reject : boolean ) : sinon . SinonStub {
2628 const fakeFetchImpl = sinon . stub ( ) . returns (
2729 Promise . resolve ( {
@@ -57,7 +59,8 @@ describe('fetch', () => {
5759 null ,
5860 null ,
5961 false ,
60- CallerSdkTypeEnum . Base
62+ CallerSdkTypeEnum . Base ,
63+ false
6164 )
6265 ) . to . eventually . be . rejectedWith ( message ) ;
6366 } ) ;
@@ -81,7 +84,8 @@ describe('fetch', () => {
8184 null ,
8285 null ,
8386 false ,
84- CallerSdkTypeEnum . Base
87+ CallerSdkTypeEnum . Base ,
88+ false
8589 )
8690 ) . to . eventually . be . rejectedWith ( JSON . stringify ( json ) ) ;
8791 } ) ;
@@ -112,7 +116,8 @@ describe('fetch', () => {
112116 null ,
113117 null ,
114118 false ,
115- CallerSdkTypeEnum . Base
119+ CallerSdkTypeEnum . Base ,
120+ false
116121 )
117122 ) . to . eventually . be . rejected . then ( error => {
118123 expect ( error . response . data ) . to . eq ( json . data ) ;
@@ -143,7 +148,8 @@ describe('fetch', () => {
143148 null ,
144149 null ,
145150 false , // _isUsingGen is false
146- callerSdkType as CallerSdkType
151+ callerSdkType as CallerSdkType ,
152+ false
147153 ) ;
148154
149155 let expectedHeaderRegex : RegExp ;
@@ -191,7 +197,8 @@ describe('fetch', () => {
191197 null ,
192198 null ,
193199 true , // _isUsingGen is true
194- callerSdkType as CallerSdkType
200+ callerSdkType as CallerSdkType ,
201+ false
195202 ) ;
196203
197204 let expectedHeaderRegex : RegExp ;
@@ -215,4 +222,30 @@ describe('fetch', () => {
215222 }
216223 }
217224 } ) ;
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+ } ) ;
218251} ) ;
0 commit comments