@@ -37,6 +37,7 @@ import {
37
37
SafetySetting ,
38
38
StreamGenerateContentResult ,
39
39
} from '../src/types/content' ;
40
+ import { GoogleAuthError } from '../src/types/errors' ;
40
41
import { constants } from '../src/util' ;
41
42
42
43
const PROJECT = 'test_project' ;
@@ -214,7 +215,7 @@ describe('VertexAI', () => {
214
215
215
216
it ( 'given specified google auth options, should be instantiated' , ( ) => {
216
217
const googleAuthOptions = {
217
- scopes : 'test.scopes ' ,
218
+ scopes : 'https://www.googleapis.com/auth/cloud-platform ' ,
218
219
} ;
219
220
const vetexai1 = new VertexAI ( {
220
221
project : PROJECT ,
@@ -241,6 +242,41 @@ describe('VertexAI', () => {
241
242
) ;
242
243
} ) ;
243
244
245
+ it ( 'given scopes missing required scope, should throw GoogleAuthError' , ( ) => {
246
+ const invalidGoogleAuthOptionsStringScopes = { scopes : 'test.scopes' } ;
247
+ expect ( ( ) => {
248
+ new VertexAI ( {
249
+ project : PROJECT ,
250
+ location : LOCATION ,
251
+ googleAuthOptions : invalidGoogleAuthOptionsStringScopes ,
252
+ } ) ;
253
+ } ) . toThrow (
254
+ new GoogleAuthError (
255
+ "input GoogleAuthOptions.scopes test.scopes doesn't contain required scope " +
256
+ 'https://www.googleapis.com/auth/cloud-platform, ' +
257
+ 'please include https://www.googleapis.com/auth/cloud-platform into GoogleAuthOptions.scopes ' +
258
+ 'or leave GoogleAuthOptions.scopes undefined'
259
+ )
260
+ ) ;
261
+ const invalidGoogleAuthOptionsArrayScopes = {
262
+ scopes : [ 'test1.scopes' , 'test2.scopes' ] ,
263
+ } ;
264
+ expect ( ( ) => {
265
+ new VertexAI ( {
266
+ project : PROJECT ,
267
+ location : LOCATION ,
268
+ googleAuthOptions : invalidGoogleAuthOptionsArrayScopes ,
269
+ } ) ;
270
+ } ) . toThrow (
271
+ new GoogleAuthError (
272
+ "input GoogleAuthOptions.scopes test1.scopes,test2.scopes doesn't contain required scope " +
273
+ 'https://www.googleapis.com/auth/cloud-platform, ' +
274
+ 'please include https://www.googleapis.com/auth/cloud-platform into GoogleAuthOptions.scopes ' +
275
+ 'or leave GoogleAuthOptions.scopes undefined'
276
+ )
277
+ ) ;
278
+ } ) ;
279
+
244
280
describe ( 'generateContent' , ( ) => {
245
281
it ( 'returns a GenerateContentResponse' , async ( ) => {
246
282
const req : GenerateContentRequest = {
0 commit comments