8 my $base = 'http://localhost';
9 my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ];
14 use Test::WWW::Mechanize::Catalyst 'RestTest';
15 use HTTP::Request::Common qw/ DELETE /;
18 my $json = JSON->new->utf8;
20 my $mech = Test::WWW::Mechanize::Catalyst->new;
21 ok( my $schema = DBICTest->init_schema(), 'got schema' );
23 my $track = $schema->resultset('Track')->first;
24 my %original_cols = $track->get_columns;
26 my $track_url = "$base/api/rest/track/";
27 my $track_delete_url = $track_url . $track->id;
30 my $req = HTTP::Request->new( DELETE => $track_delete_url );
31 $req->content_type('text/x-json');
33 cmp_ok( $mech->status, '==', 200, 'Attempt to delete track ok' );
35 my $deleted_track = $schema->resultset('Track')->find( $track->id );
36 is( $deleted_track, undef, 'track deleted' );
40 my $req = HTTP::Request->new( DELETE => $track_delete_url );
41 $req->content_type('text/x-json');
43 cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' );
47 my $track_cnt = $schema->resultset('Track')->count;
49 $schema->resultset('Track')
50 ->search( undef, { select => ['trackid'], as => ['id'], rows => 3 } );
51 $tracks_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
52 my $test_data = $json->encode( { list => [ $tracks_rs->all ] } );
53 my $req = DELETE( $track_url, Content => $test_data );
54 $req->content_type('text/x-json');
56 cmp_ok( $mech->status, '==', 200, 'Attempt to delete three tracks ok' );
58 is( $schema->resultset('Track')->count + 3,
59 $track_cnt, 'Three tracks deleted' );