|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 35; |
20 |
use Test::More tests => 36; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
|
Lines 281-286
subtest 'test sorting, limit and offset' => sub {
Link Here
|
| 281 |
->json_is('/records/3/issue_id' => $issue4->issue_id); |
281 |
->json_is('/records/3/issue_id' => $issue4->issue_id); |
| 282 |
}; |
282 |
}; |
| 283 |
|
283 |
|
|
|
284 |
subtest 'delete() tests' => sub { |
| 285 |
plan tests => 8; |
| 286 |
|
| 287 |
my $anonymous_patron = $builder->build({ |
| 288 |
source => 'Borrower' |
| 289 |
})->{borrowernumber}; |
| 290 |
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_patron); |
| 291 |
|
| 292 |
my $id = Koha::Old::Checkouts->search({}, { |
| 293 |
order_by => {'-desc' => 'issue_id'}})->next; |
| 294 |
$id = ($id) ? $id->issue_id+1 : 1; |
| 295 |
|
| 296 |
my $issue1 = Koha::Old::Checkout->new({ |
| 297 |
issue_id => $id, |
| 298 |
borrowernumber => $nopermission->{borrowernumber}, |
| 299 |
itemnumber => $itemnumber1, |
| 300 |
})->store; |
| 301 |
my $issue2 = Koha::Old::Checkout->new({ |
| 302 |
issue_id => $id+1, |
| 303 |
borrowernumber => $nopermission->{borrowernumber}, |
| 304 |
itemnumber => $itemnumber1, |
| 305 |
})->store; |
| 306 |
|
| 307 |
$tx = $t->ua->build_tx(DELETE => "/api/v1/checkouts/history" |
| 308 |
."?borrowernumber=".($borrowernumber+1)); |
| 309 |
$tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); |
| 310 |
$t->request_ok($tx) |
| 311 |
->status_is(403); |
| 312 |
|
| 313 |
$tx = $t->ua->build_tx(DELETE => "/api/v1/checkouts/history" |
| 314 |
."?borrowernumber=".$nopermission->{borrowernumber}); |
| 315 |
$tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id}); |
| 316 |
$t->request_ok($tx) |
| 317 |
->status_is(200); |
| 318 |
|
| 319 |
is(Koha::Old::Checkouts->search({ |
| 320 |
borrowernumber => $anonymous_patron, |
| 321 |
issue_id => { 'in' => [$id, $id+1] } |
| 322 |
})->count, 2, 'Found anonymized checkouts (anonymous patron)'); |
| 323 |
|
| 324 |
t::lib::Mocks::mock_preference('AnonymousPatron', undef); |
| 325 |
|
| 326 |
$tx = $t->ua->build_tx(DELETE => "/api/v1/checkouts/history" |
| 327 |
."?borrowernumber=$anonymous_patron"); |
| 328 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
| 329 |
$t->request_ok($tx) |
| 330 |
->status_is(200); |
| 331 |
|
| 332 |
is(Koha::Old::Checkouts->search({ |
| 333 |
borrowernumber => undef, |
| 334 |
issue_id => { 'in' => [$id, $id+1] } |
| 335 |
})->count, 2, 'Found anonymized checkouts (undef patron)'); |
| 336 |
}; |
| 337 |
|
| 284 |
Koha::Patrons->find($borrowernumber)->delete(); |
338 |
Koha::Patrons->find($borrowernumber)->delete(); |
| 285 |
|
339 |
|
| 286 |
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber"); |
340 |
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber"); |
| 287 |
- |
|
|