Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
LINAGORA
L
LGS
Labs
hublot
Commits
7d43c24a
Commit
7d43c24a
authored
Nov 09, 2017
by
samy
Browse files
refactor store function from Archive
parent
19dd8d3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
13 deletions
+75
-13
client/lib/archive.js
client/lib/archive.js
+13
-3
client/lib/archive.test.js
client/lib/archive.test.js
+62
-10
No files found.
client/lib/archive.js
View file @
7d43c24a
...
...
@@ -22,17 +22,27 @@
/* global robotLib:true XMLHttpRequest */
/* exported robotController */
function
checkTranscript
(
user
,
text
,
keywords
)
{
return
((
user
===
undefined
||
user
.
constructor
!==
Array
)
||
text
===
undefined
||
(
keywords
===
undefined
||
keywords
.
constructor
!==
Array
));
}
robotLib
.
archive
=
function
(
config
)
{
return
{
store
(
transcript
)
{
if
(
t
ranscript
===
undefined
)
{
store
(
user
,
text
,
keywords
)
{
if
(
checkT
ranscript
(
user
,
text
,
keywords
)
)
{
return
false
;
}
const
xhttp
=
new
XMLHttpRequest
();
xhttp
.
open
(
'
POST
'
,
config
.
archive
);
xhttp
.
setRequestHeader
(
'
Content-Type
'
,
'
application/json
'
);
const
transcript
=
{
text
,
keywords
,
users
:
user
};
xhttp
.
send
(
JSON
.
stringify
(
transcript
));
return
true
;
return
xhttp
.
status
===
200
;
}
};
};
client/lib/archive.test.js
View file @
7d43c24a
...
...
@@ -29,11 +29,24 @@ const config = {
let
xhr
;
let
request
;
describe
(
'
client/lib/archive
'
,
()
=>
{
let
user
;
let
text
;
let
keywords
;
describe
(
'
client/lib/archive when status server is valide
'
,
()
=>
{
beforeEach
(()
=>
{
request
=
[];
user
=
[
'
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,19 +66,58 @@ 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
(
user
,
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 describe the expected behavior when user is undefined
'
,
()
=>
{
user
=
undefined
;
const
result
=
global
.
archive
.
store
(
user
,
text
,
keywords
);
expect
(
result
).
toBe
(
false
);
expect
(
request
[
0
]).
toBe
(
undefined
);
});
it
(
'
should describe the expected behavior when text is undefined
'
,
()
=>
{
text
=
undefined
;
const
result
=
global
.
archive
.
store
(
user
,
text
,
keywords
);
expect
(
result
).
toBe
(
false
);
expect
(
request
[
0
]).
toBe
(
undefined
);
});
it
(
'
should describe the expected behavior when keywords are undefined
'
,
()
=>
{
keywords
=
undefined
;
const
result
=
global
.
archive
.
store
(
user
,
text
,
keywords
);
expect
(
result
).
toBe
(
false
);
expect
(
request
[
0
]).
toBe
(
undefined
);
});
it
(
'
should describe the expected behavior when keywords is not an Array
'
,
()
=>
{
keywords
=
'
invalidFormat
'
;
const
result
=
global
.
archive
.
store
(
user
,
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
);
expect
(
result
).
toBe
(
false
);
expect
(
request
[
0
]).
toBe
(
undefined
);
});
it
(
'
should not make a REST call on store when status value is invalid
'
,
()
=>
{
xhr
=
sinon
.
useFakeXMLHttpRequest
();
xhr
.
onCreate
=
function
(
req
)
{
req
.
status
=
500
;
};
const
result
=
global
.
archive
.
store
(
user
,
text
,
keywords
);
expect
(
result
).
toBe
(
false
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment