File: jsonp.t

package info (click to toggle)
libcatalyst-action-rest-perl 1.21-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 1,750; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 785 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use strict;
use warnings;
use Test::More;
use FindBin;
use JSON::MaybeXS;

use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
use Test::Rest;
use utf8;

use_ok 'Catalyst::Test', 'Test::Serialize', 'Catalyst::Action::Serialize::JSON';

my $json = JSON->new->utf8;

for ('text/javascript','application/x-javascript','application/javascript') {
    my $t = Test::Rest->new('content_type' => $_);
    my $monkey_template = { monkey => 'likes chicken!' };

    my $mres = request($t->get(url => '/monkey_get?callback=My_Animal.omnivore'));
    ok( $mres->is_success, 'GET the monkey succeeded' );

    my ($json_param) = $mres->content =~ /^My_Animal.omnivore\((.*)?\);$/;
    is_deeply($json->decode($json_param), $monkey_template, "GET returned the right data");
}

1;

done_testing;