Commit 379ddb2c authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

refactor test

parent 86eded55
Pipeline #4001 passed with stage
in 44 seconds
......@@ -38,7 +38,7 @@ const sttMock = {
}
};
describe('client/robot', () => {
describe('client/robot without init', () => {
beforeEach(() => {
global.MediaRecorder = function (stream) {
const res = {
......@@ -61,15 +61,6 @@ describe('client/robot', () => {
};
global.MediaRecorder.instances = {};
global._setIntervalCalls = [];
global.setInterval = function (f, timeout) {
global._setIntervalCalls.push([f, timeout]);
};
global.isDisconnected = false;
global.isReconnected = false;
global.robotController = {
external: {
load: () => {}
......@@ -91,15 +82,6 @@ describe('client/robot', () => {
})
};
global.robotLib = {
stt: () => sttMock,
reco: () => ({
start: () => {},
getOnlineReco: () => new Promise(() => {}, () => {})
}),
archive: () => ({})
};
/* eslint-disable import/no-unassigned-import */
require('./robot.js');
/* eslint-enable */
......@@ -109,12 +91,6 @@ describe('client/robot', () => {
expect(global.robot).toBeDefined();
});
test('should set a interval for disconnection', () => {
global.robot.start();
global.robot.onConnection();
expect.arrayContaining([[global.robot.checkDisconnect, 300000]]);
});
test('should return a started mediaRecorder on `processAudio`', () => {
const res = global.robot.processAudio({
type: 'stream'
......@@ -138,19 +114,87 @@ describe('client/robot', () => {
mediaRecorder.ondataavailable('somedata');
expect(callbackCalled).toBe('somedata');
});
});
test('should not record itself', () => {
describe('client/robot', () => {
beforeEach(() => {
global.MediaRecorder = function (stream) {
const res = {
type: 'mediaRecorder',
stream,
started: false,
stopped: false,
interval: null,
start(interval) {
this.started = true;
this.interval = interval;
},
stop() {
this.started = false;
this.stopped = true;
}
};
global.MediaRecorder.instances[stream.id] = res;
return res;
};
global.MediaRecorder.instances = {};
global._setIntervalCalls = [];
global.setInterval = function (f, timeout) {
global._setIntervalCalls.push([f, timeout]);
};
global.isDisconnected = false;
global.isReconnected = false;
global.robotController = {
external: {
load: () => {}
},
getMyId: () => 'robotId',
getRemoteParticipants: () => [
'someid0',
'someid1',
'someid2'
],
getRemoteStream: id => ({type: 'RemoteStream', id}),
disconnect: () => {
global.isDisconnected = true;
},
getWebRTCAdapter: () => ({
addDisconnectCallback: () => {
global.isReconnected = true;
}
})
};
global.robotLib = {
stt: () => sttMock,
reco: () => ({
start: () => {},
getOnlineReco: () => new Promise(() => {}, () => {})
}),
archive: () => ({})
};
/* eslint-disable import/no-unassigned-import */
require('./robot.js');
global.robot.start();
global.robot.onConnection();
/* eslint-enable */
});
test('should set a interval for disconnection', () => {
expect.arrayContaining([[global.robot.checkDisconnect, 300000]]);
});
test('should not record itself', () => {
expect(global.MediaRecorder.instances)
.not.toHaveProperty(global.robotController.getMyId());
});
test('should start transcribing users already present on `start`', () => {
global.robot.start();
global.robot.onConnection();
const e1 = {data: 'somedata1'};
global.MediaRecorder.instances.someid1.ondataavailable(e1);
expect(sttMock.sttDataSent[0]).toBe(e1.data);
......@@ -161,9 +205,6 @@ describe('client/robot', () => {
});
test('should start transcribing stream on user connection after `start`', () => {
global.robot.start();
global.robot.onConnection();
global.robotController.onAttendeePush({}, {easyrtcid: 'testid'});
const e = {data: 'somedata'};
......@@ -173,17 +214,11 @@ describe('client/robot', () => {
});
test('should participant be on', () => {
global.robot.start();
global.robot.onConnection();
expect(global.robot.participantsMediaRecorders.someid1.stopped).toBe(false);
expect(global.robot.recordedParticipantsWS.someid1.status).toBe('open');
});
test('should stop transcribing stream on user disconnect', () => {
global.robot.start();
global.robot.onConnection();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.MediaRecorder.instances.someid1.stopped).toBeTruthy();
......@@ -191,26 +226,17 @@ describe('client/robot', () => {
});
test('should not disconnected with more than one user', () => {
global.robot.start();
global.robot.onConnection();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.isDisconnected).toBe(false);
});
test('should trigger when robot is disconnect', () => {
global.robot.start();
global.robot.onConnection();
global.robotController.getWebRTCAdapter().addDisconnectCallback();
expect(global.isReconnected).toBe(true);
});
test('should clear the connection', () => {
global.robot.start();
global.robot.onConnection();
global.robot.clearConnection();
expect(global.robot.participantsMediaRecorders.someid1.stopped).toBe(true);
expect(global.robot.recordedParticipantsWS.someid1.status).toBe('closed');
......@@ -222,17 +248,11 @@ describe('client/robot', () => {
return [];
};
global.robot.start();
global.robot.onConnection();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.isDisconnected).toBe(true);
});
test('should try to reopen a stt ws on error', () => {
global.robot.start();
global.robot.onConnection();
// Trigger an error
sttMock.wsMock.status = 'error';
sttMock.wsMock.onerror('error');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment