6 my $base = 'http://localhost';
7 my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ];
12 use Test::WWW::Mechanize::Catalyst 'RestTest';
13 use HTTP::Request::Common qw/ DELETE /;
16 my $json = JSON->new->utf8;
18 my $mech = Test::WWW::Mechanize::Catalyst->new;
19 ok( my $schema = DBICTest->init_schema(), 'got schema' );
21 my $track = $schema->resultset('Track')->first;
22 my %original_cols = $track->get_columns;
24 my $track_url = "$base/api/rest/track/";
25 my $track_delete_url = $track_url . $track->id;
28 my $req = HTTP::Request->new( DELETE => $track_delete_url );
29 $req->content_type('text/x-json');
31 cmp_ok( $mech->status, '==', 200, 'Attempt to delete track ok' );
33 my $deleted_track = $schema->resultset('Track')->find( $track->id );
34 is( $deleted_track, undef, 'track deleted' );
38 my $req = HTTP::Request->new( DELETE => $track_delete_url );
39 $req->content_type('text/x-json');
41 cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' );
45 my $track_cnt = $schema->resultset('Track')->count;
47 $schema->resultset('Track')
48 ->search( undef, { select => ['trackid'], as => ['id'], rows => 3 } );
49 $tracks_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
50 my $test_data = $json->encode( { list => [ $tracks_rs->all ] } );
51 my $req = DELETE( $track_url, Content => $test_data );
52 $req->content_type('text/x-json');
54 cmp_ok( $mech->status, '==', 200, 'Attempt to delete three tracks ok' );
56 is( $schema->resultset('Track')->count + 3,
57 $track_cnt, 'Three tracks deleted' );