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
7beb48d1
Commit
7beb48d1
authored
Oct 27, 2017
by
samy
Browse files
Add sinon framework
parent
22b45ff3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
28 deletions
+44
-28
client/lib/archive.test.js
client/lib/archive.test.js
+30
-27
package.json
package.json
+2
-1
yarn.lock
yarn.lock
+12
-0
No files found.
client/lib/archive.test.js
View file @
7beb48d1
...
...
@@ -20,29 +20,24 @@
'
use strict
'
;
const
robotLib
=
{};
const
xmlHttpRequestMockFactory
=
()
=>
({
open
:
jest
.
fn
().
mockImplementation
(()
=>
({})),
setRequestHeader
:
()
=>
{},
send
:
jest
.
fn
().
mockImplementation
(()
=>
{
return
{};
})
});
const
sinon
=
require
(
'
sinon
'
);
const
robotLib
=
{};
const
config
=
{
archive
:
'
http://openpaasstore.test
'
archive
:
'
http://openpaasstore.test
/summary
'
};
let
XMLHttpRequestMock
;
let
xhr
;
let
request
;
describe
(
'
client/lib/archive
'
,
()
=>
{
beforeEach
(()
=>
{
XMLHttpRequestMock
=
xmlHttpRequestMockFactory
();
request
=
[];
xhr
=
sinon
.
useFakeXMLHttpRequest
();
xhr
.
onCreate
=
function
(
req
)
{
request
.
push
(
req
);
};
global
.
robotLib
=
robotLib
;
global
.
XMLHttpRequest
=
function
()
{
return
XMLHttpRequestMock
;
};
/* eslint-disable import/no-unassigned-import */
require
(
'
./archive.js
'
);
...
...
@@ -50,26 +45,34 @@ describe('client/lib/archive', () => {
global
.
archive
=
global
.
robotLib
.
archive
(
config
);
});
test
(
'
should define robotLib.archive
'
,
()
=>
{
afterEach
(()
=>
{
xhr
.
restore
();
});
it
(
'
should define robotLib.archive
'
,
()
=>
{
expect
(
global
.
robotLib
.
archive
).
toBeDefined
();
});
tes
t
(
'
should make
correc
t REST
call on store
'
,
()
=>
{
const
transcript
=
{}
;
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
open
).
toHaveBeenCalledWith
(
'
POST
'
,
config
.
archive
);
expect
(
XMLHttpRequestMock
.
send
).
toHaveBeenCalled
();
i
t
(
'
should make
ini
t REST
request
'
,
()
=>
{
const
transcript
=
'
transcript_test
'
;
const
result
=
global
.
archive
.
store
(
transcript
);
expect
(
result
).
toBeTruthy
(
);
expect
(
request
[
0
]).
not
.
toBeNull
();
});
tes
t
(
'
should make
a
REST call
with valid transcript
'
,
()
=>
{
const
transcript
=
{}
;
i
t
(
'
should make
correct
REST call
on store
'
,
()
=>
{
const
transcript
=
'
transcript_test
'
;
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
send
).
toHaveBeenCalledWith
(
JSON
.
stringify
(
transcript
));
console
.
log
(
request
[
0
]);
expect
(
request
[
0
].
method
).
toBe
(
'
POST
'
);
expect
(
request
[
0
].
url
).
toBe
(
config
.
archive
);
expect
(
request
[
0
].
requestBody
).
toBe
(
JSON
.
stringify
(
transcript
));
});
tes
t
(
'
should not make a REST call without transcript
'
,
()
=>
{
i
t
(
'
should not make a REST call
on store
without transcript
'
,
()
=>
{
const
transcript
=
undefined
;
global
.
archive
.
store
(
transcript
);
expect
(
XMLHttpRequestMock
.
send
).
not
.
toHaveBeenCalled
();
const
result
=
global
.
archive
.
store
(
transcript
);
expect
(
result
).
toBeFalsy
();
expect
(
request
[
0
]).
toBe
(
undefined
);
});
});
package.json
View file @
7beb48d1
...
...
@@ -18,7 +18,8 @@
},
"devDependencies"
:
{
"jest"
:
"20.0.0"
,
"
xo
"
:
"
0.18.2
"
"xo"
:
"0.18.2"
,
"sinon"
:
"^4.0.2"
,
},
"author"
:
"Linagora Folks"
,
"license"
:
"AGPL-3.0"
,
...
...
yarn.lock
View file @
7beb48d1
...
...
@@ -3155,6 +3155,18 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
sinon@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-4.0.2.tgz#c81f62456d37986c84e9f522ddb9ce413bda49d2"
dependencies:
diff "^3.1.0"
formatio "1.2.0"
lodash.get "^4.4.2"
lolex "^2.1.3"
nise "^1.2.0"
supports-color "^4.4.0"
type-detect "^4.0.0"
slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
...
...
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