Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Challonge
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Challonge
Commits
b38dd073
Commit
b38dd073
authored
Mar 14, 2017
by
Aaron Tidwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add request callback tests
parent
50b87b68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
6 deletions
+100
-6
lib/api/client.spec.js
lib/api/client.spec.js
+88
-0
spec/helpers/index.js
spec/helpers/index.js
+12
-6
No files found.
lib/api/client.spec.js
View file @
b38dd073
const
qs
=
require
(
'
querystring
'
);
const
Client
=
require
(
'
./client
'
).
Client
;
const
errorHandler
=
require
(
'
./error-handler
'
);
const
httpsMock
=
require
(
'
https
'
);
//replaced with mock by mockery
function
parseOpts
()
{
...
...
@@ -7,6 +10,9 @@ function parseOpts() {
}
describe
(
'
Client Class
'
,
()
=>
{
beforeEach
(()
=>
{
httpsMock
.
reset
();
});
describe
(
'
constructor
'
,
()
=>
{
it
(
'
should set options to the object that is passed
'
,
()
=>
{
const
opts
=
{};
...
...
@@ -195,5 +201,87 @@ describe('Client Class', () => {
}
});
});
it
(
'
should call the error handler on anything but a 200 response
'
,
()
=>
{
spyOn
(
errorHandler
,
'
handle
'
);
client
.
makeRequest
({});
httpsMock
.
res
.
statusCode
=
500
;
httpsMock
.
listeners
.
end
[
0
]();
expect
(
errorHandler
.
handle
).
toHaveBeenCalled
();
});
it
(
'
should call the callback on a 200 response
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
();
client
.
makeRequest
({
callback
:
spy
});
httpsMock
.
res
.
statusCode
=
200
;
httpsMock
.
listeners
.
data
[
0
](
'
{}
'
);
httpsMock
.
listeners
.
end
[
0
]();
expect
(
spy
).
toHaveBeenCalled
();
});
it
(
'
should parse the response as json
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
();
client
.
makeRequest
({
callback
:
spy
});
httpsMock
.
res
.
statusCode
=
200
;
httpsMock
.
listeners
.
data
[
0
](
'
{}
'
);
httpsMock
.
listeners
.
end
[
0
]();
expect
(
spy
).
toHaveBeenCalledWith
(
null
,
{});
});
it
(
'
should convert _ to camelCase if set
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
();
client
.
makeRequest
({
callback
:
spy
});
httpsMock
.
res
.
statusCode
=
200
;
httpsMock
.
listeners
.
data
[
0
](
'
{"some_prop": 123}
'
);
httpsMock
.
listeners
.
end
[
0
]();
expect
(
spy
).
toHaveBeenCalledWith
(
null
,
{
someProp
:
123
});
});
it
(
'
should not convert _ to camelCase if unset
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
();
client
.
options
.
massageProperties
=
false
;
client
.
makeRequest
({
callback
:
spy
});
httpsMock
.
res
.
statusCode
=
200
;
httpsMock
.
listeners
.
data
[
0
](
'
{"some_prop": 123}
'
);
httpsMock
.
listeners
.
end
[
0
]();
expect
(
spy
).
toHaveBeenCalledWith
(
null
,
{
some_prop
:
123
});
});
it
(
'
should not parse the response as json if set to another format
'
,
()
=>
{
const
spy
=
jasmine
.
createSpy
();
client
.
options
.
format
=
'
xml
'
;
client
.
makeRequest
({
callback
:
spy
});
httpsMock
.
res
.
statusCode
=
200
;
httpsMock
.
listeners
.
data
[
0
](
'
<bla>
'
);
httpsMock
.
listeners
.
end
[
0
]();
expect
(
spy
).
toHaveBeenCalledWith
(
null
,
'
<bla>
'
);
})
});
});
spec/helpers/index.js
View file @
b38dd073
...
...
@@ -5,17 +5,23 @@ mockery.enable({
});
const
httpsMock
=
{
reset
:
function
()
{
this
.
listeners
=
{};
this
.
opts
=
{};
this
.
res
.
statusCode
=
''
;
},
opts
:
{},
listeners
:
{
},
res
:
{
on
:
(
method
,
cb
)
=>
{
if
(
!
httpsMock
.
listeners
[
method
])
{
httpsMock
.
listeners
[
method
]
=
[];
}
httpsMock
.
listeners
[
method
].
push
(
cb
);
}
},
request
:
function
(
opts
,
pipe
)
{
this
.
opts
=
opts
;
pipe
({
on
:
(
method
,
cb
)
=>
{
if
(
!
this
.
listeners
[
method
])
{
this
.
listeners
[
method
]
=
[];
}
this
.
listeners
[
method
].
push
(
cb
);
}
});
pipe
(
this
.
res
);
return
{
end
:
()
=>
{}
...
...
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