Commit 31f2d370 authored by samy's avatar samy
Browse files

Fix PR comments

parent 144ac4d2
Pipeline #4188 passed with stage
in 40 seconds
...@@ -20,17 +20,16 @@ ...@@ -20,17 +20,16 @@
'use strict'; 'use strict';
/* global robotLib:true require XMLHttpRequest */ /* global robotLib:true XMLHttpRequest */
/* exported robotController */ /* exported robotController */
robotLib.archive = function (config) { robotLib.archive = function (config) {
return { return {
store(transcript) { store(transcript) {
const OpenPaasStore = config.archive;
const xhttp = new XMLHttpRequest();
if (transcript === undefined) { if (transcript === undefined) {
return false; return false;
} }
xhttp.open('POST', OpenPaasStore + '/summary'); const xhttp = new XMLHttpRequest();
xhttp.open('POST', config.archive);
xhttp.setRequestHeader('Content-Type', 'application/json'); xhttp.setRequestHeader('Content-Type', 'application/json');
xhttp.send(JSON.stringify(transcript)); xhttp.send(JSON.stringify(transcript));
return true; return true;
......
...@@ -21,20 +21,24 @@ ...@@ -21,20 +21,24 @@
'use strict'; 'use strict';
const robotLib = {}; const robotLib = {};
const XMLHttpRequestMock = { const xmlHttpRequestMockFactory = () => ({
open: jest.fn().mockImplementation(() => ({})), open: jest.fn().mockImplementation(() => ({})),
setRequestHeader: () => {}, setRequestHeader: () => {},
send: jest.fn().mockImplementation(() => { send: jest.fn().mockImplementation(() => {
return {}; return {};
}) })
}; });
const config = { const config = {
archive: 'http://172.17.42.1:8080/api' archive: 'http://openpaasstore.test'
}; };
let XMLHttpRequestMock;
describe('client/lib/archive', () => { describe('client/lib/archive', () => {
beforeEach(() => { beforeEach(() => {
XMLHttpRequestMock = xmlHttpRequestMockFactory();
global.robotLib = robotLib; global.robotLib = robotLib;
global.XMLHttpRequest = function () { global.XMLHttpRequest = function () {
return XMLHttpRequestMock; return XMLHttpRequestMock;
...@@ -53,7 +57,7 @@ describe('client/lib/archive', () => { ...@@ -53,7 +57,7 @@ describe('client/lib/archive', () => {
test('should make correct REST call on store', () => { test('should make correct REST call on store', () => {
const transcript = {}; const transcript = {};
global.archive.store(transcript); global.archive.store(transcript);
expect(XMLHttpRequestMock.open).toHaveBeenCalledWith('POST', config.archive + '/summary'); expect(XMLHttpRequestMock.open).toHaveBeenCalledWith('POST', config.archive);
expect(XMLHttpRequestMock.send).toHaveBeenCalled(); expect(XMLHttpRequestMock.send).toHaveBeenCalled();
}); });
...@@ -66,6 +70,6 @@ describe('client/lib/archive', () => { ...@@ -66,6 +70,6 @@ describe('client/lib/archive', () => {
test('should not make a REST call without transcript', () => { test('should not make a REST call without transcript', () => {
const transcript = undefined; const transcript = undefined;
global.archive.store(transcript); global.archive.store(transcript);
expect(XMLHttpRequestMock.send).not.toHaveBeenCalledWith(JSON.stringify(transcript)); expect(XMLHttpRequestMock.send).not.toHaveBeenCalled();
}); });
}); });
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
"https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js", "https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js" "https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"
], ],
"archive": "http://localhost:8080/api", "archive": "http://localhost:8080/api/summary",
"reco": { "reco": {
"host": "recommender", "host": "recommender",
"port": 8080, "port": 8080,
......
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