use
5.010;
use_ok
'Wing::Client'
;
my
$result
=
$wing
->_process_response(HTTP::Response->new(200,
'OK'
, [
'Content-Type'
=>
'application/json'
],
'{"result":{"foo":"bar"}}'
));
is
$result
->{foo},
'bar'
,
'process_response()'
;
my
$result
=
eval
{
$wing
->get(
'_test'
)};
if
($@) {
note
"CODE: "
.$@->code;
note
"MESSAGE: "
.$@->code;
note
"DATA: "
.to_json($@->data);
}
else
{
is
$result
->{method},
'GET'
,
'get'
;
}
eval
{
$wing
->get(
'/api/something/that/does/not/exist'
) };
is $@->code,
'404'
,
'error handling works'
;
is
$wing
->put(
'_test'
, {
foo
=>
'bar'
})->{method},
'PUT'
,
'put'
;
is
$wing
->
delete
(
'_test'
, {
foo
=>
'bar'
})->{method},
'DELETE'
,
'delete'
;
cmp_deeply
$wing
->post(
'_test'
, {
file
=> [
't/upload.txt'
]}),
{
"params"
=> {
"file"
=>
"upload.txt"
},
"uploads"
=> [
{
"filename"
=>
"upload.txt"
,
"type"
=>
"text/plain"
,
"size"
=>
"13"
}
],
"method"
=>
"POST"
,
"path"
=>
"/api/_test"
,
"tracer"
=> ignore(),
},
'post / upload'
;
}
else
{
note
"Skipping online tests, because we don't appear to have internet access."
;
}
eval
{
$wing
->_process_response(HTTP::Response->new(500,
'ERROR'
, [
'Content-Type'
=>
'text/plain'
],
'fubared'
)) };
isa_ok $@,
'Ouch'
;
is $@->code, 500,
'parsing error code works'
;
is $@->message,
'Server returned unparsable content.'
,
'parsing error message works'
;
is $@->data->{content},
'fubared'
,
'parsing error data works'
;
done_testing();