@@ -4,8 +4,12 @@ import { SapAiCoreHandler } from "../sapaicore.js"
44import type { ApiHandlerOptions } from "../../../shared/api.js"
55import axios from "axios"
66
7- vitest . mock ( "axios" )
8- const mockedAxios = vitest . mocked ( axios )
7+ vitest . mock ( "axios" , ( ) => ( {
8+ default : {
9+ post : vitest . fn ( ) ,
10+ get : vitest . fn ( ) ,
11+ } ,
12+ } ) )
913
1014// Create mock stream that implements async iteration
1115function createMockStream ( chunks : string [ ] ) {
@@ -66,7 +70,7 @@ describe("SAP AI Core Streaming", () => {
6670 ]
6771
6872 const mockStream = createMockStream ( streamChunks )
69- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
73+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
7074
7175 const messages = [ { role : "user" as const , content : "Say hello" } ]
7276 const responses = [ ]
@@ -125,7 +129,7 @@ describe("SAP AI Core Streaming", () => {
125129 ]
126130
127131 const mockStream = createMockStream ( streamChunks )
128- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
132+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
129133
130134 const messages = [ { role : "user" as const , content : "Say hello" } ]
131135 const responses = [ ]
@@ -182,7 +186,7 @@ describe("SAP AI Core Streaming", () => {
182186 }
183187
184188 // Mock both the stream and non-stream calls since o3-mini uses non-stream
185- mockedAxios . post
189+ vi . mocked ( axios . post )
186190 . mockResolvedValueOnce ( { data : createMockStream ( [ ] ) } ) // First call (stream)
187191 . mockResolvedValueOnce ( mockResponse ) // Second call (non-stream)
188192
@@ -228,7 +232,7 @@ describe("SAP AI Core Streaming", () => {
228232 ]
229233
230234 const mockStream = createMockStream ( streamChunks )
231- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
235+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
232236
233237 const messages = [ { role : "user" as const , content : "Say hello" } ]
234238 const responses = [ ]
@@ -263,7 +267,7 @@ describe("SAP AI Core Streaming", () => {
263267 ]
264268
265269 const mockStream = createMockStream ( streamChunks )
266- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
270+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
267271
268272 const messages = [ { role : "user" as const , content : "Say hello" } ]
269273 const responses = [ ]
@@ -312,7 +316,7 @@ describe("SAP AI Core Streaming", () => {
312316 ]
313317
314318 const mockStream = createMockStream ( streamChunks )
315- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
319+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
316320
317321 const messages = [ { role : "user" as const , content : "Say hello" } ]
318322 const responses = [ ]
@@ -348,7 +352,7 @@ describe("SAP AI Core Streaming", () => {
348352 ]
349353
350354 const mockStream = createMockStream ( streamChunks )
351- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
355+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
352356
353357 const messages = [ { role : "user" as const , content : "Say hello" } ]
354358 const responses = [ ]
@@ -377,7 +381,7 @@ describe("SAP AI Core Streaming", () => {
377381 ]
378382
379383 const mockStream = createMockStream ( streamChunks )
380- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
384+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
381385
382386 const consoleSpy = vitest . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
383387
@@ -405,7 +409,7 @@ describe("SAP AI Core Streaming", () => {
405409 } ,
406410 }
407411
408- mockedAxios . post . mockResolvedValueOnce ( { data : mockStream } )
412+ vi . mocked ( axios . post ) . mockResolvedValueOnce ( { data : mockStream } )
409413
410414 const messages = [ { role : "user" as const , content : "Say hello" } ]
411415
0 commit comments