Lines 194-200
subtest 'list() tests' => sub {
Link Here
|
194 |
}; |
194 |
}; |
195 |
|
195 |
|
196 |
subtest 'get() tests' => sub { |
196 |
subtest 'get() tests' => sub { |
197 |
plan tests => 2; |
197 |
|
|
|
198 |
plan tests => 3; |
198 |
|
199 |
|
199 |
$schema->storage->txn_begin; |
200 |
$schema->storage->txn_begin; |
200 |
unauthorized_access_tests('GET', -1, undef); |
201 |
unauthorized_access_tests('GET', -1, undef); |
Lines 226-231
subtest 'get() tests' => sub {
Link Here
|
226 |
|
227 |
|
227 |
$schema->storage->txn_rollback; |
228 |
$schema->storage->txn_rollback; |
228 |
}; |
229 |
}; |
|
|
230 |
|
231 |
subtest 'search_limited() tests' => sub { |
232 |
|
233 |
plan tests => 12; |
234 |
|
235 |
$schema->storage->txn_begin; |
236 |
|
237 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
238 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
239 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
240 |
|
241 |
my $patron_1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_1->id } }); |
242 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_2->id } }); |
243 |
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library_3->id } }); |
244 |
|
245 |
my @libraries_where_can_see_patrons = ($library_1->id, $library_2->id); |
246 |
|
247 |
my $mocked_patron = Test::MockModule->new('Koha::Patron'); |
248 |
$mocked_patron->mock( 'libraries_where_can_see_patrons', sub |
249 |
{ |
250 |
return @libraries_where_can_see_patrons; |
251 |
} |
252 |
); |
253 |
|
254 |
my $librarian = $builder->build_object( |
255 |
{ class => 'Koha::Patrons', |
256 |
value => { flags => 2**4, branchcode => $library_3->id } # borrowers flag = 4 |
257 |
} |
258 |
); |
259 |
my $password = 'thePassword123'; |
260 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
261 |
my $userid = $librarian->userid; |
262 |
|
263 |
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_1->id ) |
264 |
->status_is(200) |
265 |
->json_is( '/patron_id' => $patron_1->id ); |
266 |
|
267 |
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_2->id ) |
268 |
->status_is(200) |
269 |
->json_is( '/patron_id' => $patron_2->id ); |
270 |
|
271 |
@libraries_where_can_see_patrons = ($library_1->id); |
272 |
|
273 |
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_1->id ) |
274 |
->status_is(200) |
275 |
->json_is( '/patron_id' => $patron_1->id ); |
276 |
|
277 |
$t->get_ok("//$userid:$password@/api/v1/patrons/" . $patron_2->id ) |
278 |
->status_is(404) |
279 |
->json_is({ error => "Patron not found." }); |
280 |
|
281 |
$schema->storage->txn_rollback; |
282 |
}; |
229 |
}; |
283 |
}; |
230 |
|
284 |
|
231 |
subtest 'add() tests' => sub { |
285 |
subtest 'add() tests' => sub { |
232 |
- |
|
|