Commit 266bfe3e authored by samy's avatar samy
Browse files

Implement archive tests

parent a0b9d8c0
......@@ -20,9 +20,24 @@
'use strict';
describe('client/lib/stt', () => {
const robotLib = {};
const XMLHttpRequestMock = {
open: jest.fn().mockImplementation(() => ({})),
setRequestHeader: () => {},
send: jest.fn().mockImplementation(() => {
return {};
})
};
const XMLHttpRequest = function () {
return XMLHttpRequestMock;
};
const config = {
archive: 'http://172.17.42.1:8080/api'
};
describe('client/lib/archive', () => {
beforeEach(() => {
global.robotLib = {};
global.robotLib = robotLib;
global.XMLHttpRequest = XMLHttpRequest;
/* eslint-disable import/no-unassigned-import */
require('./archive.js');
......@@ -32,4 +47,29 @@ describe('client/lib/stt', () => {
test('should define robotLib.archive', () => {
expect(global.robotLib.archive).toBeDefined();
});
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');
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);
expect(XMLHttpRequestMock.send).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