Skip to content

Commit 0f8b8b2

Browse files
test(ai): mock-response update for new mocks
1 parent be07881 commit 0f8b8b2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
import { ReadableStream } from 'web-streams-polyfill';
1818
import { mocksLookup } from './mocks-lookup';
1919

20+
export enum BackendName {
21+
VertexAI = 'vertexai',
22+
GoogleAI = 'googleai',
23+
}
24+
2025
/**
2126
* Mock native Response.body
2227
* Streams contents of json file in 20 character chunks
@@ -40,10 +45,16 @@ export function getChunkedStream(input: string, chunkLength = 20): ReadableStrea
4045
return stream;
4146
}
4247
export function getMockResponseStreaming(
48+
backendName: BackendName,
4349
filename: string,
4450
chunkLength: number = 20,
4551
): Partial<Response> {
46-
const fullText = mocksLookup[filename];
52+
// @ts-ignore
53+
const backendMocksLookup: Record<string, string> = mocksLookup[backendName];
54+
if (!backendMocksLookup[filename]) {
55+
throw Error(`${backendName} mock response file '${filename}' not found.`);
56+
}
57+
const fullText = backendMocksLookup[filename] as string;
4758

4859
return {
4960
// Really tangled typescript error here from our transitive dependencies.
@@ -59,11 +70,10 @@ export function getMockResponseStreaming(
5970
};
6071
}
6172

62-
type BackendName = 'vertexai' | 'googleai';
6373
export function getMockResponse(backendName: BackendName, filename: string): Partial<Response> {
6474
// @ts-ignore
6575
const backendMocksLookup: Record<string, string> = mocksLookup[backendName];
66-
if (!(filename in backendMocksLookup)) {
76+
if (!backendMocksLookup[filename]) {
6777
throw Error(`${backendName} mock response file '${filename}' not found.`);
6878
}
6979
const fullText = backendMocksLookup[filename] as string;

0 commit comments

Comments
 (0)