@@ -178,6 +178,77 @@ describe("createConnectQueryKey", () => {
178
178
} ) ;
179
179
} ) ;
180
180
181
+ describe ( "headers" , ( ) => {
182
+ it ( "allows headers to be passed as an object" , ( ) => {
183
+ const key = createConnectQueryKey ( {
184
+ schema : ElizaService . method . say ,
185
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
186
+ cardinality : "finite" ,
187
+ headers : {
188
+ "x-custom-header" : "custom-value" ,
189
+ } ,
190
+ } ) ;
191
+ expect ( key [ 1 ] . headers ) . toEqual ( {
192
+ "x-custom-header" : "custom-value" ,
193
+ } ) ;
194
+ } ) ;
195
+ it ( "allows headers to be passed as a tuple" , ( ) => {
196
+ const key = createConnectQueryKey ( {
197
+ schema : ElizaService . method . say ,
198
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
199
+ cardinality : "finite" ,
200
+ headers : [ [ "x-custom-header" , "custom-value" ] ] ,
201
+ } ) ;
202
+ expect ( key [ 1 ] . headers ) . toEqual ( {
203
+ "x-custom-header" : "custom-value" ,
204
+ } ) ;
205
+ } ) ;
206
+ it ( "allows headers to be passed as a HeadersInit" , ( ) => {
207
+ const key = createConnectQueryKey ( {
208
+ schema : ElizaService . method . say ,
209
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
210
+ cardinality : "finite" ,
211
+ headers : new Headers ( {
212
+ "x-custom-header" : "custom-value" ,
213
+ } ) ,
214
+ } ) ;
215
+ expect ( key [ 1 ] . headers ) . toEqual ( {
216
+ "x-custom-header" : "custom-value" ,
217
+ } ) ;
218
+ } ) ;
219
+ it ( "normalizes header values" , ( ) => {
220
+ const keyA = createConnectQueryKey ( {
221
+ schema : ElizaService . method . say ,
222
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
223
+ cardinality : "finite" ,
224
+ headers : {
225
+ foo : "a" ,
226
+ Foo : "b" ,
227
+ } ,
228
+ } ) ;
229
+ const keyB = createConnectQueryKey ( {
230
+ schema : ElizaService . method . say ,
231
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
232
+ cardinality : "finite" ,
233
+ headers : {
234
+ foo : "a, b" ,
235
+ } ,
236
+ } ) ;
237
+ const keyC = createConnectQueryKey ( {
238
+ schema : ElizaService . method . say ,
239
+ input : create ( SayRequestSchema , { sentence : "hi" } ) ,
240
+ cardinality : "finite" ,
241
+ headers : [
242
+ [ "foo" , "a" ] ,
243
+ [ "foo" , "b" ] ,
244
+ ] ,
245
+ } ) ;
246
+
247
+ expect ( keyA [ 1 ] . headers ) . toEqual ( keyB [ 1 ] . headers ) ;
248
+ expect ( keyA [ 1 ] . headers ) . toEqual ( keyC [ 1 ] . headers ) ;
249
+ } ) ;
250
+ } ) ;
251
+
181
252
describe ( "infinite queries" , ( ) => {
182
253
it ( "contains type hints to indicate the output type" , ( ) => {
183
254
const sampleQueryClient = new QueryClient ( ) ;
0 commit comments