PerlDancer/Dancer2-Plugin-REST

Input not being deserialized

jahagirdar opened this issue · 3 comments

self contained test attached.
Running it results in the following test failure.

 #   Failed test 'Check If response JSON matches Input'

Problem: The input is not getting deserialized.

Full test code below for reference

use strict;
use warnings;
use Test::More;# tests=>3;
use Plack::Test;
use HTTP::Request::Common;
use Test::JSON::More;
use JSON;

{
    package App;
    use Dancer2;
    set serializer => 'JSON';

    post '/namecheck.:format' => sub {
        my $post_params = params('body');
	return $post_params;
    };

}
{
    package RESTApp;
    use Dancer2;
    use Dancer2::Plugin::REST;
    prepare_serializer_for_format;

    post '/namecheck.:format' => sub {
        my $post_params = params('body');
	return $post_params;
    };

}
my $req = HTTP::Request->new(POST => "/namecheck.json");
$req->header("Content-Type"=>"application/json");
my $json='{"item":1,"type":"test"}';
$req->content($json);
ok_json($json, "JSON Seems wellformed");

my $app = App->to_app;
my $restapp = RESTApp->to_app;
############################################
is( ref $app, 'CODE', 'Got app' );
my $test = Plack::Test->create($app);
my $res=$test->request($req);
is( $res->code, 200, '[POST: Check Name  ] ' )or BAIL_OUT("checking of a name  is necessary for testing to proceed.");
cmp_json($res->content,$json,"CheckIf Response JSON matches input");
############################################
############################################
is( ref $restapp, 'CODE', 'Got app' );
my $test = Plack::Test->create($restapp);
my $res=$test->request($req);
is( $res->code, 200, '[POST: Check Name  ] ' )or BAIL_OUT("checking of a name  is necessary for testing to proceed.");
cmp_json($res->content,$json,"Check If response JSON matches Input");
############################################
	done_testing;

t2.zip

As this repo is forked from the original repo I am not sure whether the module author is receiving these updates hence tagging @yanick

Distress flare received. Will try to check it out today. :-)

Merged. Will be deployed in the next hour.