From eed6307c7a6755c37157d481317d29d6b50b0c2a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 2 Apr 2020 18:38:33 -0300 Subject: [PATCH] Bug 25048: Regression tests This patch adds regression tests for the response bodies and statuses on DELETE actions against existing API routes. This is just enforcing the existing (voted) Coding guidelines for the API (tm). To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/*.t => FAIL: Several routes have problems --- t/db_dependent/api/v1/acquisitions_vendors.t | 12 +++++------ t/db_dependent/api/v1/cities.t | 4 ++-- t/db_dependent/api/v1/holds.t | 21 +++++++++++--------- t/db_dependent/api/v1/patrons.t | 5 +++-- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/t/db_dependent/api/v1/acquisitions_vendors.t b/t/db_dependent/api/v1/acquisitions_vendors.t index f61b59251e..6798688326 100644 --- a/t/db_dependent/api/v1/acquisitions_vendors.t +++ b/t/db_dependent/api/v1/acquisitions_vendors.t @@ -113,8 +113,8 @@ subtest 'list() and delete() tests | authorized user' => sub { $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); $t->request_ok($tx) - ->status_is(200) - ->content_is(q{""}); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $tx = $t->ua->build_tx( GET => '/api/v1/acquisitions/vendors' ); $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); @@ -128,8 +128,8 @@ subtest 'list() and delete() tests | authorized user' => sub { $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); $t->request_ok($tx) - ->status_is(200) - ->content_is(q{""}); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $tx = $t->ua->build_tx( GET => '/api/v1/acquisitions/vendors' ); $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); @@ -364,8 +364,8 @@ subtest 'delete() tests' => sub { $tx->req->cookies( { name => 'CGISESSID', value => $authorized_session_id } ); $tx->req->env( { REMOTE_ADDR => $remote_address } ); $t->request_ok($tx) - ->status_is(200) - ->content_is(q{""}); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $tx = $t->ua->build_tx( DELETE => "/api/v1/acquisitions/vendors/$vendor_id" ); $tx->req->cookies( { name => 'CGISESSID', value => $authorized_session_id } ); diff --git a/t/db_dependent/api/v1/cities.t b/t/db_dependent/api/v1/cities.t index caaa0f05d5..720e6434a1 100644 --- a/t/db_dependent/api/v1/cities.t +++ b/t/db_dependent/api/v1/cities.t @@ -370,8 +370,8 @@ subtest 'delete() tests' => sub { ->status_is(403); $t->delete_ok("//$userid:$password@/api/v1/cities/$city_id") - ->status_is(200) - ->content_is('""'); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $t->delete_ok("//$userid:$password@/api/v1/cities/$city_id") ->status_is(404); diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 8c3aa2fb4e..f7436da0ee 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -199,7 +199,7 @@ subtest "Test endpoints without permission" => sub { subtest "Test endpoints with permission" => sub { - plan tests => 57; + plan tests => 59; $t->get_ok( "//$userid_1:$password@/api/v1/holds" ) ->status_is(200) @@ -240,7 +240,8 @@ subtest "Test endpoints with permission" => sub { ->json_is( '/pickup_library_id', $branchcode2 ); $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" ) - ->status_is(200); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $t->put_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" => json => $put_data ) ->status_is(404) @@ -260,7 +261,8 @@ subtest "Test endpoints with permission" => sub { ->json_is([]); $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id2" ) - ->status_is(200); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) ->status_is(201) @@ -287,7 +289,7 @@ subtest "Test endpoints with permission" => sub { }; subtest 'Reserves with itemtype' => sub { - plan tests => 9; + plan tests => 10; my $post_data = { patron_id => int($patron_1->borrowernumber), @@ -297,7 +299,8 @@ subtest 'Reserves with itemtype' => sub { }; $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" ) - ->status_is(200); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) ->status_is(201) @@ -427,8 +430,8 @@ subtest 'suspend and resume tests' => sub { ); $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" ) - ->status_is( 204, "Correct status when deleting a resource" ) - ->json_is( undef ); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); # Pass a an expiration date for the suspension my $date = dt_from_string()->add( days => 5 ); @@ -445,8 +448,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, "Correct status when deleting a resource" ) - ->json_is( undef ); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $hold->set_waiting->discard_changes; diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index a18d364dee..5a76988fae 100644 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -342,7 +342,7 @@ subtest 'delete() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access test' => sub { - plan tests => 4; + plan tests => 5; $schema->storage->txn_begin; @@ -363,7 +363,8 @@ subtest 'delete() tests' => sub { my $patron = $builder->build_object({ class => 'Koha::Patrons' }); $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) - ->status_is(200, 'Patron deleted successfully'); + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); $schema->storage->txn_rollback; }; -- 2.26.0