1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
use strict;
use warnings;
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
subtest 'request data basic' => sub {
{
package App::Body::Str; ## no critic
use Dancer2;
post '/' => sub {
my $data = request_data;
::is(
$data,
'a string body',
'string content ok'
);
};
}
my $app = Plack::Test->create( App::Body::Str->to_app );
my $res = $app->request( POST '/', Content_Type => 'text/plain', Content => "a string body" );
ok( $res->is_success, 'Successful request' );
};
subtest 'request data serialized' => sub {
{
package App::Body::JSON; ## no critic
use Dancer2;
set serializer => 'JSON';
post '/' => sub {
my $data = request_data;
::is_deeply(
$data,
{ body => { is => [ "json" ] } },
'json content ok'
);
return +{ ok => 1 };
};
}
my $app = Plack::Test->create( App::Body::JSON->to_app );
my $res = $app->request( POST '/', Content_Type => 'application/json', Content => '{"body":{"is":["json"]}}' );
ok( $res->is_success, 'Successful request' );
};
done_testing();
|