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