Bug 25048: Regression tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 2 Apr 2020 21:38:33 +0000 (18:38 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 29 Apr 2020 15:24:37 +0000 (16:24 +0100)
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

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/api/v1/acquisitions_vendors.t
t/db_dependent/api/v1/cities.t
t/db_dependent/api/v1/holds.t
t/db_dependent/api/v1/patrons.t

index f61b592..6798688 100644 (file)
@@ -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 } );
index caaa0f0..720e643 100644 (file)
@@ -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);
index 8c3aa2f..f7436da 100644 (file)
@@ -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;
 
index a18d364..5a76988 100644 (file)
@@ -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;
     };