Commit 2a28a04e authored by samy's avatar samy

fix PR comments

parent 2e27ff4f
Pipeline #5139 passed with stage
in 46 seconds
......@@ -23,13 +23,13 @@
/* global robotLib:true XMLHttpRequest */
/* exported robotController */
function checkTranscript(user, text, keywords) {
return ((user === undefined || user.constructor !== Array) || text === undefined || (keywords === undefined || keywords.constructor !== Array));
function isValidTranscript(users, text, keywords) {
return !((users === undefined || users.constructor !== Array) || text === undefined || (keywords === undefined || keywords.constructor !== Array));
}
robotLib.archive = function (config) {
return {
store(user, text, keywords) {
if (checkTranscript(user, text, keywords)) {
store(users, text, keywords) {
if (!isValidTranscript(users, text, keywords)) {
return false;
}
......@@ -39,10 +39,10 @@ robotLib.archive = function (config) {
const transcript = {
text,
keywords,
users: user
users
};
xhttp.send(JSON.stringify(transcript));
return xhttp.status === 200;
return true;
}
};
};
......@@ -30,14 +30,14 @@ const config = {
let xhr;
let request;
let user;
let users;
let text;
let keywords;
describe('client/lib/archive when status server is valide', () => {
beforeEach(() => {
request = [];
user = ['userTest@open-paas.org'];
users = ['userTest@open-paas.org'];
text = 'Transcription Text';
keywords = [{
key: 'keyTest',
......@@ -67,7 +67,7 @@ describe('client/lib/archive when status server is valide', () => {
});
it('should make a correct REST call', () => {
const result = global.archive.store(user, text, keywords);
const result = global.archive.store(users, text, keywords);
expect(result).toBe(true);
});
......@@ -77,47 +77,38 @@ describe('client/lib/archive when status server is valide', () => {
expect(request[0]).toBe(undefined);
});
it('should describe the expected behavior when user is undefined', () => {
user = undefined;
const result = global.archive.store(user, text, keywords);
it('should not make a REST call on store users is undefined', () => {
users = undefined;
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
it('should describe the expected behavior when text is undefined', () => {
it('should not make a REST call on store text is undefined', () => {
text = undefined;
const result = global.archive.store(user, text, keywords);
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
it('should describe the expected behavior when keywords are undefined', () => {
it('should not make a REST call on store when keywords are undefined', () => {
keywords = undefined;
const result = global.archive.store(user, text, keywords);
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
it('should describe the expected behavior when keywords is not an Array', () => {
it('should not make a REST call on store when keywords is not an Array', () => {
keywords = 'invalidFormat';
const result = global.archive.store(user, text, keywords);
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
it('should describe the expected behavior when user value is not an Array', () => {
user = '';
const result = global.archive.store(user, text, keywords);
it('should not make a REST call on store when users is not an Array', () => {
users = '';
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
it('should not make a REST call on store when the webservice fail', () => {
xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function (req) {
req.status = 500;
};
const result = global.archive.store(user, text, keywords);
expect(result).toBe(false);
});
});
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