@@ -, +, @@ linked to biblio $ kshell k$ prove t/db_dependent/api/v1/volumes.t and the other two tests are fixed so they have the intended biblio_id. controller and the unit tests cover teh 'bad case' returning 409. --- Koha/REST/V1/Biblios/Volumes/Items.pm | 9 +++++++++ t/db_dependent/api/v1/volumes.t | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) --- a/Koha/REST/V1/Biblios/Volumes/Items.pm +++ a/Koha/REST/V1/Biblios/Volumes/Items.pm @@ -56,6 +56,15 @@ sub add { ); } + unless ( $volume->biblionumber eq $c->validation->param('biblio_id') ) { + return $c->render( + status => 409, + openapi => { + error => 'Volume does not belong to passed biblio_id' + } + ); + } + # All good, add the item my $body = $c->validation->param('body'); my $item_id = $body->{item_id}; --- a/t/db_dependent/api/v1/volumes.t +++ a/t/db_dependent/api/v1/volumes.t @@ -210,7 +210,7 @@ subtest 'volumes delete() tests' => sub { }; subtest 'volume items add() + delete() tests' => sub { - plan tests => 11; + plan tests => 14; $schema->storage->txn_begin; @@ -234,8 +234,12 @@ subtest 'volume items add() + delete() tests' => sub { my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); my $item_1_id = $item_1->id; - $t->post_ok( "//$userid:$password@/api/v1/biblios/{biblio_id}/volumes/$volume_id/items" => json => { item_id => $item_1->id } ) - ->status_is( 201, 'SWAGGER3.2.1' ); + $t->post_ok( "//$userid:$password@/api/v1/biblios/XXX/volumes/$volume_id/items" => json => { item_id => $item_1->id } ) + ->status_is( 409 ) + ->json_is( { error => 'Volume does not belong to passed biblio_id' } ); + + $t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id/volumes/$volume_id/items" => json => { item_id => $item_1->id } ) + ->status_is( 201, 'SWAGGER3.2.1' ); @items = $volume->items; is( scalar(@items), 1, 'Volume now has one item'); @@ -243,7 +247,7 @@ subtest 'volume items add() + delete() tests' => sub { my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); my $item_2_id = $item_2->id; - $t->post_ok( "//$userid:$password@/api/v1/biblios/{biblio_id}/volumes/$volume_id/items" => json => { item_id => $item_2->id } ) + $t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id/volumes/$volume_id/items" => json => { item_id => $item_2->id } ) ->status_is( 201, 'SWAGGER3.2.1' ); @items = $volume->items; --