Commit 144ac4d2 authored by samy's avatar samy
Browse files

Refactoring archive tests

parent 266bfe3e
......@@ -28,7 +28,6 @@ robotLib.archive = function (config) {
const OpenPaasStore = config.archive;
const xhttp = new XMLHttpRequest();
if (transcript === undefined) {
console.log('there is no transcription yet!');
return false;
}
xhttp.open('POST', OpenPaasStore + '/summary');
......
......@@ -28,20 +28,22 @@ const XMLHttpRequestMock = {
return {};
})
};
const XMLHttpRequest = function () {
return XMLHttpRequestMock;
};
const config = {
archive: 'http://172.17.42.1:8080/api'
};
describe('client/lib/archive', () => {
beforeEach(() => {
global.robotLib = robotLib;
global.XMLHttpRequest = XMLHttpRequest;
global.XMLHttpRequest = function () {
return XMLHttpRequestMock;
};
/* eslint-disable import/no-unassigned-import */
require('./archive.js');
/* eslint-enable */
global.archive = global.robotLib.archive(config);
});
test('should define robotLib.archive', () => {
......@@ -49,27 +51,21 @@ describe('client/lib/archive', () => {
});
test('should make correct REST call on store', () => {
const transcript = 'transcriptTest';
const OpenPaasStoreTest = config.archive;
const archive = global.robotLib.archive(config);
archive.store(transcript);
expect(XMLHttpRequestMock.open).toHaveBeenCalledWith('POST', OpenPaasStoreTest + '/summary');
const transcript = {};
global.archive.store(transcript);
expect(XMLHttpRequestMock.open).toHaveBeenCalledWith('POST', config.archive + '/summary');
expect(XMLHttpRequestMock.send).toHaveBeenCalled();
});
test('should store a correct transcript segment', () => {
const archive = global.robotLib.archive(config);
const transcript = {
users: [
'testUser'
],
text: 'test summary text',
keywords: [{
key: 'testKey',
value: '800'
}]
};
archive.store(transcript);
test('should make a REST call with valid transcript', () => {
const transcript = {};
global.archive.store(transcript);
expect(XMLHttpRequestMock.send).toHaveBeenCalledWith(JSON.stringify(transcript));
});
test('should not make a REST call without transcript', () => {
const transcript = undefined;
global.archive.store(transcript);
expect(XMLHttpRequestMock.send).not.toHaveBeenCalledWith(JSON.stringify(transcript));
});
});
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