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

Refactoring archive tests

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