Line 0
Link Here
|
|
|
1 |
#!/usr/bin/env perl |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use utf8; |
21 |
use Encode; |
22 |
|
23 |
use Test::More tests => 1; |
24 |
use Test::MockModule; |
25 |
use Test::Mojo; |
26 |
use Test::Warn; |
27 |
use JSON; |
28 |
|
29 |
use t::lib::Mocks; |
30 |
use t::lib::TestBuilder; |
31 |
|
32 |
use C4::Auth; |
33 |
|
34 |
use Koha::Biblios; |
35 |
use Koha::Database; |
36 |
|
37 |
my $schema = Koha::Database->new->schema; |
38 |
my $builder = t::lib::TestBuilder->new; |
39 |
|
40 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
41 |
|
42 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
43 |
|
44 |
subtest 'get() tests' => sub { |
45 |
plan tests => 13; |
46 |
|
47 |
$schema->storage->txn_begin; |
48 |
$schema->resultset('Biblio')->delete(); |
49 |
|
50 |
my $patron = $builder->build_object( |
51 |
{ |
52 |
class => 'Koha::Patrons', |
53 |
value => { flags => 0 } |
54 |
} |
55 |
); |
56 |
my $password = 'thePassword123'; |
57 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
58 |
$patron->discard_changes; |
59 |
my $userid = $patron->userid; |
60 |
|
61 |
my $biblio = $builder->build_sample_biblio({ |
62 |
title => 'The unbearable lightness of being', |
63 |
author => 'Milan Kundera', |
64 |
isbn => '0-06-093213-9', |
65 |
}); |
66 |
$t->get_ok("//$userid:$password@/api/v1/biblios") |
67 |
->status_is(403); |
68 |
|
69 |
$patron->flags(4)->store; |
70 |
|
71 |
$t->get_ok("//$userid:$password@/api/v1/biblios") |
72 |
->status_is(200) |
73 |
->json_is( '/0/title', 'The unbearable lightness of being' ) |
74 |
->json_is( '/0/author', 'Milan Kundera' ) |
75 |
->json_is( '/0/isbn', '0-06-093213-9' ); |
76 |
|
77 |
# Test the ability to filter using biblioitems columns |
78 |
my $api_filter = encode_json({'biblioitem.isbn' => '123'}); |
79 |
$t->get_ok("//$userid:$password@/api/v1/biblios?q=$api_filter") |
80 |
->status_is(200) |
81 |
->json_hasnt('/0'); |
82 |
|
83 |
$api_filter = encode_json({'biblioitem.isbn' => '0-06-093213-9'}); |
84 |
$t->get_ok("//$userid:$password@/api/v1/biblios?q=$api_filter") |
85 |
->status_is(200) |
86 |
->json_is('/0/isbn', '0-06-093213-9'); |
87 |
|
88 |
$schema->storage->txn_rollback; |
89 |
}; |