Skip to content

Commit 6ae734e

Browse files
russellwheatleymikehardy
authored andcommitted
test(ai): getMockResponse()
1 parent 5c54600 commit 6ae734e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/ai/__tests__/test-utils/mock-response.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export function getMockResponseStreaming(
4646
const fullText = mocksLookup[filename];
4747

4848
return {
49-
5049
// Really tangled typescript error here from our transitive dependencies.
5150
// Ignoring it now, but uncomment and run `yarn lerna:prepare` in top-level
5251
// of the repo to see if you get it or if it has gone away.
@@ -60,10 +59,17 @@ export function getMockResponseStreaming(
6059
};
6160
}
6261

63-
export function getMockResponse(filename: string): Partial<Response> {
64-
const fullText = mocksLookup[filename];
62+
type BackendName = 'vertexai' | 'googleai';
63+
export function getMockResponse(backendName: BackendName, filename: string): Partial<Response> {
64+
// @ts-ignore
65+
const backendMocksLookup: Record<string, string> = mocksLookup[backendName];
66+
if (!(filename in backendMocksLookup)) {
67+
throw Error(`${backendName} mock response file '${filename}' not found.`);
68+
}
69+
const fullText = backendMocksLookup[filename] as string;
70+
6571
return {
6672
ok: true,
67-
json: () => Promise.resolve(JSON.parse(fullText!)),
73+
json: () => Promise.resolve(JSON.parse(fullText)),
6874
};
6975
}

0 commit comments

Comments
 (0)