e9e6537fae
GET /api/v1/items/{item_id} Gets one Item This patch adds route to get one item from koha.items table. To test: 1. Apply patch 2. Open a browser tab on Koha staff and log in (to create CGISESSID cookie). 3. Send GET request to http://yourlibrary/api/v1/items/YYY where YYY is an existing itemnumber. 4. Make sure the returned data is correct. 5. Run unit tests in t/db_dependent/api/v1/items.t Sponsored-by: Koha-Suomi Oy Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Johanna Raisa <johanna.raisa@gmail.com> Signed-off-by: Michal Denar <black23@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
81 lines
2.4 KiB
Perl
81 lines
2.4 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
# Copyright 2016 Koha-Suomi
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it under the
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along
|
|
# with Koha; if not, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
use Modern::Perl;
|
|
|
|
use Test::More tests => 1;
|
|
use Test::Mojo;
|
|
use Test::Warn;
|
|
|
|
use t::lib::TestBuilder;
|
|
use t::lib::Mocks;
|
|
|
|
use C4::Auth;
|
|
use Koha::Items;
|
|
use Koha::Database;
|
|
|
|
my $schema = Koha::Database->new->schema;
|
|
my $builder = t::lib::TestBuilder->new;
|
|
|
|
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
|
|
|
|
my $t = Test::Mojo->new('Koha::REST::V1');
|
|
|
|
subtest 'get() tests' => sub {
|
|
|
|
plan tests => 9;
|
|
|
|
$schema->storage->txn_begin;
|
|
|
|
my $item = $builder->build_object( { class => 'Koha::Items' } );
|
|
my $patron = $builder->build_object({
|
|
class => 'Koha::Patrons',
|
|
value => { flags => 4 }
|
|
});
|
|
|
|
my $nonprivilegedpatron = $builder->build_object({
|
|
class => 'Koha::Patrons',
|
|
value => { flags => 0 }
|
|
});
|
|
|
|
my $password = 'thePassword123';
|
|
|
|
$nonprivilegedpatron->set_password({ password => $password, skip_validation => 1 });
|
|
my $userid = $nonprivilegedpatron->userid;
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber )
|
|
->status_is(403)
|
|
->json_is( '/error' => 'Authorization failure. Missing required permission(s).' );
|
|
|
|
$patron->set_password({ password => $password, skip_validation => 1 });
|
|
$userid = $patron->userid;
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber )
|
|
->status_is( 200, 'SWAGGER3.2.2' )
|
|
->json_is( '' => Koha::REST::V1::Items::_to_api( $item->TO_JSON ), 'SWAGGER3.3.2' );
|
|
|
|
my $non_existent_code = $item->itemnumber;
|
|
$item->delete;
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code )
|
|
->status_is(404)
|
|
->json_is( '/error' => 'Item not found' );
|
|
|
|
$schema->storage->txn_rollback;
|
|
};
|