Skip to content

Commit d60f09a

Browse files
author
Guiners
committed
adding mock to live-conversation-audio-with-audio
1 parent 1be8530 commit d60f09a

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

genai/test/live-conversation-audio-with-audio.test.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,69 @@
1616

1717
const {assert} = require('chai');
1818
const {describe, it} = require('mocha');
19+
const sinon = require('sinon');
1920

2021
const projectId = process.env.CAIP_PROJECT_ID;
21-
const sample = require('../live/live-conversation-audio-with-audio');
2222
const {delay} = require('./util');
23+
const proxyquire = require('proxyquire');
2324

2425
describe('live-conversation-audio-with-audio', () => {
2526
it('should generate content in a live session conversation from a text prompt', async function () {
27+
const mockClient = {
28+
live: {
29+
connect: async (opts = {}) => {
30+
setImmediate(() =>
31+
opts.callbacks.onmessage({
32+
serverContent: {
33+
inputTranscription: 'Hello Gemini',
34+
outputTranscription: 'Hi Mocked Gemini there!',
35+
modelTurn: {
36+
parts: [
37+
{
38+
inlineData: {
39+
data: Buffer.from('fake audio data').toString('base64'),
40+
},
41+
},
42+
],
43+
},
44+
turnComplete: false,
45+
},
46+
})
47+
);
48+
49+
setImmediate(() =>
50+
opts.callbacks.onmessage({
51+
serverContent: {
52+
modelTurn: {parts: []},
53+
turnComplete: true,
54+
},
55+
})
56+
);
57+
58+
return {
59+
sendRealtimeInput: async () => {},
60+
close: async () => {},
61+
};
62+
},
63+
},
64+
};
65+
66+
const sample = proxyquire('../live/live-conversation-audio-with-audio', {
67+
'@google/genai': {
68+
GoogleGenAI: function () {
69+
return mockClient;
70+
},
71+
Modality: {AUDIO: 'AUDIO'},
72+
},
73+
fs: {
74+
readFileSync: sinon.stub().returns(Buffer.alloc(100, 0)),
75+
writeFileSync: sinon.stub().returns(),
76+
},
77+
path: {
78+
join: (...args) => args.join('/'),
79+
},
80+
});
81+
2682
this.timeout(180000);
2783
this.retries(4);
2884
await delay(this.test);

0 commit comments

Comments
 (0)