Skip to content

Instantly share code, notes, and snippets.

@moznion
Created November 4, 2013 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moznion/7303022 to your computer and use it in GitHub Desktop.
Save moznion/7303022 to your computer and use it in GitHub Desktop.
use HTTP::Request::Common;
use JSON qw/to_json/;
use Plack::Test;
use Test::More;
use Test::JsonAPI::Autodoc;
# PSGI application
my $app = sub {
my $json = to_json({
jsonrpc => '2.0',
result => {
entries => [{
title => 'example',
body => 'Hello!',
}],
},
id => 1,
});
return [ 200, [ 'Content-Type' => 'application/json' ], [$json] ];
};
my $test_app = Plack::Test->create($app);
describe 'POST /' => sub {
my $json = to_json({
jsonrpc => '2.0',
method => 'get_entries',
params => { limit => 1, category => 'technology' },
});
my $req = POST '/';
$req->header('Content-Type' => 'application/json');
$req->header('Content-Length' => length $json);
$req->content($json);
plack_ok($test_app, $req, 200, "get message ok");
};
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment