Commit | Line | Data |
609916e5 |
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::Any; |
17 | |
18 | my $mech = Test::WWW::Mechanize::Catalyst->new; |
19 | ok(my $schema = DBICTest->init_schema(), 'got schema'); |
20 | |
21 | my $artist_view_url = "$base/api/rest/artist/"; |
22 | |
23 | { |
24 | my $id = 1; |
25 | my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); |
26 | $mech->request($req); |
27 | cmp_ok( $mech->status, '==', 200, 'open attempt okay' ); |
28 | my %expected_response = $schema->resultset('Artist')->find($id)->get_columns; |
29 | my $response = JSON::Any->Load( $mech->content); |
30 | is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned' ); |
31 | } |
32 | |
33 | { |
34 | my $id = 5; |
35 | my $req = GET( $artist_view_url . $id, undef, 'Accept' => 'application/json' ); |
36 | $mech->request($req); |
37 | cmp_ok( $mech->status, '==', 400, 'open attempt not ok' ); |
38 | my $response = JSON::Any->Load( $mech->content); |
39 | is($response->{success}, 'false', 'not existing object fetch failed ok'); |
40 | like($response->{messages}->[0], qr/^No object found for id/, 'error message for not existing object fetch ok'); |
41 | } |
42 | |
15754afc |
43 | my $track_view_url = "$base/api/rest/track/"; |
44 | |
45 | { |
46 | my $id = 9; |
47 | my $req = GET( $track_view_url . $id, undef, 'Accept' => 'application/json' ); |
48 | $mech->request($req); |
49 | cmp_ok( $mech->status, '==', 200, 'got track with datetime object okay' ); |
50 | my %expected_response = $schema->resultset('Track')->find($id)->get_columns; |
51 | warn $mech->content, "\n"; |
52 | my $response = JSON::Any->Load( $mech->content); |
53 | use Data::Dumper; |
54 | warn Dumper($response); |
55 | is_deeply( $response, { data => \%expected_response, success => 'true' }, 'correct data returned for track with datetime' ); |
56 | } |
57 | |
609916e5 |
58 | done_testing(); |