Commit 2a28a04e authored by samy's avatar samy

fix PR comments

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