Bug 24487: Regresion test
authorAgustin Moyano <agustinmoyano@theke.io>
Wed, 22 Jan 2020 23:44:04 +0000 (20:44 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 30 Jan 2020 15:34:46 +0000 (15:34 +0000)
This patch introduces a regresion test where a path parameter is combined with 'contains' match criteria

To test:
1. apply this patch
2. prove t/db_dependent/Koha/REST/Plugin/Objects.t

Test should fail at this point.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/Koha/REST/Plugin/Objects.t

index 2e162b2..a25eb21 100644 (file)
@@ -19,6 +19,7 @@ use Modern::Perl;
 
 use Koha::Acquisition::Orders;
 use Koha::Cities;
+use Koha::Holds;
 
 # Dummy app for testing the plugin
 use Mojolicious::Lite;
@@ -44,8 +45,18 @@ get '/orders' => sub {
     $c->render( status => 200, json => $orders );
 };
 
+get '/patrons/:patron_id/holds' => sub {
+    my $c = shift;
+    my $params = $c->req->params->to_hash;
+    $params->{patron_id} = $c->stash("patron_id");
+    $c->validation->output($params);
+    my $holds_set = Koha::Holds->new;
+    my $holds     = $c->objects->search( $holds_set );
+    $c->render( status => 200, json => {count => scalar(@$holds)} );
+};
+
 # The tests
-use Test::More tests => 3;
+use Test::More tests => 4;
 use Test::Mojo;
 
 use t::lib::TestBuilder;
@@ -176,3 +187,21 @@ subtest 'objects.search helper, embed' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'objects.search helper, with path parameters and _match' => sub {
+    plan tests => 4;
+
+    $schema->storage->txn_begin;
+
+    Koha::Holds->search()->delete;
+
+    $builder->build_object({class=>"Koha::Holds", value => {borrowernumber => 10 }});
+
+    $t->get_ok('/patrons/1/holds?_match=exact')
+      ->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=exact');
+
+    $t->get_ok('/patrons/1/holds?_match=contains')
+      ->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=contains');
+
+    $schema->storage->txn_rollback;
+};