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
Yoann HOUPERT
hublot
Commits
a5d3626c
Commit
a5d3626c
authored
Oct 24, 2017
by
Tom JORQUERA
Browse files
Merge branch 'hublot-sbenhamiche#33' into 'master'
Hublot sbenhamiche#33 Closes
#33
See merge request
!35
parents
e5bc8b81
31f2d370
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
8 deletions
+52
-8
client/lib/archive.js
client/lib/archive.js
+9
-5
client/lib/archive.test.js
client/lib/archive.test.js
+42
-2
config.json
config.json
+1
-1
No files found.
client/lib/archive.js
View file @
a5d3626c
...
...
@@ -21,14 +21,18 @@
'
use strict
'
;
/* global robotLib:true XMLHttpRequest */
/* exported robotController */
robotLib
.
archive
=
function
(
config
)
{
return
{
store
(
transcript
)
{
const
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
open
(
'
POST
'
,
config
.
archive
+
'
/json-handler
'
);
xmlhttp
.
setRequestHeader
(
'
Content-Type
'
,
'
application/json;charset=UTF-8
'
);
xmlhttp
.
send
(
JSON
.
stringify
(
transcript
));
if
(
transcript
===
undefined
)
{
return
false
;
}
const
xhttp
=
new
XMLHttpRequest
();
xhttp
.
open
(
'
POST
'
,
config
.
archive
);
xhttp
.
setRequestHeader
(
'
Content-Type
'
,
'
application/json
'
);
xhttp
.
send
(
JSON
.
stringify
(
transcript
));
return
true
;
}
};
};
client/lib/archive.test.js
View file @
a5d3626c
...
...
@@ -20,16 +20,56 @@
'
use strict
'
;
describe
(
'
client/lib/stt
'
,
()
=>
{
const
robotLib
=
{};
const
xmlHttpRequestMockFactory
=
()
=>
({
open
:
jest
.
fn
().
mockImplementation
(()
=>
({})),
setRequestHeader
:
()
=>
{},
send
:
jest
.
fn
().
mockImplementation
(()
=>
{
return
{};
})
});
const
config
=
{
archive
:
'
http://openpaasstore.test
'
};
let
XMLHttpRequestMock
;
describe
(
'
client/lib/archive
'
,
()
=>
{
beforeEach
(()
=>
{
global
.
robotLib
=
{};
XMLHttpRequestMock
=
xmlHttpRequestMockFactory
();
global
.
robotLib
=
robotLib
;
global
.
XMLHttpRequest
=
function
()
{
return
XMLHttpRequestMock
;
};
/* eslint-disable import/no-unassigned-import */
require
(
'
./archive.js
'
);
/* eslint-enable */
global
.
archive
=
global
.
robotLib
.
archive
(
config
);
});
test
(
'
should define robotLib.archive
'
,
()
=>
{
expect
(
global
.
robotLib
.
archive
).
toBeDefined
();
});
test
(
'
should make correct REST call on store
'
,
()
=>
{
const
transcript
=
{};
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
open
).
toHaveBeenCalledWith
(
'
POST
'
,
config
.
archive
);
expect
(
XMLHttpRequestMock
.
send
).
toHaveBeenCalled
();
});
test
(
'
should make a REST call with valid transcript
'
,
()
=>
{
const
transcript
=
{};
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
send
).
toHaveBeenCalledWith
(
JSON
.
stringify
(
transcript
));
});
test
(
'
should not make a REST call without transcript
'
,
()
=>
{
const
transcript
=
undefined
;
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
send
).
not
.
toHaveBeenCalled
();
});
});
config.json
View file @
a5d3626c
...
...
@@ -30,7 +30,7 @@
"https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js"
,
"https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"
],
"archive"
:
"http://localhost:8080/api"
,
"archive"
:
"http://localhost:8080/api
/summary
"
,
"reco"
:
{
"host"
:
"recommender"
,
"port"
:
8080
,
...
...
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