Bug 17932: (followup) Fix /patrons endpoint

Bug 17927 introduced data type fixes on the /patrons endpoint (integer
and boolean types got fixed). This led to the /patrons endpoint not to
work because the underlying code didn't provide the right data.

With the introduction of TO_JSON on Koha::Object(s) we now have a way to
output the proper data types.

This patch does so by:
- Adding is_boolean => 1 to the relevant columns on the Borrower.pm
  schema file.
- Tweaking the controller class for the /patrons endpoint so it doesn't
  use the $object(s)->unblessed call but just let the Mojo::JSON library
  pick out TO_JSON implementation instead on rendering the output.
- It adds a new test for booleans.

To test:
- Have 17927 applied
- Run:
  $ prove t/db_dependent/api/v1/patrons.t
=> FAIL: Tests fail [1]
- Apply this patches
- Run:
  $ prove t/db_dependent/api/v1/patrons.t
=> SUCCESS: Tests pass!
- Sign off! :-D

[1] It is self explanatory to just try the API using any of the
available tools (I use HttpRequester on Firefox)

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2017-01-23 09:47:54 -03:00 committed by Kyle M Hall
parent 51f62ccb30
commit 39d090a8b6
3 changed files with 12 additions and 5 deletions

View File

@ -28,7 +28,7 @@ sub list {
my $patrons = Koha::Patrons->search;
$c->$cb($patrons->unblessed, 200);
$c->$cb($patrons, 200);
}
sub get {
@ -41,7 +41,7 @@ sub get {
return $c->$cb({error => "Patron not found"}, 404);
}
return $c->$cb($patron->unblessed, 200);
return $c->$cb($patron, 200);
}
1;

View File

@ -1343,6 +1343,11 @@ __PACKAGE__->belongs_to(
{ borrowernumber => "guarantorid" },
);
__PACKAGE__->add_columns(
'+lost' => { is_boolean => 1 },
'+gonenoaddress' => { is_boolean => 1 }
);
sub koha_objects_class {
'Koha::Patrons';
}

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 20;
use Test::More tests => 21;
use Test::Mojo;
use t::lib::TestBuilder;
@ -52,7 +52,8 @@ my $borrower = $builder->build({
branchcode => $branchcode,
categorycode => $categorycode,
flags => 0,
guarantorid => $guarantor->{borrowernumber},
lost => 1,
guarantorid => $guarantor->{borrowernumber},
}
});
@ -127,6 +128,7 @@ $tx->req->cookies({name => 'CGISESSID', value => $session->id});
$t->request_ok($tx)
->status_is(200)
->json_is('/borrowernumber' => $borrower->{ borrowernumber })
->json_is('/surname' => $borrower->{ surname });
->json_is('/surname' => $borrower->{ surname })
->json_is('/lost' => 1 );
$dbh->rollback;