Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
hublot
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yoann HOUPERT
hublot
Commits
7d43c24a
Commit
7d43c24a
authored
Nov 09, 2017
by
samy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
(
transcript
===
undefined
)
{
store
(
user
,
text
,
keywords
)
{
if
(
checkTranscript
(
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