use JSON instead of JSON::Any to get rid of the CPAN Testers failures when only JSON...
[catagits/Catalyst-Controller-DBIC-API.git] / t / rpc / setup_dbic_args.t
1 use 5.6.0;
2
3 use strict;
4 use warnings;
5
6 use lib 't/lib';
7
8 my $base = 'http://localhost';
9
10 use RestTest;
11 use DBICTest;
12 use URI;
13 use Test::More;
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common;
16 use JSON;
17
18 my $json = JSON->new->utf8;
19
20 my $mech = Test::WWW::Mechanize::Catalyst->new;
21 ok( my $schema = DBICTest->init_schema(), 'got schema' );
22
23 my $track_list_url = "$base/api/rpc/track_setup_dbic_args/list";
24 my $base_rs =
25     $schema->resultset('Track')
26     ->search( {},
27     { select => [qw/me.title me.position/], order_by => 'position' } );
28
29 # test open request
30 {
31     my $req = GET(
32         $track_list_url,
33         {
34
35         },
36         'Accept' => 'text/x-json'
37     );
38     $mech->request($req);
39     cmp_ok( $mech->status, '==', 200, 'open attempt okay' );
40
41     my @expected_response = map {
42         { $_->get_columns }
43     } $base_rs->search( { position => { '!=' => '1' } } )->all;
44     my $response = $json->decode( $mech->content );
45     is_deeply( { list => \@expected_response, success => 'true' },
46         $response, 'correct message returned' );
47 }
48
49 done_testing();