Commit | Line | Data |
07b00970 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use lib 't/lib'; |
5 | |
6 | my $base = 'http://localhost'; |
7 | |
8 | use RestTest; |
9 | use DBICTest; |
10 | use URI; |
11 | use Test::More; |
12 | use Test::WWW::Mechanize::Catalyst 'RestTest'; |
13 | use HTTP::Request::Common; |
14 | use JSON; |
15 | use Data::Dumper; |
16 | |
17 | my $json = JSON->new->utf8; |
18 | |
19 | my $mech = Test::WWW::Mechanize::Catalyst->new; |
20 | ok( my $schema = DBICTest->init_schema(), 'got schema' ); |
21 | |
22 | my $base_url = "$base/api/rest/stashedclass"; |
23 | |
24 | # test cd |
25 | { |
26 | my $class = 'RestTestDB::CD'; |
27 | my $req = GET( "$base_url/$class", {}, 'Accept' => 'text/x-json'); |
28 | $mech->request($req); |
29 | cmp_ok( $mech->status, '==', '200', "status OK" ); |
30 | my $response = $json->decode( $mech->content ); |
31 | is($response->{success}, 'true', 'success'); |
32 | is(scalar( @{$response->{list}} ), 6, 'six results'); |
33 | } |
34 | |
35 | # test author |
36 | { |
37 | my $class = 'RestTestDB::Artist'; |
38 | my $req = GET( "$base_url/$class", {}, 'Accept' => 'text/x-json'); |
39 | $mech->request($req); |
40 | cmp_ok( $mech->status, '==', '200', "status OK" ); |
41 | my $response = $json->decode( $mech->content ); |
42 | is($response->{success}, 'true', 'success'); |
43 | is(scalar( @{$response->{list}} ), 3, 'three results'); |
44 | } |
45 | |
46 | # test non-existent class |
47 | { |
48 | my $class = 'Foo::Bar::Baz'; |
49 | my $req = GET( "$base_url/$class", {}, 'Accept' => 'text/x-json'); |
50 | $mech->request($req); |
51 | cmp_ok( $mech->status, '==', '400', "status 400" ); |
52 | my $response = $json->decode( $mech->content ); |
53 | like($response->{messages}[0], qr/current_result_set.*does not pass the type constraint/, 'invalid class'); |
54 | } |
55 | |
56 | done_testing(); |