15
15
* limitations under the License.
16
16
*/
17
17
import { describe , expect , it , afterEach , jest , beforeEach } from '@jest/globals' ;
18
- import { getMockResponse } from './test-utils/mock-response' ;
18
+ import { BackendName , getMockResponse } from './test-utils/mock-response' ;
19
19
import * as request from '../lib/requests/request' ;
20
20
import { generateContent } from '../lib/methods/generate-content' ;
21
21
import {
@@ -81,7 +81,10 @@ describe('generateContent()', () => {
81
81
} ) ;
82
82
83
83
it ( 'short response' , async ( ) => {
84
- const mockResponse = getMockResponse ( 'unary-success-basic-reply-short.json' ) ;
84
+ const mockResponse = getMockResponse (
85
+ BackendName . VertexAI ,
86
+ 'unary-success-basic-reply-short.json' ,
87
+ ) ;
85
88
const makeRequestStub = jest
86
89
. spyOn ( request , 'makeRequest' )
87
90
. mockResolvedValue ( mockResponse as Response ) ;
@@ -98,7 +101,10 @@ describe('generateContent()', () => {
98
101
} ) ;
99
102
100
103
it ( 'long response' , async ( ) => {
101
- const mockResponse = getMockResponse ( 'unary-success-basic-reply-long.json' ) ;
104
+ const mockResponse = getMockResponse (
105
+ BackendName . VertexAI ,
106
+ 'unary-success-basic-reply-long.json' ,
107
+ ) ;
102
108
const makeRequestStub = jest
103
109
. spyOn ( request , 'makeRequest' )
104
110
. mockResolvedValue ( mockResponse as Response ) ;
@@ -116,7 +122,10 @@ describe('generateContent()', () => {
116
122
} ) ;
117
123
118
124
it ( 'long response with token details' , async ( ) => {
119
- const mockResponse = getMockResponse ( 'unary-success-basic-response-long-usage-metadata.json' ) ;
125
+ const mockResponse = getMockResponse (
126
+ BackendName . VertexAI ,
127
+ 'unary-success-basic-response-long-usage-metadata.json' ,
128
+ ) ;
120
129
const makeRequestStub = jest
121
130
. spyOn ( request , 'makeRequest' )
122
131
. mockResolvedValue ( mockResponse as Response ) ;
@@ -138,7 +147,7 @@ describe('generateContent()', () => {
138
147
} ) ;
139
148
140
149
it ( 'citations' , async ( ) => {
141
- const mockResponse = getMockResponse ( 'unary-success-citations.json' ) ;
150
+ const mockResponse = getMockResponse ( BackendName . VertexAI , 'unary-success-citations.json' ) ;
142
151
const makeRequestStub = jest
143
152
. spyOn ( request , 'makeRequest' )
144
153
. mockResolvedValue ( mockResponse as Response ) ;
@@ -156,7 +165,10 @@ describe('generateContent()', () => {
156
165
} ) ;
157
166
158
167
it ( 'blocked prompt' , async ( ) => {
159
- const mockResponse = getMockResponse ( 'unary-failure-prompt-blocked-safety.json' ) ;
168
+ const mockResponse = getMockResponse (
169
+ BackendName . VertexAI ,
170
+ 'unary-failure-prompt-blocked-safety.json' ,
171
+ ) ;
160
172
const makeRequestStub = jest
161
173
. spyOn ( request , 'makeRequest' )
162
174
. mockResolvedValue ( mockResponse as Response ) ;
@@ -175,7 +187,10 @@ describe('generateContent()', () => {
175
187
} ) ;
176
188
177
189
it ( 'finishReason safety' , async ( ) => {
178
- const mockResponse = getMockResponse ( 'unary-failure-finish-reason-safety.json' ) ;
190
+ const mockResponse = getMockResponse (
191
+ BackendName . VertexAI ,
192
+ 'unary-failure-finish-reason-safety.json' ,
193
+ ) ;
179
194
const makeRequestStub = jest
180
195
. spyOn ( request , 'makeRequest' )
181
196
. mockResolvedValue ( mockResponse as Response ) ;
@@ -192,7 +207,7 @@ describe('generateContent()', () => {
192
207
} ) ;
193
208
194
209
it ( 'empty content' , async ( ) => {
195
- const mockResponse = getMockResponse ( 'unary-failure-empty-content.json' ) ;
210
+ const mockResponse = getMockResponse ( BackendName . VertexAI , 'unary-failure-empty-content.json' ) ;
196
211
const makeRequestStub = jest
197
212
. spyOn ( request , 'makeRequest' )
198
213
. mockResolvedValue ( mockResponse as Response ) ;
@@ -209,7 +224,10 @@ describe('generateContent()', () => {
209
224
} ) ;
210
225
211
226
it ( 'unknown enum - should ignore' , async ( ) => {
212
- const mockResponse = getMockResponse ( 'unary-success-unknown-enum-safety-ratings.json' ) ;
227
+ const mockResponse = getMockResponse (
228
+ BackendName . VertexAI ,
229
+ 'unary-success-unknown-enum-safety-ratings.json' ,
230
+ ) ;
213
231
const makeRequestStub = jest
214
232
. spyOn ( request , 'makeRequest' )
215
233
. mockResolvedValue ( mockResponse as Response ) ;
@@ -226,7 +244,7 @@ describe('generateContent()', () => {
226
244
} ) ;
227
245
228
246
it ( 'image rejected (400)' , async ( ) => {
229
- const mockResponse = getMockResponse ( 'unary-failure-image-rejected.json' ) ;
247
+ const mockResponse = getMockResponse ( BackendName . VertexAI , 'unary-failure-image-rejected.json' ) ;
230
248
const mockFetch = jest . spyOn ( globalThis , 'fetch' ) . mockResolvedValue ( {
231
249
ok : false ,
232
250
status : 400 ,
@@ -239,7 +257,10 @@ describe('generateContent()', () => {
239
257
} ) ;
240
258
241
259
it ( 'api not enabled (403)' , async ( ) => {
242
- const mockResponse = getMockResponse ( 'unary-failure-firebasevertexai-api-not-enabled.json' ) ;
260
+ const mockResponse = getMockResponse (
261
+ BackendName . VertexAI ,
262
+ 'unary-failure-firebasevertexai-api-not-enabled.json' ,
263
+ ) ;
243
264
const mockFetch = jest . spyOn ( globalThis , 'fetch' ) . mockResolvedValue ( {
244
265
ok : false ,
245
266
status : 403 ,
@@ -263,7 +284,10 @@ describe('generateContent()', () => {
263
284
} ) ;
264
285
265
286
it ( 'throws error when method is defined' , async ( ) => {
266
- const mockResponse = getMockResponse ( 'unary-success-basic-reply-short.txt' ) ;
287
+ const mockResponse = getMockResponse (
288
+ BackendName . GoogleAI ,
289
+ 'unary-success-basic-reply-short.txt' ,
290
+ ) ;
267
291
makeRequestStub . mockResolvedValue ( mockResponse as Response ) ;
268
292
269
293
const requestParamsWithMethod : GenerateContentRequest = {
@@ -285,7 +309,10 @@ describe('generateContent()', () => {
285
309
} ) ;
286
310
287
311
it ( 'maps request to GoogleAI format' , async ( ) => {
288
- const mockResponse = getMockResponse ( 'unary-success-basic-reply-short.txt' ) ;
312
+ const mockResponse = getMockResponse (
313
+ BackendName . GoogleAI ,
314
+ 'unary-success-basic-reply-short.txt' ,
315
+ ) ;
289
316
makeRequestStub . mockResolvedValue ( mockResponse as Response ) ;
290
317
291
318
await generateContent ( fakeGoogleAIApiSettings , 'model' , fakeGoogleAIRequestParams ) ;
0 commit comments