Commit | Line | Data |
d2739840 |
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; |
0b0bf911 |
16 | use JSON; |
17 | |
18 | my $json = JSON->new->utf8; |
d2739840 |
19 | |
20 | my $mech = Test::WWW::Mechanize::Catalyst->new; |
0b0bf911 |
21 | ok( my $schema = DBICTest->init_schema(), 'got schema' ); |
d2739840 |
22 | |
23 | my $track_list_url = "$base/api/rpc/track_setup_dbic_args/list"; |
0b0bf911 |
24 | my $base_rs = |
25 | $schema->resultset('Track') |
26 | ->search( {}, |
27 | { select => [qw/me.title me.position/], order_by => 'position' } ); |
d2739840 |
28 | |
29 | # test open request |
30 | { |
0b0bf911 |
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' ); |
d2739840 |
47 | } |
48 | |
49 | done_testing(); |