|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
|
|
23 |
use Test::MockModule; |
| 23 |
use Test::Mojo; |
24 |
use Test::Mojo; |
| 24 |
use Test::Warn; |
25 |
use Test::Warn; |
| 25 |
|
26 |
|
|
Lines 187-192
subtest 'get() tests' => sub {
Link Here
|
| 187 |
$schema->storage->txn_rollback; |
188 |
$schema->storage->txn_rollback; |
| 188 |
}; |
189 |
}; |
| 189 |
|
190 |
|
|
|
191 |
subtest 'delete() tests' => sub { |
| 192 |
|
| 193 |
plan tests => 23; |
| 194 |
|
| 195 |
$schema->storage->txn_begin; |
| 196 |
|
| 197 |
my $fail = 0; |
| 198 |
my $expected_error; |
| 199 |
|
| 200 |
# we want to control all the safe_to_delete use cases |
| 201 |
my $item_class = Test::MockModule->new('Koha::Item'); |
| 202 |
$item_class->mock( 'safe_to_delete', sub { |
| 203 |
if ( $fail ) { |
| 204 |
return Koha::Result::Boolean->new(0)->add_message({ message => $expected_error }); |
| 205 |
} |
| 206 |
else { |
| 207 |
return Koha::Result::Boolean->new(1); |
| 208 |
} |
| 209 |
}); |
| 210 |
|
| 211 |
my $librarian = $builder->build_object( |
| 212 |
{ |
| 213 |
class => 'Koha::Patrons', |
| 214 |
value => { flags => 2**9 } # catalogue flag = 2 |
| 215 |
} |
| 216 |
); |
| 217 |
my $password = 'thePassword123'; |
| 218 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 219 |
my $userid = $librarian->userid; |
| 220 |
|
| 221 |
my $item = $builder->build_sample_item; |
| 222 |
|
| 223 |
my $errors = { |
| 224 |
book_on_loan => { code => 'checked_out', description => 'The item is checked out' }, |
| 225 |
book_reserved => { code => 'found_hold', description => 'Waiting or in-transit hold for the item' }, |
| 226 |
last_item_for_hold => { code => 'last_item_for_hold', description => 'The item is the last one on a record on which a biblio-level hold is placed' }, |
| 227 |
linked_analytics => { code => 'linked_analytics', description => 'The item has linked analytic records' }, |
| 228 |
not_same_branch => { code => 'not_same_branch', description => 'The item is blocked by independent branches' }, |
| 229 |
}; |
| 230 |
|
| 231 |
$fail = 1; |
| 232 |
|
| 233 |
foreach my $error_code ( keys %{$errors} ) { |
| 234 |
|
| 235 |
$expected_error = $error_code; |
| 236 |
|
| 237 |
$t->delete_ok( "//$userid:$password@/api/v1/items/" . $item->id ) |
| 238 |
->status_is(409) |
| 239 |
->json_is( |
| 240 |
{ error => $errors->{$error_code}->{description}, |
| 241 |
error_code => $errors->{$error_code}->{code}, |
| 242 |
} |
| 243 |
); |
| 244 |
} |
| 245 |
|
| 246 |
$expected_error = 'unknown_error'; |
| 247 |
$t->delete_ok( "//$userid:$password@/api/v1/items/" . $item->id ) |
| 248 |
->status_is(500, 'unhandled error case generated default unhandled exception message') |
| 249 |
->json_is( |
| 250 |
{ error => 'Something went wrong, check Koha logs for details.', |
| 251 |
error_code => 'internal_server_error', |
| 252 |
} |
| 253 |
); |
| 254 |
|
| 255 |
$fail = 0; |
| 256 |
|
| 257 |
$t->delete_ok("//$userid:$password@/api/v1/items/" . $item->id) |
| 258 |
->status_is(204, 'SWAGGER3.2.4') |
| 259 |
->content_is('', 'SWAGGER3.3.4'); |
| 260 |
|
| 261 |
$t->delete_ok("//$userid:$password@/api/v1/items/" . $item->id) |
| 262 |
->status_is(404); |
| 263 |
|
| 264 |
$schema->storage->txn_rollback; |
| 265 |
}; |
| 266 |
|
| 190 |
subtest 'pickup_locations() tests' => sub { |
267 |
subtest 'pickup_locations() tests' => sub { |
| 191 |
|
268 |
|
| 192 |
plan tests => 16; |
269 |
plan tests => 16; |
| 193 |
- |
|
|