3 # Copyright 2016 Koha-Suomi
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use Test::More tests => 1;
26 use t::lib::TestBuilder;
33 my $schema = Koha::Database->new->schema;
34 my $builder = t::lib::TestBuilder->new;
36 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
38 my $t = Test::Mojo->new('Koha::REST::V1');
40 subtest 'get() tests' => sub {
44 $schema->storage->txn_begin;
46 my $item = $builder->build_object( { class => 'Koha::Items' } );
47 my $patron = $builder->build_object({
48 class => 'Koha::Patrons',
49 value => { flags => 4 }
52 my $nonprivilegedpatron = $builder->build_object({
53 class => 'Koha::Patrons',
54 value => { flags => 0 }
57 my $password = 'thePassword123';
59 $nonprivilegedpatron->set_password({ password => $password, skip_validation => 1 });
60 my $userid = $nonprivilegedpatron->userid;
62 $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber )
64 ->json_is( '/error' => 'Authorization failure. Missing required permission(s).' );
66 $patron->set_password({ password => $password, skip_validation => 1 });
67 $userid = $patron->userid;
69 $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber )
70 ->status_is( 200, 'SWAGGER3.2.2' )
71 ->json_is( '' => Koha::REST::V1::Items::_to_api( $item->TO_JSON ), 'SWAGGER3.3.2' );
73 my $non_existent_code = $item->itemnumber;
76 $t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code )
78 ->json_is( '/error' => 'Item not found' );
80 $schema->storage->txn_rollback;