Lines 158-224
subtest 'delete() tests' => sub {
Link Here
|
158 |
}; |
158 |
}; |
159 |
|
159 |
|
160 |
subtest 'batch_add() and batch_delete() tests' => sub { |
160 |
subtest 'batch_add() and batch_delete() tests' => sub { |
161 |
plan tests => 26; |
161 |
|
|
|
162 |
plan tests => 38; |
162 |
|
163 |
|
163 |
$schema->storage->txn_begin; |
164 |
$schema->storage->txn_begin; |
164 |
|
165 |
|
|
|
166 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
167 |
|
165 |
Koha::Item::Transfer::Limits->delete; |
168 |
Koha::Item::Transfer::Limits->delete; |
166 |
|
169 |
|
167 |
#my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
170 |
#my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
168 |
|
171 |
|
169 |
my $library = Koha::Libraries->search->next; |
172 |
my $library = Koha::Libraries->search->next; |
170 |
my $itemtype = Koha::ItemTypes->search->next; |
173 |
my $itemtype = Koha::ItemTypes->search->next; |
171 |
|
174 |
|
172 |
my $authorized_patron = $builder->build_object({ |
175 |
my $authorized_patron = $builder->build_object( |
173 |
class => 'Koha::Patrons', |
176 |
{ |
174 |
value => { flags => 1 } |
177 |
class => 'Koha::Patrons', |
175 |
}); |
178 |
value => { flags => 1 } |
|
|
179 |
} |
180 |
); |
176 |
my $password = 'thePassword123'; |
181 |
my $password = 'thePassword123'; |
177 |
$authorized_patron->set_password({ password => $password, skip_validation => 1 }); |
182 |
$authorized_patron->set_password( { password => $password, skip_validation => 1 } ); |
178 |
my $auth_userid = $authorized_patron->userid; |
183 |
my $auth_userid = $authorized_patron->userid; |
179 |
|
184 |
|
180 |
my $unauthorized_patron = $builder->build_object({ |
185 |
my $unauthorized_patron = $builder->build_object( |
181 |
class => 'Koha::Patrons', |
186 |
{ |
182 |
value => { flags => 4 } |
187 |
class => 'Koha::Patrons', |
183 |
}); |
188 |
value => { flags => 4 } |
184 |
$unauthorized_patron->set_password({ password => $password, skip_validation => 1 }); |
189 |
} |
|
|
190 |
); |
191 |
$unauthorized_patron->set_password( { password => $password, skip_validation => 1 } ); |
185 |
my $unauth_userid = $unauthorized_patron->userid; |
192 |
my $unauth_userid = $unauthorized_patron->userid; |
186 |
|
193 |
|
187 |
my $limit_hashref = { |
194 |
my $limit_hashref = { item_type => $itemtype->id }; |
188 |
item_type => $itemtype->id |
|
|
189 |
}; |
190 |
|
195 |
|
191 |
# Unauthorized attempt to write |
196 |
# Unauthorized attempt to write |
192 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
197 |
$t->post_ok( "//$unauth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref )->status_is(403); |
193 |
->status_is(403); |
|
|
194 |
|
198 |
|
195 |
# Authorized attempt to write invalid data |
199 |
# Authorized attempt to write invalid data |
196 |
my $limit_with_invalid_field = {'invalid' => 'invalid'}; |
200 |
my $limit_with_invalid_field = { 'invalid' => 'invalid' }; |
197 |
|
201 |
|
198 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_with_invalid_field ) |
202 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_with_invalid_field ) |
199 |
->status_is(400) |
203 |
->status_is(400)->json_is( |
200 |
->json_is( |
|
|
201 |
"/errors" => [ |
204 |
"/errors" => [ |
202 |
{ |
205 |
{ |
203 |
message => "Properties not allowed: invalid.", |
206 |
message => "Properties not allowed: invalid.", |
204 |
path => "/body" |
207 |
path => "/body" |
205 |
} |
208 |
} |
206 |
] |
209 |
] |
207 |
); |
210 |
); |
|
|
211 |
|
212 |
# Create all combinations of to/from libraries |
213 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => |
214 |
{ item_type => 'X', collection_code => 'Y' } )->status_is(400) |
215 |
->json_is( '/error' => "Only one of 'item_type' and 'collecion_code' can be passed at a time" ); |
216 |
|
217 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'ccode' ); |
218 |
|
219 |
# Create all combinations of to/from libraries |
220 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { item_type => 'X' } ) |
221 |
->status_is(409)->json_is( '/error' => "You passed 'item_type' but configuration expects 'collection_code'" ); |
222 |
|
223 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
224 |
|
225 |
# Create all combinations of to/from libraries |
226 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => { collection_code => 'X' } ) |
227 |
->status_is(409)->json_is( '/error' => "You passed 'collection_code' but configuration expects 'item_type'" ); |
208 |
|
228 |
|
209 |
# Create all combinations of to/from libraries |
229 |
# Create all combinations of to/from libraries |
210 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
230 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
211 |
->status_is( 201, 'SWAGGER3.2.1' ) |
231 |
->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
212 |
->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
|
|
213 |
|
232 |
|
214 |
my $limits = Koha::Item::Transfer::Limits->search; |
233 |
my $limits = Koha::Item::Transfer::Limits->search; |
215 |
|
234 |
|
216 |
my $libraries_count = Koha::Libraries->search->count; |
235 |
my $libraries_count = Koha::Libraries->search->count; |
217 |
is( $limits->count, $libraries_count * ($libraries_count - 1 ), "Created the correct number of limits" ); |
236 |
is( $limits->count, $libraries_count * ( $libraries_count - 1 ), "Created the correct number of limits" ); |
218 |
|
237 |
|
219 |
# Delete all combinations of to/from libraries |
238 |
# Delete all combinations of to/from libraries |
220 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
239 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
221 |
->status_is( 204, 'SWAGGER3.2.1' ); |
240 |
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); |
222 |
|
241 |
|
223 |
$limits = Koha::Item::Transfer::Limits->search; |
242 |
$limits = Koha::Item::Transfer::Limits->search; |
224 |
|
243 |
|
Lines 227-242
subtest 'batch_add() and batch_delete() tests' => sub {
Link Here
|
227 |
# Create all combinations of 'to' libraries |
246 |
# Create all combinations of 'to' libraries |
228 |
$limit_hashref->{to_library_id} = $library->id; |
247 |
$limit_hashref->{to_library_id} = $library->id; |
229 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
248 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
230 |
->status_is( 201, 'SWAGGER3.2.1' ) |
249 |
->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
231 |
->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
|
|
232 |
|
250 |
|
233 |
$limits = Koha::Item::Transfer::Limits->search; |
251 |
$limits = Koha::Item::Transfer::Limits->search; |
234 |
|
252 |
|
235 |
is( $limits->count, $libraries_count - 1 , "Created the correct number of limits" ); |
253 |
is( $limits->count, $libraries_count - 1, "Created the correct number of limits" ); |
236 |
|
254 |
|
237 |
# Delete all combinations of 'to' libraries |
255 |
# Delete all combinations of 'to' libraries |
238 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
256 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
239 |
->status_is( 204, 'SWAGGER3.2.1' ); |
257 |
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); |
240 |
|
258 |
|
241 |
$limits = Koha::Item::Transfer::Limits->search; |
259 |
$limits = Koha::Item::Transfer::Limits->search; |
242 |
|
260 |
|
Lines 248-264
subtest 'batch_add() and batch_delete() tests' => sub {
Link Here
|
248 |
delete $limit_hashref->{to_library_id}; |
266 |
delete $limit_hashref->{to_library_id}; |
249 |
$limit_hashref->{from_library_id} = $library->id; |
267 |
$limit_hashref->{from_library_id} = $library->id; |
250 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
268 |
$t->post_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
251 |
->status_is( 201, 'SWAGGER3.2.1' ) |
269 |
->status_is( 201, 'SWAGGER3.2.1' )->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
252 |
->json_has( '' => $limit_hashref, 'SWAGGER3.3.1' ); |
|
|
253 |
|
270 |
|
254 |
$limits = Koha::Item::Transfer::Limits->search; |
271 |
$limits = Koha::Item::Transfer::Limits->search; |
255 |
|
272 |
|
256 |
$libraries_count = Koha::Libraries->search->count; |
273 |
$libraries_count = Koha::Libraries->search->count; |
257 |
is( $limits->count, $libraries_count - 1 , "Created the correct number of limits" ); |
274 |
is( $limits->count, $libraries_count - 1, "Created the correct number of limits" ); |
258 |
|
275 |
|
259 |
# Delete all combinations of 'from' libraries |
276 |
# Delete all combinations of 'from' libraries |
260 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
277 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/transfer_limits/batch" => json => $limit_hashref ) |
261 |
->status_is( 204, 'SWAGGER3.2.1' ); |
278 |
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); |
262 |
|
279 |
|
263 |
$limits = Koha::Item::Transfer::Limits->search; |
280 |
$limits = Koha::Item::Transfer::Limits->search; |
264 |
|
281 |
|
265 |
- |
|
|