3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Test::More tests => 2;
25 use t::lib::TestBuilder;
31 my $schema = Koha::Database->new->schema;
32 my $builder = t::lib::TestBuilder->new;
34 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
36 my $t = Test::Mojo->new('Koha::REST::V1');
38 subtest 'get() tests' => sub {
42 $schema->storage->txn_begin;
44 my $patron = $builder->build_object(
46 class => 'Koha::Patrons',
47 value => { flags => 0 }
50 my $password = 'thePassword123';
51 $patron->set_password( { password => $password, skip_validation => 1 } );
52 $patron->discard_changes;
53 my $userid = $patron->userid;
55 my $biblio = $builder->build_sample_biblio({
56 title => 'The unbearable lightness of being',
57 author => 'Milan Kundera'
59 $t->get_ok("//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber)
62 $patron->flags(4)->store;
64 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
65 => { Accept => 'application/weird+format' } )
67 ->json_is( [ "application/json",
68 "application/marcxml+xml",
69 "application/marc-in-json",
70 "application/marc" ] );
72 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
73 => { Accept => 'application/json' } )
75 ->json_is( '/title', 'The unbearable lightness of being' )
76 ->json_is( '/author', 'Milan Kundera' );
78 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
79 => { Accept => 'application/marcxml+xml' } )
82 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
83 => { Accept => 'application/marc-in-json' } )
86 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
87 => { Accept => 'application/marc' } )
91 $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber
92 => { Accept => 'application/marc' } )
94 ->json_is( '/error', 'Object not found.' );
96 $schema->storage->txn_rollback;
99 subtest 'delete() tests' => sub {
103 $schema->storage->txn_begin;
105 my $patron = $builder->build_object(
107 class => 'Koha::Patrons',
108 value => { flags => 0 } # no permissions
111 my $password = 'thePassword123';
112 $patron->set_password( { password => $password, skip_validation => 1 } );
113 my $userid = $patron->userid;
115 my $item = $builder->build_sample_item();
116 my $biblio_id = $item->biblionumber;
118 $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")
119 ->status_is(403, 'Not enough permissions makes it return the right code');
124 source => 'UserPermission',
126 borrowernumber => $patron->borrowernumber,
128 code => 'edit_catalogue'
134 # Bibs with items cannot be deleted
135 $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")
140 # Bibs with no items can be deleted
141 $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")
142 ->status_is(204, 'SWAGGER3.2.4')
143 ->content_is('', 'SWAGGER3.3.4');
145 $t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")
148 $schema->storage->txn_rollback;