Skip to content

Commit 93b5f3d

Browse files
committed
fix(tests): update RequestyHandler tests to properly handle Azure inference and streaming
1 parent c13cb2a commit 93b5f3d

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/api/providers/__tests__/requesty.test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,43 @@ describe("RequestyHandler", () => {
3838
// Clear mocks
3939
jest.clearAllMocks()
4040

41-
// Setup mock create function
42-
mockCreate = jest.fn()
41+
// Setup mock create function that preserves params
42+
let lastParams: any
43+
mockCreate = jest.fn().mockImplementation((params) => {
44+
lastParams = params
45+
return {
46+
[Symbol.asyncIterator]: async function* () {
47+
yield {
48+
choices: [{ delta: { content: "Hello" } }],
49+
}
50+
yield {
51+
choices: [{ delta: { content: " world" } }],
52+
usage: {
53+
prompt_tokens: 30,
54+
completion_tokens: 10,
55+
prompt_tokens_details: {
56+
cached_tokens: 15,
57+
caching_tokens: 5,
58+
},
59+
},
60+
}
61+
},
62+
}
63+
})
4364

4465
// Mock OpenAI constructor
4566
;(OpenAI as jest.MockedClass<typeof OpenAI>).mockImplementation(
4667
() =>
4768
({
4869
chat: {
4970
completions: {
50-
create: mockCreate,
71+
create: (params: any) => {
72+
// Store params for verification
73+
const result = mockCreate(params)
74+
// Make params available for test assertions
75+
;(result as any).params = params
76+
return result
77+
},
5178
},
5279
},
5380
}) as unknown as OpenAI,
@@ -122,7 +149,12 @@ describe("RequestyHandler", () => {
122149
},
123150
])
124151

125-
expect(mockCreate).toHaveBeenCalledWith({
152+
// Get the actual params that were passed
153+
const calls = mockCreate.mock.calls
154+
expect(calls.length).toBe(1)
155+
const actualParams = calls[0][0]
156+
157+
expect(actualParams).toEqual({
126158
model: defaultOptions.requestyModelId,
127159
temperature: 0,
128160
messages: [

0 commit comments

Comments
 (0)