Bug 24545: Fix license statements
[srvgit] / t / db_dependent / api / v1 / acquisitions_funds.t
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 => 13;
21 use Test::Mojo;
22 use t::lib::TestBuilder;
23 use t::lib::Mocks;
24
25 use C4::Budgets;
26
27 use Koha::Database;
28
29 my $schema  = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new();
31
32 $schema->storage->txn_begin;
33
34 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
35
36 my $t = Test::Mojo->new('Koha::REST::V1');
37
38 my $librarian = $builder->build_object({
39     class => 'Koha::Patrons',
40     value => { flags => 2052 }
41 });
42 my $password = 'thePassword123';
43 $librarian->set_password({ password => $password, skip_validation => 1 });
44 my $userid = $librarian->userid;
45
46 my $patron = $builder->build_object({
47     class => 'Koha::Patrons',
48     value => { flags => 0 }
49 });
50 my $unauth_password = 'thePassword123';
51 $patron->set_password({ password => $unauth_password, skip_validation => 1 });
52 my $unauth_userid = $patron->userid;
53
54 my $fund_name = 'Periodiques';
55
56 my $fund = $builder->build_object(
57     {
58         class => 'Koha::Acquisition::Funds',
59         value => {
60             budget_amount => '123.132000',
61             budget_name   => $fund_name,
62             budget_notes  => 'This is a note'
63         }
64     }
65 );
66
67 $t->get_ok('/api/v1/acquisitions/funds')
68   ->status_is(401);
69
70 $t->get_ok('/api/v1/acquisitions/funds/?name=testFund')
71   ->status_is(401);
72
73 $t->get_ok("//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds")
74   ->status_is(403);
75
76 $t->get_ok("//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds?name=" . $fund_name)
77   ->status_is(403);
78
79 $t->get_ok("//$userid:$password@/api/v1/acquisitions/funds")
80   ->status_is(200);
81
82 $t->get_ok("//$userid:$password@/api/v1/acquisitions/funds?name=" . $fund_name)
83   ->status_is(200)
84   ->json_like('/0/name' => qr/$fund_name/);
85
86 $schema->storage->txn_rollback;
87
88 1;