Lines 56-62
subtest 'list() tests' => sub {
Link Here
|
56 |
|
56 |
|
57 |
## Authorized user tests |
57 |
## Authorized user tests |
58 |
# No statuses, so empty array should be returned |
58 |
# No statuses, so empty array should be returned |
59 |
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_is( [] ); |
59 |
$t->get_ok("//$userid:$password@/api/v1/ill/batchstatuses")->status_is(200)->json_is( [] ); |
60 |
|
60 |
|
61 |
my $status = $builder->build_object( |
61 |
my $status = $builder->build_object( |
62 |
{ |
62 |
{ |
Lines 70-76
subtest 'list() tests' => sub {
Link Here
|
70 |
); |
70 |
); |
71 |
|
71 |
|
72 |
# One batch created, should get returned |
72 |
# One batch created, should get returned |
73 |
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_has( '/0/id', 'ID' ) |
73 |
$t->get_ok("//$userid:$password@/api/v1/ill/batchstatuses")->status_is(200)->json_has( '/0/id', 'ID' ) |
74 |
->json_has( '/0/name', 'Name' )->json_has( '/0/code', 'Code' )->json_has( '/0/is_system', 'is_system' ); |
74 |
->json_has( '/0/name', 'Name' )->json_has( '/0/code', 'Code' )->json_has( '/0/is_system', 'is_system' ); |
75 |
|
75 |
|
76 |
$schema->storage->txn_rollback; |
76 |
$schema->storage->txn_rollback; |
Lines 113-129
subtest 'get() tests' => sub {
Link Here
|
113 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
113 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
114 |
my $unauth_userid = $patron->userid; |
114 |
my $unauth_userid = $patron->userid; |
115 |
|
115 |
|
116 |
$t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )->status_is(200) |
116 |
$t->get_ok( "//$userid:$password@/api/v1/ill/batchstatuses/" . $status->code )->status_is(200) |
117 |
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' ) |
117 |
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' ) |
118 |
->json_has( '/is_system', 'is_system' ); |
118 |
->json_has( '/is_system', 'is_system' ); |
119 |
|
119 |
|
120 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id )->status_is(403); |
120 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/ill/batchstatuses/" . $status->id )->status_is(403); |
121 |
|
121 |
|
122 |
my $status_to_delete = $builder->build_object( { class => 'Koha::IllbatchStatuses' } ); |
122 |
my $status_to_delete = $builder->build_object( { class => 'Koha::IllbatchStatuses' } ); |
123 |
my $non_existent_code = $status_to_delete->code; |
123 |
my $non_existent_code = $status_to_delete->code; |
124 |
$status_to_delete->delete; |
124 |
$status_to_delete->delete; |
125 |
|
125 |
|
126 |
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code")->status_is(404) |
126 |
$t->get_ok("//$userid:$password@/api/v1/ill/batchstatuses/$non_existent_code")->status_is(404) |
127 |
->json_is( '/error' => 'ILL batch status not found' ); |
127 |
->json_is( '/error' => 'ILL batch status not found' ); |
128 |
|
128 |
|
129 |
$schema->storage->txn_rollback; |
129 |
$schema->storage->txn_rollback; |
Lines 161-167
subtest 'add() tests' => sub {
Link Here
|
161 |
}; |
161 |
}; |
162 |
|
162 |
|
163 |
# Unauthorized attempt to write |
163 |
# Unauthorized attempt to write |
164 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(403); |
164 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/ill/batchstatuses" => json => $status_metadata )->status_is(403); |
165 |
|
165 |
|
166 |
# Authorized attempt to write invalid data |
166 |
# Authorized attempt to write invalid data |
167 |
my $status_with_invalid_field = { |
167 |
my $status_with_invalid_field = { |
Lines 169-175
subtest 'add() tests' => sub {
Link Here
|
169 |
doh => 1 |
169 |
doh => 1 |
170 |
}; |
170 |
}; |
171 |
|
171 |
|
172 |
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )->status_is(400) |
172 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batchstatuses" => json => $status_with_invalid_field )->status_is(400) |
173 |
->json_is( |
173 |
->json_is( |
174 |
"/errors" => [ |
174 |
"/errors" => [ |
175 |
{ |
175 |
{ |
Lines 181-193
subtest 'add() tests' => sub {
Link Here
|
181 |
|
181 |
|
182 |
# Authorized attempt to write |
182 |
# Authorized attempt to write |
183 |
my $status_id = |
183 |
my $status_id = |
184 |
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(201) |
184 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batchstatuses" => json => $status_metadata )->status_is(201) |
185 |
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' ) |
185 |
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' ) |
186 |
->json_has( '/is_system', 'is_system' ); |
186 |
->json_has( '/is_system', 'is_system' ); |
187 |
|
187 |
|
188 |
# Authorized attempt to create with null id |
188 |
# Authorized attempt to create with null id |
189 |
$status_metadata->{id} = undef; |
189 |
$status_metadata->{id} = undef; |
190 |
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(400) |
190 |
$t->post_ok( "//$userid:$password@/api/v1/ill/batchstatuses" => json => $status_metadata )->status_is(400) |
191 |
->json_has('/errors'); |
191 |
->json_has('/errors'); |
192 |
|
192 |
|
193 |
$schema->storage->txn_rollback; |
193 |
$schema->storage->txn_rollback; |
Lines 221-227
subtest 'update() tests' => sub {
Link Here
|
221 |
my $status_code = $builder->build_object( { class => 'Koha::IllbatchStatuses' } )->code; |
221 |
my $status_code = $builder->build_object( { class => 'Koha::IllbatchStatuses' } )->code; |
222 |
|
222 |
|
223 |
# Unauthorized attempt to update |
223 |
# Unauthorized attempt to update |
224 |
$t->put_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/$status_code" => json => |
224 |
$t->put_ok( "//$unauth_userid:$password@/api/v1/ill/batchstatuses/$status_code" => json => |
225 |
{ name => 'These are not the droids you are looking for' } )->status_is(403); |
225 |
{ name => 'These are not the droids you are looking for' } )->status_is(403); |
226 |
|
226 |
|
227 |
# Attempt partial update on a PUT |
227 |
# Attempt partial update on a PUT |
Lines 230-236
subtest 'update() tests' => sub {
Link Here
|
230 |
is_system => 0 |
230 |
is_system => 0 |
231 |
}; |
231 |
}; |
232 |
|
232 |
|
233 |
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field ) |
233 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batchstatuses/$status_code" => json => $status_with_missing_field ) |
234 |
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] ); |
234 |
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] ); |
235 |
|
235 |
|
236 |
# Full object update on PUT |
236 |
# Full object update on PUT |
Lines 240-246
subtest 'update() tests' => sub {
Link Here
|
240 |
is_system => 0 |
240 |
is_system => 0 |
241 |
}; |
241 |
}; |
242 |
|
242 |
|
243 |
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field ) |
243 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batchstatuses/$status_code" => json => $status_with_updated_field ) |
244 |
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' ); |
244 |
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' ); |
245 |
|
245 |
|
246 |
# Authorized attempt to write invalid data |
246 |
# Authorized attempt to write invalid data |
Lines 250-256
subtest 'update() tests' => sub {
Link Here
|
250 |
code => $status_code |
250 |
code => $status_code |
251 |
}; |
251 |
}; |
252 |
|
252 |
|
253 |
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field ) |
253 |
$t->put_ok( "//$userid:$password@/api/v1/ill/batchstatuses/$status_code" => json => $status_with_invalid_field ) |
254 |
->status_is(400)->json_is( |
254 |
->status_is(400)->json_is( |
255 |
"/errors" => [ |
255 |
"/errors" => [ |
256 |
{ |
256 |
{ |
Lines 265-271
subtest 'update() tests' => sub {
Link Here
|
265 |
$status_to_delete->delete; |
265 |
$status_to_delete->delete; |
266 |
|
266 |
|
267 |
$t->put_ok( |
267 |
$t->put_ok( |
268 |
"//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field ) |
268 |
"//$userid:$password@/api/v1/ill/batchstatuses/$non_existent_code" => json => $status_with_updated_field ) |
269 |
->status_is(404); |
269 |
->status_is(404); |
270 |
|
270 |
|
271 |
$schema->storage->txn_rollback; |
271 |
$schema->storage->txn_rollback; |
Lines 312-324
subtest 'delete() tests' => sub {
Link Here
|
312 |
); |
312 |
); |
313 |
|
313 |
|
314 |
# Unauthorized attempt to delete |
314 |
# Unauthorized attempt to delete |
315 |
$t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(403); |
315 |
$t->delete_ok( "//$unauth_userid:$password@/api/v1/ill/batchstatuses/" . $non_system_status->code )->status_is(403); |
316 |
|
316 |
|
317 |
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(204); |
317 |
$t->delete_ok( "//$userid:$password@/api/v1/ill/batchstatuses/" . $non_system_status->code )->status_is(204); |
318 |
|
318 |
|
319 |
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(404); |
319 |
$t->delete_ok( "//$userid:$password@/api/v1/ill/batchstatuses/" . $non_system_status->code )->status_is(404); |
320 |
|
320 |
|
321 |
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )->status_is(400) |
321 |
$t->delete_ok( "//$userid:$password@/api/v1/ill/batchstatuses/" . $system_status->code )->status_is(400) |
322 |
->json_is( "/errors" => [ { message => "ILL batch status cannot be deleted" } ] ); |
322 |
->json_is( "/errors" => [ { message => "ILL batch status cannot be deleted" } ] ); |
323 |
|
323 |
|
324 |
$schema->storage->txn_rollback; |
324 |
$schema->storage->txn_rollback; |
325 |
- |
|
|