Line 0
Link Here
|
0 |
- |
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 Test::More tests => 1; |
21 |
use Test::Mojo; |
22 |
|
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks; |
25 |
|
26 |
use Koha::AuthorisedValues; |
27 |
use Koha::Database; |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
33 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
34 |
|
35 |
subtest 'list_av_from_category() tests' => sub { |
36 |
|
37 |
plan tests => 11; |
38 |
|
39 |
$schema->storage->txn_begin; |
40 |
|
41 |
my $librarian = $builder->build_object( |
42 |
{ |
43 |
class => 'Koha::Patrons', |
44 |
value => { flags => 2 ** 2 } # catalogue flag = 2 |
45 |
} |
46 |
); |
47 |
my $password = 'thePassword123'; |
48 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
49 |
my $userid = $librarian->userid; |
50 |
|
51 |
my $patron = $builder->build_object( |
52 |
{ |
53 |
class => 'Koha::Patrons', |
54 |
value => { flags => 0 } |
55 |
} |
56 |
); |
57 |
|
58 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
59 |
my $unauth_userid = $patron->userid; |
60 |
|
61 |
## Authorized user tests |
62 |
# No category, 404 expected |
63 |
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/NON_EXISTS/values") |
64 |
->status_is(404) |
65 |
->json_is( '/error' => 'Category not found' ); |
66 |
|
67 |
my $av_cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories' })->category_name; |
68 |
|
69 |
# No AVs, so empty array should be returned |
70 |
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/values") |
71 |
->status_is(200) |
72 |
->json_is( [] ); |
73 |
|
74 |
my $av = $builder->build_object( |
75 |
{ class => 'Koha::AuthorisedValues', value => { category => $av_cat } } ); |
76 |
|
77 |
# One av created, should get returned |
78 |
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/values") |
79 |
->status_is(200) |
80 |
->json_is( [$av->to_api] ); |
81 |
|
82 |
# Unauthorized access |
83 |
$t->get_ok("//$unauth_userid:$password@/api/v1/authorised_value_categories/$av_cat/values") |
84 |
->status_is(403); |
85 |
|
86 |
$schema->storage->txn_rollback; |
87 |
}; |