Commit | Line | Data |
e2aa4a21 |
1 | #!/usr/bin/env perl |
2 | |
3 | use warnings; |
4 | use strict; |
5 | |
6 | use FindBin; |
7 | use Test::More; |
8 | use HTTP::Request::Common; |
9 | use JSON::MaybeXS; |
10 | |
11 | use lib "$FindBin::Bin/lib"; |
12 | use Catalyst::Test 'TestDataHandlers'; |
13 | |
14 | ok my($res, $c) = ctx_request('/'); |
3eba0dd5 |
15 | |
16 | { |
17 | ok my $message = 'helloworld'; |
18 | ok my $post = encode_json +{message=>$message}; |
19 | ok my $req = POST $c->uri_for_action('/test_json'), |
20 | Content_Type => 'application/json', |
21 | Content => $post; |
22 | |
23 | ok my $response = request $req, 'got a response from a catalyst controller'; |
24 | is $response->content, $message, 'expected content body'; |
25 | } |
26 | |
27 | { |
28 | ok my $req = POST $c->uri_for_action('/test_nested_for'), [ 'nested.value' => 'expected' ]; |
29 | ok my $response = request $req, 'got a response from a catalyst controller'; |
30 | is $response->content, 'expected', 'expected content body'; |
31 | } |
32 | |
c63ec19d |
33 | { |
34 | my $out; |
35 | local *STDERR; |
36 | open(STDERR, ">", \$out) or die "Can't open STDERR: $!"; |
37 | ok my $req = POST $c->uri_for_action('/test_nested_for'), 'Content-Type' => 'multipart/form-data', Content => { die => "a horrible death" }; |
38 | ok my $response = request $req; |
39 | is($out, "[error] multipart/form-data does not have an available data handler. Valid data_handlers are application/json, application/x-www-form-urlencoded.\n", 'yep we throw the slightly more usefull error'); |
40 | } |
e2aa4a21 |
41 | |
42 | done_testing; |