Lines 60-66
subtest 'list() tests' => sub {
Link Here
|
60 |
|
60 |
|
61 |
## Authorized user tests |
61 |
## Authorized user tests |
62 |
# No batches, so empty array should be returned |
62 |
# No batches, so empty array should be returned |
63 |
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_is( [] ); |
63 |
$t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_is( [] ); |
64 |
|
64 |
|
65 |
my $batch = $builder->build_object( |
65 |
my $batch = $builder->build_object( |
66 |
{ |
66 |
{ |
Lines 85-91
subtest 'list() tests' => sub {
Link Here
|
85 |
); |
85 |
); |
86 |
|
86 |
|
87 |
# One batch created, should get returned |
87 |
# One batch created, should get returned |
88 |
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' ) |
88 |
$t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' ) |
89 |
->json_has( '/0/name', 'Batch name' )->json_has( '/0/backend', 'Backend name' ) |
89 |
->json_has( '/0/name', 'Batch name' )->json_has( '/0/backend', 'Backend name' ) |
90 |
->json_has( '/0/patron_id', 'Borrowernumber' )->json_has( '/0/library_id', 'Branchcode' ) |
90 |
->json_has( '/0/patron_id', 'Borrowernumber' )->json_has( '/0/library_id', 'Branchcode' ) |
91 |
->json_has( '/0/patron', 'patron embedded' )->json_has( '/0/branch', 'branch embedded' ) |
91 |
->json_has( '/0/patron', 'patron embedded' )->json_has( '/0/branch', 'branch embedded' ) |
Lines 98-104
subtest 'list() tests' => sub {
Link Here
|
98 |
my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } ); |
98 |
my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } ); |
99 |
|
99 |
|
100 |
# Two batches created, they should both be returned |
100 |
# Two batches created, they should both be returned |
101 |
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0', 'has first batch' ) |
101 |
$t->get_ok("//$userid:$password@/api/v1/ill/batches")->status_is(200)->json_has( '/0', 'has first batch' ) |
102 |
->json_has( '/1', 'has second batch' ); |
102 |
->json_has( '/1', 'has second batch' ); |
103 |
|
103 |
|
104 |
my $patron = $builder->build_object( |
104 |
my $patron = $builder->build_object( |
Lines 115-121
subtest 'list() tests' => sub {
Link Here
|
115 |
my $unauth_userid = $patron->userid; |
115 |
my $unauth_userid = $patron->userid; |
116 |
|
116 |
|
117 |
# Unauthorized access |
117 |
# Unauthorized access |
118 |
$t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")->status_is(403); |
118 |
$t->get_ok("//$unauth_userid:$password@/api/v1/ill/batches")->status_is(403); |
119 |
|
119 |
|
120 |
$schema->storage->txn_rollback; |
120 |
$schema->storage->txn_rollback; |
121 |
}; |
121 |
}; |
Lines 160-178
subtest 'get() tests' => sub {
Link Here
|
160 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
160 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
161 |
my $unauth_userid = $patron->userid; |
161 |
my $unauth_userid = $patron->userid; |
162 |
|
162 |
|
163 |
$t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(200) |
163 |
$t->get_ok( "//$userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(200) |
164 |
->json_has( '/batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' ) |
164 |
->json_has( '/batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' ) |
165 |
->json_has( '/backend', 'Backend name' )->json_has( '/patron_id', 'Borrowernumber' ) |
165 |
->json_has( '/backend', 'Backend name' )->json_has( '/patron_id', 'Borrowernumber' ) |
166 |
->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' ) |
166 |
->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' ) |
167 |
->json_has( '/branch', 'branch embedded' )->json_has( '/requests_count', 'request count' ); |
167 |
->json_has( '/branch', 'branch embedded' )->json_has( '/requests_count', 'request count' ); |
168 |
|
168 |
|
169 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(403); |
169 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/ill/batches/" . $batch->id )->status_is(403); |
170 |
|
170 |
|
171 |
my $batch_to_delete = $builder->build_object( { class => 'Koha::Illbatches' } ); |
171 |
my $batch_to_delete = $builder->build_object( { class => 'Koha::Illbatches' } ); |
172 |
my $non_existent_id = $batch_to_delete->id; |
172 |
my $non_existent_id = $batch_to_delete->id; |
173 |
$batch_to_delete->delete; |
173 |
$batch_to_delete->delete; |
174 |
|
174 |
|
175 |
$t->get_ok("//$userid:$password@/api/v1/illbatches/$non_existent_id")->status_is(404) |
175 |
$t->get_ok("//$userid:$password@/api/v1/ill/batches/$non_existent_id")->status_is(404) |
176 |
->json_is( '/error' => 'ILL batch not found' ); |
176 |
->json_is( '/error' => 'ILL batch not found' ); |
177 |
|
177 |
|
178 |
$schema->storage->txn_rollback; |
178 |
$schema->storage->txn_rollback; |
Lines 217-223
subtest 'add() tests' => sub {
Link Here
|
217 |
}; |
217 |
}; |
218 |
|
218 |
|
219 |
# Unauthorized attempt to write |
219 |
# Unauthorized attempt to write |
220 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(403); |
220 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(403); |
221 |
|
221 |
|
222 |
# Authorized attempt to write invalid data |
222 |
# Authorized attempt to write invalid data |
223 |
my $batch_with_invalid_field = { |
223 |
my $batch_with_invalid_field = { |
Lines 225-231
subtest 'add() tests' => sub {
Link Here
|
225 |
doh => 1 |
225 |
doh => 1 |
226 |
}; |
226 |
}; |
227 |
|
227 |
|
228 |
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )->status_is(400) |
228 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_with_invalid_field )->status_is(400) |
229 |
->json_is( |
229 |
->json_is( |
230 |
"/errors" => [ |
230 |
"/errors" => [ |
231 |
{ |
231 |
{ |
Lines 237-243
subtest 'add() tests' => sub {
Link Here
|
237 |
|
237 |
|
238 |
# Authorized attempt to write |
238 |
# Authorized attempt to write |
239 |
my $batch_id = |
239 |
my $batch_id = |
240 |
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(201) |
240 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(201) |
241 |
->json_is( '/name' => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} ) |
241 |
->json_is( '/name' => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} ) |
242 |
->json_is( '/patron_id' => $librarian->borrowernumber ) |
242 |
->json_is( '/patron_id' => $librarian->borrowernumber ) |
243 |
->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code ) |
243 |
->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code ) |
Lines 245-251
subtest 'add() tests' => sub {
Link Here
|
245 |
|
245 |
|
246 |
# Authorized attempt to create with null id |
246 |
# Authorized attempt to create with null id |
247 |
$batch_metadata->{id} = undef; |
247 |
$batch_metadata->{id} = undef; |
248 |
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(400) |
248 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batches" => json => $batch_metadata )->status_is(400) |
249 |
->json_has('/errors'); |
249 |
->json_has('/errors'); |
250 |
|
250 |
|
251 |
$schema->storage->txn_rollback; |
251 |
$schema->storage->txn_rollback; |
Lines 282-288
subtest 'update() tests' => sub {
Link Here
|
282 |
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; |
282 |
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; |
283 |
|
283 |
|
284 |
# Unauthorized attempt to update |
284 |
# Unauthorized attempt to update |
285 |
$t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => |
285 |
$t->put_ok( "//$unauth_userid:$password@/api/v1/ill/batches/$batch_id" => json => |
286 |
{ name => 'These are not the droids you are looking for' } )->status_is(403); |
286 |
{ name => 'These are not the droids you are looking for' } )->status_is(403); |
287 |
|
287 |
|
288 |
my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } ); |
288 |
my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } ); |
Lines 295-301
subtest 'update() tests' => sub {
Link Here
|
295 |
statuscode => $batch_status->code |
295 |
statuscode => $batch_status->code |
296 |
}; |
296 |
}; |
297 |
|
297 |
|
298 |
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field ) |
298 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_missing_field ) |
299 |
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] ); |
299 |
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] ); |
300 |
|
300 |
|
301 |
# Full object update on PUT |
301 |
# Full object update on PUT |
Lines 307-313
subtest 'update() tests' => sub {
Link Here
|
307 |
statuscode => $batch_status->code |
307 |
statuscode => $batch_status->code |
308 |
}; |
308 |
}; |
309 |
|
309 |
|
310 |
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field ) |
310 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field ) |
311 |
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' ); |
311 |
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' ); |
312 |
|
312 |
|
313 |
# Authorized attempt to write invalid data |
313 |
# Authorized attempt to write invalid data |
Lines 317-323
subtest 'update() tests' => sub {
Link Here
|
317 |
backend => "Mock" |
317 |
backend => "Mock" |
318 |
}; |
318 |
}; |
319 |
|
319 |
|
320 |
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field ) |
320 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_invalid_field ) |
321 |
->status_is(400)->json_is( |
321 |
->status_is(400)->json_is( |
322 |
"/errors" => [ |
322 |
"/errors" => [ |
323 |
{ |
323 |
{ |
Lines 331-343
subtest 'update() tests' => sub {
Link Here
|
331 |
my $non_existent_id = $batch_to_delete->id; |
331 |
my $non_existent_id = $batch_to_delete->id; |
332 |
$batch_to_delete->delete; |
332 |
$batch_to_delete->delete; |
333 |
|
333 |
|
334 |
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field ) |
334 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batches/$non_existent_id" => json => $batch_with_updated_field ) |
335 |
->status_is(404); |
335 |
->status_is(404); |
336 |
|
336 |
|
337 |
# Wrong method (POST) |
337 |
# Wrong method (POST) |
338 |
$batch_with_updated_field->{id} = 2; |
338 |
$batch_with_updated_field->{id} = 2; |
339 |
|
339 |
|
340 |
$t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field ) |
340 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batches/$batch_id" => json => $batch_with_updated_field ) |
341 |
->status_is(404); |
341 |
->status_is(404); |
342 |
|
342 |
|
343 |
$schema->storage->txn_rollback; |
343 |
$schema->storage->txn_rollback; |
Lines 372-382
subtest 'delete() tests' => sub {
Link Here
|
372 |
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; |
372 |
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id; |
373 |
|
373 |
|
374 |
# Unauthorized attempt to delete |
374 |
# Unauthorized attempt to delete |
375 |
$t->delete_ok("//$unauth_userid:$password@/api/v1/illbatches/$batch_id")->status_is(403); |
375 |
$t->delete_ok("//$unauth_userid:$password@/api/v1/ill/batches/$batch_id")->status_is(403); |
376 |
|
376 |
|
377 |
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(204); |
377 |
$t->delete_ok("//$userid:$password@/api/v1/ill/batches/$batch_id")->status_is(204); |
378 |
|
378 |
|
379 |
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(404); |
379 |
$t->delete_ok("//$userid:$password@/api/v1/ill/batches/$batch_id")->status_is(404); |
380 |
|
380 |
|
381 |
$schema->storage->txn_rollback; |
381 |
$schema->storage->txn_rollback; |
382 |
}; |
382 |
}; |
383 |
- |
|
|