CatalystX-ExtJS-REST
view release on metacpan or search on metacpan
t/direct/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->request( POST '/rest/object/1' ), 'chained action is working' );
foreach my $action (qw(create read update destroy)) {
ok(
$mech->request(
POST $api->{url},
Content_Type => 'application/json',
Content => encode_json(
{
action => 'REST',
method => $action,
data => [1],
tid => $tid,
type => 'rpc'
}
)
),
'rest interface: ' . $action
);
ok( my $json = decode_json( $mech->content ), 'response is valid json' );
is_deeply(
$json,
{
action => 'REST',
method => $action,
result => { action => $action },
tid => $tid++,
type => 'rpc'
},
'expected response'
);
}
ok(
$mech->request(
POST $api->{url},
[
extAction => 'User',
extMethod => 'create',
extTID => $tid,
extType => 'rpc',
password => 'foobar',
( run in 0.483 second using v1.01-cache-2.11-cpan-13bb782fe5a )