Bug 29290: Unit tests
This patch adds unit tests for the new route. All behaviors are tested: To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/api/v1/biblios.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
8fdd52b17c
commit
c9fc07aee3
1 changed files with 66 additions and 1 deletions
|
@ -20,7 +20,7 @@ use Modern::Perl;
|
|||
use utf8;
|
||||
use Encode;
|
||||
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 7;
|
||||
use Test::MockModule;
|
||||
use Test::Mojo;
|
||||
use Test::Warn;
|
||||
|
@ -29,8 +29,12 @@ use t::lib::Mocks;
|
|||
use t::lib::TestBuilder;
|
||||
|
||||
use C4::Auth;
|
||||
use C4::Circulation qw( AddIssue AddReturn );
|
||||
|
||||
use Koha::Biblios;
|
||||
use Koha::Database;
|
||||
use Koha::Checkouts;
|
||||
use Koha::Old::Checkouts;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my $builder = t::lib::TestBuilder->new;
|
||||
|
@ -578,3 +582,64 @@ subtest 'get_items_public() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'get_checkouts() tests' => sub {
|
||||
|
||||
plan tests => 14;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $patron = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { flags => 0 }
|
||||
}
|
||||
);
|
||||
my $password = 'thePassword123';
|
||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
$patron->discard_changes;
|
||||
my $userid = $patron->userid;
|
||||
|
||||
my $biblio = $builder->build_sample_biblio();
|
||||
$t->get_ok("//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
|
||||
->status_is(403);
|
||||
|
||||
$patron->flags(1)->store; # circulate permissions
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
|
||||
->status_is(200)
|
||||
->json_is( '' => [], 'No checkouts on the biblio' );
|
||||
|
||||
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
|
||||
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
|
||||
|
||||
AddIssue( $patron->unblessed, $item_1->barcode );
|
||||
AddIssue( $patron->unblessed, $item_2->barcode );
|
||||
|
||||
my $ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
my $checkout_1 = Koha::Checkouts->find({ itemnumber => $item_1->id });
|
||||
my $checkout_2 = Koha::Checkouts->find({ itemnumber => $item_2->id });
|
||||
|
||||
is_deeply( $ret, [ $checkout_1->to_api, $checkout_2->to_api ] );
|
||||
|
||||
AddReturn( $item_1->barcode );
|
||||
|
||||
$ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts")
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
is_deeply( $ret, [ $checkout_2->to_api ] );
|
||||
|
||||
$ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts?checked_in=1")
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
my $old_checkout_1 = Koha::Old::Checkouts->find( $checkout_1->id );
|
||||
|
||||
is_deeply( $ret, [ $old_checkout_1->to_api ] );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue