3 # This file is part of Koha.
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.
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.
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>.
20 use Test::More tests => 28;
23 use t::lib::TestBuilder;
26 use Koha::BackgroundJobs;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 my $t = Test::Mojo->new('Koha::REST::V1');
34 #my $t = t::lib::Mojo->new('Koha::REST::V1');
35 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
37 $schema->storage->txn_begin;
39 Koha::BackgroundJobs->delete;
40 my $superlibrarian = $builder->build_object(
42 class => 'Koha::Patrons',
43 value => { flags => 1 },
46 my $password = 'thePassword123';
47 $superlibrarian->set_password( { password => $password, skip_validation => 1 } );
48 my $superlibrarian_userid = $superlibrarian->userid;
50 my $librarian = $builder->build_object(
52 class => 'Koha::Patrons',
53 value => { flags => 2 ** 2 }, # catalogue flag = 2
56 $librarian->set_password( { password => $password, skip_validation => 1 } );
57 my $librarian_userid = $librarian->userid;
59 my $patron = $builder->build_object(
61 class => 'Koha::Patrons',
62 value => { flags => 0 },
65 $patron->set_password( { password => $password, skip_validation => 1 } );
66 my $patron_userid = $patron->userid;
68 $t->get_ok("//$librarian_userid:$password@/api/v1/jobs")
72 my $job = $builder->build_object(
74 class => 'Koha::BackgroundJobs',
79 borrowernumber => $patron->borrowernumber,
80 type => 'batch_item_record_modification',
82 #data => '{"record_ids":["1"],"regex_mod":null,"exclude_from_local_holds_priority":null,"new_values":{"itemnotes":"xxx"}}' ,
83 data => '{"regex_mod":null,"report":{"total_records":1,"modified_fields":1,"modified_itemnumbers":[1]},"new_values":{"itemnotes":"xxx"},"record_ids":["1"],"exclude_from_local_holds_priority":null}',
89 $t->get_ok("//$superlibrarian_userid:$password@/api/v1/jobs")
90 ->status_is(200)->json_is( [ $job->to_api ] );
92 $t->get_ok("//$librarian_userid:$password@/api/v1/jobs")
93 ->status_is(200)->json_is( [] );
95 $t->get_ok("//$patron_userid:$password@/api/v1/jobs")
98 $job->borrowernumber( $librarian->borrowernumber )->store;
100 $t->get_ok("//$librarian_userid:$password@/api/v1/jobs")
101 ->status_is(200)->json_is( [ $job->to_api ] );
103 $t->get_ok("//$librarian_userid:$password@/api/v1/jobs?only_current=1")
104 ->status_is(200)->json_is( [] );
108 $t->get_ok( "//$superlibrarian_userid:$password@/api/v1/jobs/"
109 . $job->id )->status_is(200)
110 ->json_is( $job->to_api );
112 $t->get_ok( "//$librarian_userid:$password@/api/v1/jobs/"
113 . $job->id )->status_is(200)
114 ->json_is( $job->to_api );
116 $job->borrowernumber( $superlibrarian->borrowernumber )->store;
117 $t->get_ok( "//$librarian_userid:$password@/api/v1/jobs/"
118 . $job->id )->status_is(403);
123 $t->get_ok( "//$superlibrarian_userid:$password@/api/v1/jobs/"
124 . $job->id )->status_is(404)
125 ->json_is( '/error' => 'Object not found' );
128 $schema->storage->txn_rollback;