X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Frpc%2Fupdate.t;h=37bdbe94465a32983f4107ab2f61ccd71103d8ea;hb=208c3bed3073714439661c8ed1af085d1bf8a2be;hp=dc68881474b861045b74b92105a9e95c8757dc99;hpb=d273984026646e5b57c052deef3fcb9121122060;p=catagits%2FCatalyst-Controller-DBIC-API.git diff --git a/t/rpc/update.t b/t/rpc/update.t index dc68881..37bdbe9 100644 --- a/t/rpc/update.t +++ b/t/rpc/update.t @@ -23,6 +23,7 @@ my %original_cols = $track->get_columns; my $track_update_url = "$base/api/rpc/track/id/" . $track->id . "/update"; my $any_track_update_url = "$base/api/rpc/any/track/id/" . $track->id . "/update"; +my $tracks_update_url = "$base/api/rpc/track/update"; # test invalid track id caught { @@ -130,4 +131,33 @@ my $any_track_update_url = "$base/api/rpc/any/track/id/" . $track->id . "/update is($track->get_column('position'), '14', 'Position changed'); } +# bulk_update existing objects +{ + # order to get a stable order of rows + my $tracks_rs = $schema->resultset('Track')->search(undef, { order_by => 'trackid', rows => 3 }); + my $test_data = JSON::Any->Dump({ list => [map +{ id => $_->id, title => 'Track ' . $_->id }, $tracks_rs->all] }); + my $req = POST( $tracks_update_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 200, 'Attempt to update three tracks ok' ); + + $tracks_rs->reset; + while (my $track = $tracks_rs->next) { + is($track->title, 'Track ' . $track->id, 'Title changed'); + } +} + +# bulk_update nonexisting objects +{ + # order to get a stable order of rows + my $test_data = JSON::Any->Dump({ list => [map +{ id => $_, title => 'Track ' . $_ }, (1000..1002)] }); + my $req = POST( $tracks_update_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'Attempt to update three nonexisting tracks fails' ); + my $response = JSON::Any->Load( $mech->content); + is( $response->{success}, 'false', 'success property returns quoted false' ); + like( $response->{messages}->[0], qr/No object found for id/, 'correct message returned' ); +} + done_testing();