Add tests which should fail, but don't.
[catagits/Catalyst-Action-REST.git] / t / json.t
CommitLineData
7ad87df9 1use strict;
2use warnings;
2f7533ed 3use Test::More;
7ad87df9 4use FindBin;
5
6use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
7use Test::Rest;
c6c4ff28 8use utf8;
7ad87df9 9
8b010556 10eval 'use JSON 2.12';
11plan skip_all => 'Install JSON 2.12 or later to run this test' if ($@);
7ad87df9 12
2f7533ed 13plan tests => 9;
d6fb033c 14
2f7533ed 15use_ok 'Catalyst::Test', 'Test::Serialize';
17d910bd 16
c6c4ff28 17my $json = JSON->new->utf8;
2f7533ed 18# The text/x-json should throw a warning
19for ('text/x-json', 'application/json') {
20 my $t = Test::Rest->new('content_type' => $_);
21 my $monkey_template = {
22 monkey => 'likes chicken!',
23 };
24 my $mres = request($t->get(url => '/monkey_get'));
25 ok( $mres->is_success, 'GET the monkey succeeded' );
26 is_deeply($json->decode($mres->content), $monkey_template, "GET returned the right data");
17d910bd 27
2f7533ed 28 my $post_data = {
29 'sushi' => 'is good for monkey',
c6c4ff28 30 'chicken' => ' 佐藤 純',
2f7533ed 31 };
32 my $mres_post = request($t->post(url => '/monkey_put', data => $json->encode($post_data)));
33 ok( $mres_post->is_success, "POST to the monkey succeeded");
c6c4ff28 34 my $exp = "is good for monkey 佐藤 純";
35 utf8::encode($exp);
36 is_deeply($mres_post->content, $exp, "POST data matches");
2f7533ed 37}
7ad87df9 38
391;