From c01323937daa30d446b760346618433ce74a74e3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 25 Jun 2021 09:57:11 -0300 Subject: [PATCH] Bug 28585: Regression tests This patch adds tests for filtering GET calls with date/date-time parameters. Tests fail because the feature is not working Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind --- t/db_dependent/api/v1/patrons.t | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 41f5681095..78ec764422 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -27,6 +27,7 @@ use t::lib::Mocks; use C4::Auth; use Koha::Database; +use Koha::DateUtils qw(dt_from_string output_pref); use Koha::Exceptions::Patron; use Koha::Exceptions::Patron::Attribute; use Koha::Patron::Attributes; @@ -46,7 +47,7 @@ subtest 'list() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 16; + plan tests => 17; $schema->storage->txn_begin; @@ -84,6 +85,34 @@ subtest 'list() tests' => sub { ->json_is( '/0/restricted' => Mojo::JSON->true ) ->json_hasnt('/1'); + subtest 'searching date and date-time fields' => sub { + + plan tests => 6; + + my $date_of_birth = '1980-06-18'; + my $last_seen = '2021-06-25 14:05:35'; + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + dateofbirth => $date_of_birth, + lastseen => $last_seen, + } + } + ); + + my $last_seen_rfc3339 = $last_seen . "z"; + + $t->get_ok("//$userid:$password@/api/v1/patrons?date_of_birth=" . $date_of_birth . "&cardnumber=" . $patron->cardnumber) + ->status_is(200) + ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date works' ); + + $t->get_ok("//$userid:$password@/api/v1/patrons?last_seen=" . $last_seen_rfc3339 . "&cardnumber=" . $patron->cardnumber) + ->status_is(200) + ->json_is( '/0/patron_id' => $patron->id, 'Filtering by date-time works' ); + }; + $schema->storage->txn_rollback; }; }; -- 2.20.1