@@ -18,52 +18,39 @@ import { expect } from 'chai';
1818import { AI_TYPE } from './constants' ;
1919import { encodeInstanceIdentifier , decodeInstanceIdentifier } from './helpers' ;
2020import { AIError } from './errors' ;
21- import { BackendType } from './public-types' ;
22- import { InstanceIdentifier } from './types/internal' ;
2321import { AIErrorCode } from './types' ;
22+ import { GoogleAIBackend , VertexAIBackend } from './backend' ;
2423
2524describe ( 'Identifier Encoding/Decoding' , ( ) => {
2625 describe ( 'encodeInstanceIdentifier' , ( ) => {
2726 it ( 'should encode Vertex AI identifier with a specific location' , ( ) => {
28- const identifier : InstanceIdentifier = {
29- backendType : BackendType . VERTEX_AI ,
30- location : 'us-central1'
31- } ;
27+ const backend = new VertexAIBackend ( 'us-central1' ) ;
3228 const expected = `${ AI_TYPE } /vertexai/us-central1` ;
33- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
29+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
3430 } ) ;
3531
3632 it ( 'should encode Vertex AI identifier using empty location' , ( ) => {
37- const identifier : InstanceIdentifier = {
38- backendType : BackendType . VERTEX_AI ,
39- location : ''
40- } ;
33+ const backend = new VertexAIBackend ( '' ) ;
4134 const expected = `${ AI_TYPE } /vertexai/` ;
42- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
35+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
4336 } ) ;
4437
4538 it ( 'should encode Google AI identifier' , ( ) => {
46- const identifier : InstanceIdentifier = {
47- backendType : BackendType . GOOGLE_AI
48- } ;
39+ const backend = new GoogleAIBackend ( ) ;
4940 const expected = `${ AI_TYPE } /googleai` ;
50- expect ( encodeInstanceIdentifier ( identifier ) ) . to . equal ( expected ) ;
41+ expect ( encodeInstanceIdentifier ( backend ) ) . to . equal ( expected ) ;
5142 } ) ;
5243
5344 it ( 'should throw AIError for unknown backend type' , ( ) => {
54- const identifier = {
55- backendType : 'some-future-backend'
56- } as any ; // bypass type checking for the test
57-
58- expect ( ( ) => encodeInstanceIdentifier ( identifier ) ) . to . throw ( AIError ) ;
45+ expect ( ( ) => encodeInstanceIdentifier ( { } as any ) ) . to . throw ( AIError ) ;
5946
6047 try {
61- encodeInstanceIdentifier ( identifier ) ;
48+ encodeInstanceIdentifier ( { } as any ) ;
6249 expect . fail ( 'Expected encodeInstanceIdentifier to throw' ) ;
6350 } catch ( e ) {
6451 expect ( e ) . to . be . instanceOf ( AIError ) ;
6552 const error = e as AIError ;
66- expect ( error . message ) . to . contain ( `Unknown backend` ) ;
53+ expect ( error . message ) . to . contain ( 'Invalid backend' ) ;
6754 expect ( error . code ) . to . equal ( AIErrorCode . ERROR ) ;
6855 }
6956 } ) ;
@@ -72,11 +59,8 @@ describe('Identifier Encoding/Decoding', () => {
7259 describe ( 'decodeInstanceIdentifier' , ( ) => {
7360 it ( 'should decode Vertex AI identifier with location' , ( ) => {
7461 const encoded = `${ AI_TYPE } /vertexai/europe-west1` ;
75- const expected : InstanceIdentifier = {
76- backendType : BackendType . VERTEX_AI ,
77- location : 'europe-west1'
78- } ;
79- expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( expected ) ;
62+ const backend = new VertexAIBackend ( 'europe-west1' ) ;
63+ expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( backend ) ;
8064 } ) ;
8165
8266 it ( 'should throw an error if Vertex AI identifier string without explicit location part' , ( ) => {
@@ -98,10 +82,8 @@ describe('Identifier Encoding/Decoding', () => {
9882
9983 it ( 'should decode Google AI identifier' , ( ) => {
10084 const encoded = `${ AI_TYPE } /googleai` ;
101- const expected : InstanceIdentifier = {
102- backendType : BackendType . GOOGLE_AI
103- } ;
104- expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( expected ) ;
85+ const backend = new GoogleAIBackend ( ) ;
86+ expect ( decodeInstanceIdentifier ( encoded ) ) . to . deep . equal ( backend ) ;
10587 } ) ;
10688
10789 it ( 'should throw AIError for invalid backend string' , ( ) => {
0 commit comments