Add tests which should fail, but don't.
[catagits/Catalyst-Action-REST.git] / t / jsonp.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use FindBin;
5
6 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
7 use Test::Rest;
8 use utf8;
9
10 eval 'use JSON 2.12';
11 plan skip_all => 'Install JSON 2.12 or later to run this test' if ($@);
12
13 plan tests => 7;
14
15 use_ok 'Catalyst::Test', 'Test::Serialize', 'Catalyst::Action::Serialize::JSON';
16
17 my $json = JSON->new->utf8;
18
19 for ('text/javascript','application/x-javascript','application/javascript') {
20     my $t = Test::Rest->new('content_type' => $_);
21     my $monkey_template = { monkey => 'likes chicken!' };
22
23     my $mres = request($t->get(url => '/monkey_get?callback=omnivore'));
24     ok( $mres->is_success, 'GET the monkey succeeded' );
25
26     my ($json_param) = $mres->content =~ /^omnivore\((.*)?\);$/;
27     is_deeply($json->decode($json_param), $monkey_template, "GET returned the right data");
28 }
29
30 1;