import { EventEmitter } from "events"; jest.mock("../src/api/api", () => ({ authService: jest.fn(), })); import { SofyaTranscriber } from "../src/services/transcription/SofyaTranscriber"; import { TranscriptionServiceFactory } from "../src/services/transcription/TranscriptionServiceFactory"; import { flushMicrotasks } from "./helpers/testUtils"; class MockBatchTranscriptionService extends EventEmitter { public readonly startTranscription = jest.fn(); public readonly pauseTranscription = jest.fn(); public readonly resumeTranscription = jest.fn(); public readonly stopTranscription = jest.fn(async () => ({ transcript: "batch final", })); public readonly getResilienceStatus = jest.fn(() => null); public readonly getTelemetrySnapshot = jest.fn(() => null); public readonly getTelemetryRows = jest.fn(() => []); public readonly clearTelemetryRows = jest.fn(); public readonly resetTelemetry = jest.fn(); } describe("SofyaTranscriber batch mode", () => { afterEach(() => { jest.restoreAllMocks(); }); it("forwards mode=batch into the factory and returns the batch payload on stop", async () => { const service = new MockBatchTranscriptionService(); const createSpy = jest .spyOn(TranscriptionServiceFactory, "create") .mockResolvedValue(service as any); const transcriber = new SofyaTranscriber({ provider: "sofya_as_service", mode: "batch", endpoint: "https://scribe.sofya.health/api/transcriber", config: { language: "en-US", batch: { parseResponse: async () => ({ transcript: "batch final" }), }, }, } as any); await flushMicrotasks(); transcriber.startTranscription({} as MediaStream); const result = await transcriber.stopTranscription(); expect(createSpy).toHaveBeenCalledWith( "sofya_as_service", expect.objectContaining({ mode: "batch", endpoint: { endpoint: "https://scribe.sofya.health/api/transcriber", }, }) ); expect(service.startTranscription).toHaveBeenCalled(); expect(result).toEqual({ transcript: "batch final" }); }); });