Bug 36988: Update unit tests

These highlight why we may have made this choice. With only 'edit_borrowers' you can make
changes, but you cannot view your changes as you aren't allowed to see other borrowers.

Test now pass, but not sure if this answers the question of why we did it this way, or if there is more
work here. Should you be able to get back the fields that you updated at the least, to confirm your changes? Or
should we send a success with a message that you can't see the data?

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2024-05-30 06:55:32 -04:00 committed by Lucas Gass
parent 9348047f10
commit 27e34e630c
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 27 additions and 11 deletions

View File

@ -1015,9 +1015,29 @@ subtest 'update() tests' => sub {
my $authorized_patron = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 1 }
value => { flags => 2**2 } # catalog only, no additional permissions
}
);
my $superlibrarian = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 1 } # superlibrarian
}
);
# Ensure our librarian can see users from all branches (once list_borrowers is added)
$builder->build(
{
source => 'UserPermission',
value => {
borrowernumber => $authorized_patron->borrowernumber,
module_bit => 4,
code => 'edit_borrowers',
},
}
);
my $password = 'thePassword123';
$authorized_patron->set_password( { password => $password, skip_validation => 1 } );
my $userid = $authorized_patron->userid;
@ -1033,7 +1053,10 @@ subtest 'update() tests' => sub {
my $patron_1 = $authorized_patron;
my $patron_2 = $unauthorized_patron;
my $newpatron = $unauthorized_patron->to_api( { user => $authorized_patron } );
my $newpatron = $unauthorized_patron->to_api( { user => $superlibrarian } )
; # Need to use a patron with ability to view the patron
my $blanked_patron = $unauthorized_patron->to_api( { user => $authorized_patron } )
; # The api return will blank since we can't see, only update
# delete RO attributes
delete $newpatron->{patron_id};
@ -1126,8 +1149,8 @@ subtest 'update() tests' => sub {
my $got = $result->tx->res->json;
my $updated_on_got = delete $got->{updated_on};
my $updated_on_expected = delete $newpatron->{updated_on};
is_deeply( $got, $newpatron, 'Returned patron from update matches expected' );
my $updated_on_expected = delete $blanked_patron->{updated_on};
is_deeply( $got, $blanked_patron, 'Returned patron from update matches expected' );
is(
t::lib::Dates::compare(
dt_from_string( $updated_on_got, 'rfc3339' ),
@ -1142,13 +1165,6 @@ subtest 'update() tests' => sub {
$newpatron->{cardnumber}, 'Patron is really updated!'
);
my $superlibrarian = $builder->build_object(
{
class => 'Koha::Patrons',
value => { flags => 1 }
}
);
$newpatron->{cardnumber} = $superlibrarian->cardnumber;
$newpatron->{userid} = $superlibrarian->userid;
$newpatron->{email} = 'nosense@no.no';