1
+ import { createSha256 } from "helpers" ;
1
2
import {
2
3
afterAll ,
3
4
beforeAll ,
@@ -10,7 +11,6 @@ import {
10
11
import createFetchMock from "vitest-fetch-mock" ;
11
12
import { initClientFetcher } from "./client" ;
12
13
import { TypedDocumentString } from "./testing" ;
13
- import { createSha256 } from "helpers" ;
14
14
15
15
const query = new TypedDocumentString ( /* GraphQL */ `
16
16
query myQuery {
@@ -98,6 +98,7 @@ describe("gqlClientFetch", () => {
98
98
} ,
99
99
) ;
100
100
} ) ;
101
+
101
102
it ( "should perform a mutation" , async ( ) => {
102
103
const mockedFetch = fetchMock . mockResponse ( responseString ) ;
103
104
const gqlResponse = await fetcher ( mutation , {
@@ -196,6 +197,64 @@ describe("gqlClientFetch", () => {
196
197
expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
197
198
} ) ;
198
199
200
+ it ( "should use 'omit' credentials when provided" , async ( ) => {
201
+ const fetcher = initClientFetcher ( "https://localhost/graphql" , {
202
+ defaultCredentials : "omit" ,
203
+ } ) ;
204
+ fetchMock . mockResponse ( responseString ) ;
205
+
206
+ const gqlResponse = await fetcher ( query , {
207
+ myVar : "baz" ,
208
+ } ) ;
209
+
210
+ expect ( gqlResponse ) . toEqual ( response ) ;
211
+
212
+ expect ( fetchMock ) . toHaveBeenCalledWith (
213
+ expect . any ( String ) ,
214
+ expect . objectContaining ( {
215
+ credentials : "omit" ,
216
+ } ) ,
217
+ ) ;
218
+ } ) ;
219
+
220
+ it ( "should use 'same-origin' credentials when provided" , async ( ) => {
221
+ const fetcher = initClientFetcher ( "https://localhost/graphql" , {
222
+ defaultCredentials : "same-origin" ,
223
+ } ) ;
224
+ fetchMock . mockResponse ( responseString ) ;
225
+
226
+ const gqlResponse = await fetcher ( query , {
227
+ myVar : "baz" ,
228
+ } ) ;
229
+
230
+ expect ( gqlResponse ) . toEqual ( response ) ;
231
+
232
+ expect ( fetchMock ) . toHaveBeenCalledWith (
233
+ expect . any ( String ) ,
234
+ expect . objectContaining ( {
235
+ credentials : "same-origin" ,
236
+ } ) ,
237
+ ) ;
238
+ } ) ;
239
+
240
+ it ( "should use 'include' credentials when provided" , async ( ) => {
241
+ const fetcher = initClientFetcher ( "https://localhost/graphql" ) ;
242
+ fetchMock . mockResponse ( responseString ) ;
243
+
244
+ const gqlResponse = await fetcher ( query , {
245
+ myVar : "baz" ,
246
+ } ) ;
247
+
248
+ expect ( gqlResponse ) . toEqual ( response ) ;
249
+
250
+ expect ( fetchMock ) . toHaveBeenCalledWith (
251
+ expect . any ( String ) ,
252
+ expect . objectContaining ( {
253
+ credentials : "include" ,
254
+ } ) ,
255
+ ) ;
256
+ } ) ;
257
+
199
258
it ( "should use the provided signal" , async ( ) => {
200
259
const fetcher = initClientFetcher ( "https://localhost/graphql" ) ;
201
260
fetchMock . mockResponse ( responseString ) ;
0 commit comments