From d249162f74715fd1cbeb75cb99a374500838ddbc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Jan 2025 12:38:02 -0300 Subject: [PATCH] Bug 38929: Regression tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/authorities.t | 6 +- t/db_dependent/api/v1/biblios.t | 103 ++++++++++-------- t/db_dependent/api/v1/clubs_holds.t | 18 +-- t/db_dependent/api/v1/holds.t | 31 +++--- t/db_dependent/api/v1/ill_batchstatuses.t | 13 ++- t/db_dependent/api/v1/import_batch_profiles.t | 16 +-- t/db_dependent/api/v1/transfer_limits.t | 25 +++-- 7 files changed, 114 insertions(+), 98 deletions(-) diff --git a/t/db_dependent/api/v1/authorities.t b/t/db_dependent/api/v1/authorities.t index 41c9be864e3..19d1a75cb3b 100755 --- a/t/db_dependent/api/v1/authorities.t +++ b/t/db_dependent/api/v1/authorities.t @@ -202,7 +202,7 @@ subtest 'post() tests' => sub { ->json_is(q{}) ->header_like( Location => qr|^\/api\/v1\/authorities/\d*|, - 'SWAGGER3.4.1' + 'REST3.4.1' ); # x-koha-override not passed to force block because duplicate @@ -217,7 +217,7 @@ subtest 'post() tests' => sub { ->json_is(q{}) ->header_like( Location => qr|^\/api\/v1\/authorities/\d*|, - 'SWAGGER3.4.1' + 'REST3.4.1' ); $t->post_ok("//$userid:$password@/api/v1/authorities" => {'Content-Type' => 'application/marc', 'x-authority-type' => 'CORPO_NAME', 'x-koha-override' => 'duplicate' } => $marc) @@ -225,7 +225,7 @@ subtest 'post() tests' => sub { ->json_is(q{}) ->header_like( Location => qr|^\/api\/v1\/authorities/\d*|, - 'SWAGGER3.4.1' + 'REST3.4.1' ); $schema->storage->txn_rollback; diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t index c44509033e7..9adfb1194e0 100755 --- a/t/db_dependent/api/v1/biblios.t +++ b/t/db_dependent/api/v1/biblios.t @@ -287,8 +287,8 @@ subtest 'delete() tests' => sub { # Bibs with no items can be deleted $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id") - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id") ->status_is(404); @@ -901,7 +901,7 @@ subtest 'set_rating() tests' => sub { subtest 'add() tests' => sub { - plan tests => 17; + plan tests => 18; $schema->storage->txn_begin; @@ -1312,9 +1312,11 @@ subtest 'add() tests' => sub { $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode, "x-record-schema" => 'INVALID'}) ->status_is(400, 'Invalid header x-record-schema'); - $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode} => $marcxml) - ->status_is(200) - ->json_has('/id'); + $t->post_ok( "//$userid:$password@/api/v1/biblios" => + { 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml ) + ->status_is(200) + ->json_has('/id') + ->header_is( 'Location' => "/api/v1/biblios/" . $t->tx->res->json->{id}, "REST3.4.1" ); $t->post_ok("//$userid:$password@/api/v1/biblios" => {'Content-Type' => 'application/marc-in-json', 'x-framework-id' => $frameworkcode, 'x-confirm-not-duplicate' => 1} => $mij) ->status_is(200) @@ -1893,59 +1895,64 @@ subtest 'list() tests' => sub { }; subtest 'add_item() tests' => sub { - plan tests => 7; - $schema->storage->txn_begin; + plan tests => 8; - my $patron = $builder->build_object( - { - class => 'Koha::Patrons', - value => { flags => 0 } - } - ); - my $password = 'thePassword123'; - $patron->set_password( { password => $password, skip_validation => 1 } ); - my $userid = $patron->userid; + $schema->storage->txn_begin; - my $biblio = $builder->build_sample_biblio(); - my $biblio_id = $biblio->biblionumber; + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 0 } + } + ); + my $password = 'thePassword123'; + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $patron->userid; - my $barcode = 'mybarcode'; - my $matching_items = Koha::Items->search({ barcode => $barcode }); + my $biblio = $builder->build_sample_biblio(); + my $biblio_id = $biblio->biblionumber; - while (my $item = $matching_items->next) { - $item->delete; - } + my $barcode = 'mybarcode'; + my $matching_items = Koha::Items->search( { barcode => $barcode } ); - $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { external_id => $barcode }) - ->status_is(403, 'Not enough permissions to create an item'); + while ( my $item = $matching_items->next ) { + $item->delete; + } - # Add permissions - $builder->build( - { - source => 'UserPermission', - value => { - borrowernumber => $patron->borrowernumber, - module_bit => 9, - code => 'edit_catalogue' - } - } - ); + $t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { external_id => $barcode } ) + ->status_is( 403, 'Not enough permissions to create an item' ); - $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { - external_id => $barcode, - }) - ->status_is(201, 'Item created') - ->json_is('/biblio_id', $biblio_id); + # Add permissions + $builder->build( + { + source => 'UserPermission', + value => { + borrowernumber => $patron->borrowernumber, + module_bit => 9, + code => 'edit_catalogue' + } + } + ); - my $item = $builder->build_sample_item(); + $t->post_ok( + "//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { + external_id => $barcode, + } + )->status_is( 201, 'Item created' )->json_is( '/biblio_id', $biblio_id ); - $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { - external_id => $item->barcode, - }) - ->status_is(409, 'Duplicate barcode'); + my $item_id = $t->tx->res->json->{item_id}; + $t->header_is( 'Location' => "/api/v1/items/$item_id", "REST3.4.1" ); - $schema->storage->txn_rollback; + my $item = $builder->build_sample_item(); + + $t->post_ok( + "//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { + external_id => $item->barcode, + } + )->status_is( 409, 'Duplicate barcode' ); + + $schema->storage->txn_rollback; }; subtest 'update_item() tests' => sub { diff --git a/t/db_dependent/api/v1/clubs_holds.t b/t/db_dependent/api/v1/clubs_holds.t index 927e7eb5aac..e7de87b8386 100755 --- a/t/db_dependent/api/v1/clubs_holds.t +++ b/t/db_dependent/api/v1/clubs_holds.t @@ -61,7 +61,7 @@ subtest 'add() tests' => sub { subtest 'librarian access tests' => sub { - plan tests => 20; + plan tests => 21; $schema->storage->txn_begin; @@ -144,13 +144,15 @@ subtest 'add() tests' => sub { ->status_is(409) ->json_is( '/error' => "Cannot place a hold on a club without patrons." ); - $t->post_ok( "//$userid:$password@/api/v1/clubs/" - . $club_with_enrollments->id - . "/holds" => json => $data ) - ->status_is( 201, 'Created Hold' ) - ->json_has( '/club_hold_id', 'got a club hold id' ) - ->json_is( '/club_id' => $club_with_enrollments->id ) - ->json_is( '/biblio_id' => $item->biblionumber ); + $t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data ) + ->status_is( 201, 'Created Hold' ) + ->json_has( '/club_hold_id', 'got a club hold id' ) + ->json_is( '/club_id' => $club_with_enrollments->id ) + ->json_is( '/biblio_id' => $item->biblionumber ) + ->header_is( + 'Location' => '/api/v1/clubs/' . $club_with_enrollments->id . '/holds/' . $t->tx->res->json->{club_hold_id}, + 'REST3.4.1' + ); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 4528712ec98..ff78fd51126 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -200,7 +200,7 @@ subtest "Test endpoints without permission" => sub { subtest "Test endpoints with permission" => sub { - plan tests => 44; + plan tests => 45; $t->get_ok( "//$userid_1:$password@/api/v1/holds" ) ->status_is(200) @@ -214,8 +214,8 @@ subtest "Test endpoints with permission" => sub { ->json_hasnt('/1'); $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); $t->patch_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" => json => $patch_data ) ->status_is(404) @@ -235,8 +235,8 @@ subtest "Test endpoints with permission" => sub { ->json_is([]); $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id2" => json => "Cancellation reason" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); # Make sure pickup location checks doesn't get in the middle my $mock_biblio = Test::MockModule->new('Koha::Biblio'); @@ -245,8 +245,9 @@ subtest "Test endpoints with permission" => sub { $mock_item->mock( 'pickup_locations', sub { return Koha::Libraries->search }); $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) - ->status_is(201) - ->json_has('/hold_id'); + ->status_is(201) + ->json_has('/hold_id') + ->header_is( 'Location' => '/api/v1/holds/' . $t->tx->res->json->{hold_id}, "REST3.4.1" ); # Get id from response $reserve_id = $t->tx->res->json->{hold_id}; @@ -294,8 +295,8 @@ subtest 'Reserves with itemtype' => sub { }; $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); # Make sure pickup location checks doesn't get in the middle my $mock_biblio = Test::MockModule->new('Koha::Biblio'); @@ -517,8 +518,8 @@ subtest 'suspend and resume tests' => sub { ); $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); # Pass a an expiration date for the suspension my $date = dt_from_string()->add( days => 5 ); @@ -535,8 +536,8 @@ subtest 'suspend and resume tests' => sub { ->header_is( Location => "/api/v1/holds/" . $hold->id . "/suspension", 'The Location header is set' ); $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); $hold->set_waiting->discard_changes; @@ -1519,8 +1520,8 @@ subtest 'delete() tests' => sub { ) ); - $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id )->status_is( 204, 'SWAGGER3.2.4' ) - ->content_is( '', 'SWAGGER3.3.4' ); + $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id )->status_is( 204, 'REST3.2.4' ) + ->content_is( '', 'REST3.3.4' ); $hold = Koha::Holds->find( AddReserve( diff --git a/t/db_dependent/api/v1/ill_batchstatuses.t b/t/db_dependent/api/v1/ill_batchstatuses.t index b9af25a0753..cf73020ec74 100755 --- a/t/db_dependent/api/v1/ill_batchstatuses.t +++ b/t/db_dependent/api/v1/ill_batchstatuses.t @@ -131,7 +131,7 @@ subtest 'get() tests' => sub { subtest 'add() tests' => sub { - plan tests => 14; + plan tests => 15; $schema->storage->txn_begin; @@ -180,10 +180,13 @@ subtest 'add() tests' => sub { ); # Authorized attempt to write - my $status_id = - $t->post_ok( "//$userid:$password@/api/v1/ill/batchstatuses" => json => $status_metadata )->status_is(201) - ->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' ) - ->json_has( '/is_system', 'is_system' ); + $t->post_ok( "//$userid:$password@/api/v1/ill/batchstatuses" => json => $status_metadata ) + ->status_is(201) + ->json_has( '/id', 'ID' ) + ->json_has( '/name', 'Name' ) + ->json_has( '/code', 'Code' ) + ->json_has( '/is_system', 'is_system' ) + ->header_is( 'Location' => '/api/v1/ill/batchstatuses/' . $t->tx->res->json->{code}, "REST3.4.1" ); # Authorized attempt to create with null id $status_metadata->{id} = undef; diff --git a/t/db_dependent/api/v1/import_batch_profiles.t b/t/db_dependent/api/v1/import_batch_profiles.t index e0eb6adcb8a..88c074c5585 100755 --- a/t/db_dependent/api/v1/import_batch_profiles.t +++ b/t/db_dependent/api/v1/import_batch_profiles.t @@ -110,8 +110,9 @@ subtest 'list profiles' => sub { }; -subtest 'add profile' => sub { - plan tests => 5; +subtest 'add() tests' => sub { + + plan tests => 6; $schema->storage->txn_begin; @@ -140,12 +141,13 @@ subtest 'add profile' => sub { name => 'profileName', overlay_action => 'overlay_action' }; - $t->post_ok("//$uid:$pwd@/api/v1/import_batch_profiles", json => $post_data) - ->status_is(201) - ->json_has('/profile_id') - ->json_is('/name', $post_data->{name}) - ->json_is('/overlay_action', $post_data->{overlay_action}); + $t->post_ok( "//$uid:$pwd@/api/v1/import_batch_profiles", json => $post_data ) + ->status_is(201) + ->json_has('/profile_id') + ->json_is( '/name', $post_data->{name} ) + ->json_is( '/overlay_action', $post_data->{overlay_action} ) + ->header_is( 'Location', '/api/v1/import_batch_profiles/' . $t->tx->res->json->{profile_id}, 'REST3.4.1' ); $schema->storage->txn_rollback; diff --git a/t/db_dependent/api/v1/transfer_limits.t b/t/db_dependent/api/v1/transfer_limits.t index 33ceecec723..59490401506 100755 --- a/t/db_dependent/api/v1/transfer_limits.t +++ b/t/db_dependent/api/v1/transfer_limits.t @@ -54,7 +54,7 @@ subtest 'list() tests' => sub { my $limit = $builder->build_object({ class => 'Koha::Item::Transfer::Limits' }); $t->get_ok( "//$userid:$password@/api/v1/transfer_limits" ) - ->status_is( 200, 'SWAGGER3.2.2' ) + ->status_is( 200, 'REST3.2.2' ) ->json_is( [$limit->to_api] ); $schema->storage->txn_rollback; @@ -62,7 +62,7 @@ subtest 'list() tests' => sub { subtest 'add() tests' => sub { - plan tests => 11; + plan tests => 12; $schema->storage->txn_begin; @@ -106,8 +106,9 @@ subtest 'add() tests' => sub { # Authorized attempt to write $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits" => json => $limit_hashref ) - ->status_is( 201, 'SWAGGER3.2.1' ) - ->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); + ->status_is( 201, 'REST3.2.1' ) + ->json_has( '' => $limit_hashref, 'REST3.3.1' ) + ->header_is( 'Location' => '/api/v1/transfer_limits/' . $t->tx->res->json->{limit_id}, 'REST3.4.1' ); $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits" => json => $limit_hashref ) ->status_is( 409, 'Conflict creating the resource' ) @@ -148,8 +149,8 @@ subtest 'delete() tests' => sub { ->status_is(403); $t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/$limit_id" ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + ->status_is(204, 'REST3.2.4') + ->content_is('', 'REST3.3.4'); $t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/$limit_id" ) ->status_is(404); @@ -228,7 +229,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { # Create all combinations of to/from libraries $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); + ->status_is( 201, 'REST3.2.1' )->json_has( '' => $limit_hashref, 'REST3.3.1' ); my $limits = Koha::Item::Transfer::Limits->search; @@ -237,7 +238,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { # Delete all combinations of to/from libraries $t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); + ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); $limits = Koha::Item::Transfer::Limits->search; @@ -246,7 +247,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { # Create all combinations of 'to' libraries $limit_hashref->{to_library_id} = $library->id; $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); + ->status_is( 201, 'REST3.2.1' )->json_has( '' => $limit_hashref, 'REST3.3.1' ); $limits = Koha::Item::Transfer::Limits->search; @@ -254,7 +255,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { # Delete all combinations of 'to' libraries $t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); + ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); $limits = Koha::Item::Transfer::Limits->search; @@ -266,7 +267,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { delete $limit_hashref->{to_library_id}; $limit_hashref->{from_library_id} = $library->id; $t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); + ->status_is( 201, 'REST3.2.1' )->json_has( '' => $limit_hashref, 'REST3.3.1' ); $limits = Koha::Item::Transfer::Limits->search; @@ -275,7 +276,7 @@ subtest 'batch_add() and batch_delete() tests' => sub { # Delete all combinations of 'from' libraries $t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) - ->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); + ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); $limits = Koha::Item::Transfer::Limits->search; -- 2.48.1