Skip to content

Commit 4ea4539

Browse files
committed
Add backwards compatibility tests
1 parent bd7bd2a commit 4ea4539

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { expect } from "chai";
2+
import { GenAIError, GenAIModel, GenerativeModel, VertexAIError, VertexAIErrorCode, VertexAIModel, getGenerativeModel, getImagenModel, vertexAIBackend } from "./api";
3+
import { GenAI, VertexAI, GenAIErrorCode } from "./public-types";
4+
5+
function assertAssignable<T, _U extends T>(): void {};
6+
7+
const fakeGenAI: GenAI = {
8+
app: {
9+
name: 'DEFAULT',
10+
automaticDataCollectionEnabled: true,
11+
options: {
12+
apiKey: 'key',
13+
projectId: 'my-project',
14+
appId: 'app-id'
15+
}
16+
},
17+
backend: vertexAIBackend('us-central1'),
18+
location: 'us-central1'
19+
};
20+
21+
const fakeVertexAI: VertexAI = fakeGenAI;
22+
23+
describe('backwards-compatible types', () => {
24+
it('GenAI is backwards compatible with VertexAI', () => {
25+
assertAssignable<VertexAI, GenAI>();
26+
});
27+
it('GenAIError is backwards compatible with VertexAIError', () => {
28+
assertAssignable<typeof VertexAIError, typeof GenAIError>();
29+
const err = new VertexAIError(VertexAIErrorCode.ERROR, "");
30+
expect(err).instanceOf(GenAIError);
31+
expect(err).instanceOf(VertexAIError);
32+
});
33+
it('GenAIErrorCode is backwards compatible with VertexAIErrorCode', () => {
34+
assertAssignable<VertexAIErrorCode, GenAIErrorCode>();
35+
const errCode = GenAIErrorCode.ERROR;
36+
expect(errCode).to.equal(VertexAIErrorCode.ERROR);
37+
});
38+
it('GenAIModel is backwards compatible with VertexAIModel', () => {
39+
assertAssignable<typeof VertexAIModel, typeof GenAIModel>();
40+
41+
const model = new GenerativeModel(fakeGenAI, { model: 'model-name' });
42+
expect(model).to.be.instanceOf(GenAIModel);
43+
expect(model).to.be.instanceOf(VertexAIModel);
44+
});
45+
});
46+
47+
describe('backward-compatible functions', () => {
48+
it ('getGenerativeModel', () => {
49+
const model = getGenerativeModel(fakeVertexAI, { model: 'model-name' });
50+
expect(model).to.be.instanceOf(GenAIModel);
51+
expect(model).to.be.instanceOf(VertexAIModel);
52+
});
53+
it ('getImagenModel', () => {
54+
const model = getImagenModel(fakeVertexAI, { model: 'model-name' });
55+
expect(model).to.be.instanceOf(GenAIModel);
56+
expect(model).to.be.instanceOf(VertexAIModel);
57+
});
58+
});

0 commit comments

Comments
 (0)