From 2447a7c04de653bf5d28a08579bd35ee9f804c67 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 21 Oct 2021 15:33:54 -0300 Subject: [PATCH] Bug 28585: (QA follow-up) Add explicit tests for setting date/date-time attributes Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/patrons.t | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index d8dc2ff608..ed8e7bec13 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -189,7 +189,7 @@ subtest 'add() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 22; + plan tests => 24; $schema->storage->txn_begin; @@ -284,6 +284,11 @@ subtest 'add() tests' => sub { delete $newpatron->{anonymized}; $patron_to_delete->delete; + # Set a date field + $newpatron->{date_of_birth} = '1980-06-18'; + # Set a date-time field + $newpatron->{last_seen} = output_pref({ dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' }); + $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron) ->status_is(201, 'Patron created successfully') ->header_like( @@ -291,9 +296,11 @@ subtest 'add() tests' => sub { 'SWAGGER3.4.1' ) ->json_has('/patron_id', 'got a patron_id') - ->json_is( '/cardnumber' => $newpatron->{ cardnumber }) - ->json_is( '/surname' => $newpatron->{ surname }) - ->json_is( '/firstname' => $newpatron->{ firstname }); + ->json_is( '/cardnumber' => $newpatron->{ cardnumber }) + ->json_is( '/surname' => $newpatron->{ surname }) + ->json_is( '/firstname' => $newpatron->{ firstname }) + ->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' ) + ->json_is( '/last_seen' => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' ); warning_like { $t->post_ok("//$userid:$password@/api/v1/patrons" => json => $newpatron) @@ -432,7 +439,7 @@ subtest 'update() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 42; + plan tests => 44; $schema->storage->txn_begin; @@ -548,7 +555,6 @@ subtest 'update() tests' => sub { is_deeply($got, $newpatron, 'Returned patron from update matches expected'); t::lib::Dates::compare( $updated_on_got, $updated_on_expected, 'updated_on values matched' ); - is(Koha::Patrons->find( $patron_2->id )->cardnumber, $newpatron->{ cardnumber }, 'Patron is really updated!'); @@ -611,9 +617,16 @@ subtest 'update() tests' => sub { delete $newpatron->{email}; delete $newpatron->{secondary_email}; delete $newpatron->{altaddress_email}; + + # Set a date field + $newpatron->{date_of_birth} = '1980-06-18'; + # Set a date-time field + $newpatron->{last_seen} = output_pref({ dt => dt_from_string->add( days => -1 ), dateformat => 'rfc3339' }); + $t->put_ok( "//$userid:$password@/api/v1/patrons/" . $superlibrarian->borrowernumber => json => $newpatron ) - ->status_is(200, "Non-superlibrarian user can edit superlibrarian successfully if not changing email"); -# ->json_is( { error => "Not enough privileges to change a superlibrarian's email" } ); + ->status_is(200, "Non-superlibrarian user can edit superlibrarian successfully if not changing email") + ->json_is( '/date_of_birth' => $newpatron->{ date_of_birth }, 'Date field set (Bug 28585)' ) + ->json_is( '/last_seen' => $newpatron->{ last_seen }, 'Date-time field set (Bug 28585)' ); $schema->storage->txn_rollback; }; -- 2.33.1