From: Alexander Hartmaier Date: Wed, 13 Jun 2018 17:24:41 +0000 (+0200) Subject: add test for bulk create with database error X-Git-Tag: 2.007001~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=7f3ed65229c15d978fd4ac17848947da0a454369 add test for bulk create with database error --- diff --git a/t/rest/create.t b/t/rest/create.t index ba850c1..eff1bfa 100644 --- a/t/rest/create.t +++ b/t/rest/create.t @@ -19,6 +19,7 @@ ok( my $schema = DBICTest->init_schema(), 'got schema' ); my $artist_create_url = "$base/api/rest/artist"; my $producer_create_url = "$base/api/rest/producer"; +my $track_create_url = "$base/api/rest/track"; # test validation when no params sent { @@ -105,4 +106,45 @@ my $producer_create_url = "$base/api/rest/producer"; 'json for bulk create returned' ); } +# test bulk create with database error +{ + my $test_data = $json->encode({ + list => [ + { + cd => 2, + position => 4, + title => "Foobar", + }, + { + cd => 2, + # set position column to NULL to force error + position => undef, + title => "Foobar", + }, + ] + }); + #my $req = PUT( $tracks_update_url, Content => $test_data ); + my $req = PUT($track_create_url); + $req->content_type('text/x-json'); + $req->content_length( + do { use bytes; length($test_data) } + ); + $req->content($test_data); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'bulk request with one invalid object fails' ); + my $rs = + $schema->resultset('Track') + ->search( [ { cd => 2 } ] ); + is( $rs->count, 3, 'no records created' ); + + my $response = $json->decode( $mech->content ); + is( $response->{success}, JSON::false, + 'success property returns unquoted false' ); + like( + $response->{messages}->[0], + qr/a database error has occured/, + 'correct message returned' + ); +} + done_testing();