CatalystX-ExtJS-Direct

 view release on metacpan or  search on metacpan

t/router.t  view on Meta::CPAN

use Test::More;

use strict;
use warnings;

use HTTP::Request::Common;
use JSON::XS;

use lib qw(t/lib);

use Test::WWW::Mechanize::Catalyst 'MyApp';

my $mech = Test::WWW::Mechanize::Catalyst->new();
my $tid  = 1;

ok(
    my $api = MyApp->controller('API')->api,
    'get api directly from controller'
);

is( $api->{url}, '/api/router' );

ok( $mech->get_ok('/add/8/to/9') );

is( $mech->content, '17', 'calculator works' );

ok( $mech->get( $api->{url} ) );

is( $mech->status, 400, 'bad request' );

my $request = {
    action => 'Calculator',
    method => 'add',
    data   => [ 1, 3 ],
    tid    => $tid,
    type   => 'rpc'
};

ok(
    $mech->request(
        POST $api->{url},
        Content_Type => 'application/json',
        Content      => encode_json($request)
    ),
    'get via json in body'
);

ok( my $json = decode_json( $mech->content ), 'response is valid json' );

is_deeply(
    $json,
    {
        action => 'Calculator',
        method => 'add',
        result => 4,
        tid    => $tid++,
        type   => 'rpc'
    },
    'expected response'
);

ok(
    $mech->request(
        POST $api->{url},
        [
            extAction => 'Calculator',



( run in 1.060 second using v1.01-cache-2.11-cpan-39bf76dae61 )