mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
test(server): add transcript e2e (#11557)
This commit is contained in:
@@ -19,6 +19,7 @@ import { MockEmbeddingClient } from '../plugins/copilot/context/embedding';
|
||||
import { prompts, PromptService } from '../plugins/copilot/prompt';
|
||||
import {
|
||||
CopilotProviderFactory,
|
||||
GeminiProvider,
|
||||
OpenAIProvider,
|
||||
} from '../plugins/copilot/providers';
|
||||
import { CopilotStorage } from '../plugins/copilot/storage';
|
||||
@@ -35,10 +36,12 @@ import {
|
||||
addContextDoc,
|
||||
addContextFile,
|
||||
array2sse,
|
||||
audioTranscription,
|
||||
chatWithImages,
|
||||
chatWithText,
|
||||
chatWithTextStream,
|
||||
chatWithWorkflow,
|
||||
claimAudioTranscription,
|
||||
cleanObject,
|
||||
createCopilotContext,
|
||||
createCopilotMessage,
|
||||
@@ -50,6 +53,7 @@ import {
|
||||
matchFiles,
|
||||
matchWorkspaceDocs,
|
||||
sse2array,
|
||||
submitAudioTranscription,
|
||||
textToEventStream,
|
||||
unsplashSearch,
|
||||
updateCopilotSession,
|
||||
@@ -96,6 +100,7 @@ test.before(async t => {
|
||||
},
|
||||
});
|
||||
m.overrideProvider(OpenAIProvider).useClass(MockCopilotProvider);
|
||||
m.overrideProvider(GeminiProvider).useClass(MockCopilotProvider);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -868,3 +873,44 @@ test('should be able to manage context', async t => {
|
||||
t.is(result[0].docId, docId, 'should match doc id');
|
||||
}
|
||||
});
|
||||
|
||||
test('should be able to transcript', async t => {
|
||||
const { app } = t.context;
|
||||
|
||||
const { id: workspaceId } = await createWorkspace(app);
|
||||
|
||||
Sinon.stub(app.get(GeminiProvider), 'generateText').resolves(
|
||||
'[{"a":"A","s":30,"e":45,"t":"Hello, everyone."},{"a":"B","s":46,"e":70,"t":"Hi, thank you for joining the meeting today."}]'
|
||||
);
|
||||
|
||||
const job = await submitAudioTranscription(
|
||||
app,
|
||||
workspaceId,
|
||||
'blobId',
|
||||
'test.mp3',
|
||||
Buffer.from([1, 1])
|
||||
);
|
||||
t.snapshot(
|
||||
cleanObject([job], ['id']),
|
||||
'should submit audio transcription job'
|
||||
);
|
||||
t.truthy(job.id, 'should have job id');
|
||||
|
||||
// wait for processing
|
||||
{
|
||||
let { status } = (await audioTranscription(app, workspaceId, job.id)) || {};
|
||||
|
||||
while (status !== 'finished') {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
({ status } = (await audioTranscription(app, workspaceId, job.id)) || {});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const result = await claimAudioTranscription(app, job.id);
|
||||
t.snapshot(
|
||||
cleanObject([result], ['id']),
|
||||
'should claim audio transcription job'
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user