Bug 35797: Syspref, schema path file and tests changes
1- Corrected tests according to the comments 2- Removed unused import 3- Added syspref check of 'patronimages' 4- Tweaked swagger path schema Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
ad190dcc5d
commit
b590f1a0a3
|
|
@ -23,8 +23,6 @@ use Koha::Patrons;
|
|||
|
||||
use Try::Tiny qw( catch try );
|
||||
|
||||
use MIME::Base64 qw( encode_base64 );
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::REST::V1::Patrons::Image
|
||||
|
|
@ -42,6 +40,13 @@ Controller method that gets a patron's image
|
|||
sub get {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
unless ( C4::Context->preference('patronimages') ) {
|
||||
return $c->render(
|
||||
status => 403,
|
||||
openapi => { error => "Patron images are disabled." }
|
||||
);
|
||||
}
|
||||
|
||||
my $patron = Koha::Patrons->find( $c->param('patron_id') );
|
||||
|
||||
unless ($patron) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@
|
|||
- image/png
|
||||
responses:
|
||||
"200":
|
||||
description: Patron's image
|
||||
description: Patron image
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
"401":
|
||||
description: Authentication required
|
||||
schema:
|
||||
|
|
|
|||
|
|
@ -35,14 +35,34 @@ my $t = Test::Mojo->new('Koha::REST::V1');
|
|||
|
||||
subtest 'Image tests' => sub {
|
||||
|
||||
plan tests => 16;
|
||||
plan tests => 19;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $privileged_patron = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { flags => 1 }
|
||||
value => { flags => 0 }
|
||||
}
|
||||
);
|
||||
$builder->build(
|
||||
{
|
||||
source => 'UserPermission',
|
||||
value => {
|
||||
borrowernumber => $privileged_patron->borrowernumber,
|
||||
module_bit => 4,
|
||||
code => 'list_borrowers',
|
||||
},
|
||||
}
|
||||
);
|
||||
$builder->build(
|
||||
{
|
||||
source => 'UserPermission',
|
||||
value => {
|
||||
borrowernumber => $privileged_patron->borrowernumber,
|
||||
module_bit => 4,
|
||||
code => 'edit_borrowers',
|
||||
},
|
||||
}
|
||||
);
|
||||
my $password = 'thePassword123';
|
||||
|
|
@ -50,6 +70,12 @@ subtest 'Image tests' => sub {
|
|||
my $userid = $privileged_patron->userid;
|
||||
my $borrowernumber = $privileged_patron->borrowernumber;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons/$borrowernumber/default_image")
|
||||
->status_is(403)
|
||||
->json_is( '/error' => 'Patron images are disabled.' );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'patronimages', 1 );
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons/$borrowernumber/default_image")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Patron image not found.' );
|
||||
|
|
@ -58,9 +84,9 @@ subtest 'Image tests' => sub {
|
|||
my $non_existent_patron_borrower_number = $non_existent_patron->borrowernumber;
|
||||
$non_existent_patron->delete;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/patrons/" . $non_existent_patron_borrower_number . '/checkouts' )
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons/$non_existent_patron_borrower_number/default_image")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Patron not found' );
|
||||
->json_is( '/error' => 'Patron not found.' );
|
||||
|
||||
my $new_image = Koha::Patron::Image->new(
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue