Commit 2b9e4324 authored by Tom JORQUERA's avatar Tom JORQUERA

Merge branch '54-Refactor-libArchive-API-clean' into 'master'

54-Refactor-libArchive-API-clean

Closes #54

See merge request !45
parents 19dd8d3b 2a28a04e
Pipeline #5147 passed with stage
in 40 seconds
......@@ -22,15 +22,25 @@
/* global robotLib:true XMLHttpRequest */
/* exported robotController */
function isValidTranscript(users, text, keywords) {
return !((users === undefined || users.constructor !== Array) || text === undefined || (keywords === undefined || keywords.constructor !== Array));
}
robotLib.archive = function (config) {
return {
store(transcript) {
if (transcript === undefined) {
store(users, text, keywords) {
if (!isValidTranscript(users, text, keywords)) {
return false;
}
const xhttp = new XMLHttpRequest();
xhttp.open('POST', config.archive);
xhttp.setRequestHeader('Content-Type', 'application/json');
const transcript = {
text,
keywords,
users
};
xhttp.send(JSON.stringify(transcript));
return true;
}
......
......@@ -29,11 +29,24 @@ const config = {
let xhr;
let request;
describe('client/lib/archive', () => {
let users;
let text;
let keywords;
describe('client/lib/archive when status server is valide', () => {
beforeEach(() => {
request = [];
users = ['userTest@open-paas.org'];
text = 'Transcription Text';
keywords = [{
key: 'keyTest',
value: 'testValue'
}];
xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function (req) {
req.status = 200;
request.push(req);
};
......@@ -53,18 +66,48 @@ describe('client/lib/archive', () => {
expect(global.robotLib.archive).toBeDefined();
});
it('should make correct REST call on store', () => {
const transcript = 'transcript_test';
const result = global.archive.store(transcript);
it('should make a correct REST call', () => {
const result = global.archive.store(users, text, keywords);
expect(result).toBe(true);
expect(request[0].method).toBe('POST');
expect(request[0].url).toBe(config.archive);
expect(request[0].requestBody).toBe(JSON.stringify(transcript));
});
it('should not make a REST call on store without transcript', () => {
const transcript = undefined;
const result = global.archive.store(transcript);
it('should not make a REST call on store without parameters', () => {
const result = global.archive.store();
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
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 not make a REST call on store text is undefined', () => {
text = undefined;
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 keywords are undefined', () => {
keywords = undefined;
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 keywords is not an Array', () => {
keywords = 'invalidFormat';
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 users is not an Array', () => {
users = '';
const result = global.archive.store(users, text, keywords);
expect(result).toBe(false);
expect(request[0]).toBe(undefined);
});
......
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