#!/usr/bin/env perl
plan
tests
=> 5;
set
serializer
=>
'JSON'
;
sub
invalid { {
key
=>
'value'
} }
sub
valid { [
'array'
] }
my
$app
= MyApp->to_app;
my
$test
= Plack::Test->create(
$app
);
subtest
"mssing optional parameter"
=>
sub
{
local
$TODO
=
"allow optional parameter missing"
;
my
$res
=
$test
->request( GET
'/valid'
);
is
$res
->
code
=> 200;
is
$res
->
content
=>
q(["array"])
;
};
subtest
"successful request"
=>
sub
{
my
$res
=
$test
->request( GET
'/valid?param=foo'
);
is
$res
->
code
=> 200;
is
$res
->
content
=>
q(["array"])
;
};
subtest
"invalid request"
=>
sub
{
my
$res
=
$test
->request( GET
'/valid?param='
);
is
$res
->
code
=> 400;
like
$res
->
content
=>
qr/^\{"errors":\["/
;
};
subtest
"invalid request 2"
=>
sub
{
local
$TODO
=
"validation of unknown parameters"
;
my
$res
=
$test
->request( GET
'/valid?invalid=param'
);
is
$res
->
code
=> 400;
is
$res
->
content
=>
""
;
};
subtest
"invalid response"
=>
sub
{
my
$res
=
$test
->request( GET
'/invalid'
);
is
$res
->
code
=> 500;
like
$res
->
content
=>
qr/^\{"errors":\["/
;
};