@@ -27,7 +27,10 @@ import {
27
27
_makeRequestInternal ,
28
28
constructRequest ,
29
29
} from "./request" ;
30
- import { GoogleGenerativeAIFetchError } from "../errors" ;
30
+ import {
31
+ GoogleGenerativeAIFetchError ,
32
+ GoogleGenerativeAIRequestInputError ,
33
+ } from "../errors" ;
31
34
32
35
use ( sinonChai ) ;
33
36
use ( chaiAsPromised ) ;
@@ -155,6 +158,40 @@ describe("request methods", () => {
155
158
) ;
156
159
expect ( request . fetchOptions . signal ) . to . be . instanceOf ( AbortSignal ) ;
157
160
} ) ;
161
+ it ( "passes custom headers" , async ( ) => {
162
+ const request = await constructRequest (
163
+ "model-name" ,
164
+ Task . GENERATE_CONTENT ,
165
+ "key" ,
166
+ true ,
167
+ "" ,
168
+ {
169
+ customHeaders : new Headers ( { customerHeader : "customerHeaderValue" } ) ,
170
+ } ,
171
+ ) ;
172
+ expect (
173
+ ( request . fetchOptions . headers as Headers ) . get ( "customerHeader" ) ,
174
+ ) . to . equal ( "customerHeaderValue" ) ;
175
+ } ) ;
176
+ it ( "passes custom x-goog-api-client header" , async ( ) => {
177
+ await expect (
178
+ constructRequest ( "model-name" , Task . GENERATE_CONTENT , "key" , true , "" , {
179
+ customHeaders : new Headers ( {
180
+ "x-goog-api-client" : "client/version" ,
181
+ } ) ,
182
+ } ) ,
183
+ ) . to . be . rejectedWith ( GoogleGenerativeAIRequestInputError ) ;
184
+ } ) ;
185
+ it ( "passes apiClient and custom x-goog-api-client header" , async ( ) => {
186
+ await expect (
187
+ constructRequest ( "model-name" , Task . GENERATE_CONTENT , "key" , true , "" , {
188
+ apiClient : "client/version" ,
189
+ customHeaders : new Headers ( {
190
+ "x-goog-api-client" : "client/version2" ,
191
+ } ) ,
192
+ } ) ,
193
+ ) . to . be . rejectedWith ( GoogleGenerativeAIRequestInputError ) ;
194
+ } ) ;
158
195
} ) ;
159
196
describe ( "_makeRequestInternal" , ( ) => {
160
197
it ( "no error" , async ( ) => {
@@ -309,5 +346,23 @@ describe("request methods", () => {
309
346
}
310
347
expect ( fetchStub ) . to . be . calledOnce ;
311
348
} ) ;
349
+ it ( "has invalid custom header" , async ( ) => {
350
+ const fetchStub = stub ( ) ;
351
+ await expect (
352
+ _makeRequestInternal (
353
+ "model-name" ,
354
+ Task . GENERATE_CONTENT ,
355
+ "key" ,
356
+ true ,
357
+ "" ,
358
+ {
359
+ customHeaders : new Headers ( {
360
+ "x-goog-api-client" : "client/version" ,
361
+ } ) ,
362
+ } ,
363
+ fetchStub as typeof fetch ,
364
+ ) ,
365
+ ) . to . be . rejectedWith ( GoogleGenerativeAIRequestInputError ) ;
366
+ } ) ;
312
367
} ) ;
313
368
} ) ;
0 commit comments