Lines 33-39
my $t = Test::Mojo->new('Koha::REST::V1');
Link Here
|
33 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
33 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
34 |
|
34 |
|
35 |
subtest 'list_rules() tests' => sub { |
35 |
subtest 'list_rules() tests' => sub { |
36 |
plan tests => 32; |
36 |
plan tests => 33; |
37 |
|
37 |
|
38 |
$schema->storage->txn_begin; |
38 |
$schema->storage->txn_begin; |
39 |
|
39 |
|
Lines 202-206
subtest 'list_rules() tests' => sub {
Link Here
|
202 |
# Unauthorized access |
202 |
# Unauthorized access |
203 |
$t->get_ok("//$unauth_userid:$password@/api/v1/circulation_rules")->status_is(403); |
203 |
$t->get_ok("//$unauth_userid:$password@/api/v1/circulation_rules")->status_is(403); |
204 |
|
204 |
|
|
|
205 |
subtest 'effective=false tests' => sub { |
206 |
|
207 |
my $expected_keys = [ keys %{ Koha::CirculationRules->rule_kinds } ]; |
208 |
my $count = scalar( @{$expected_keys} ); |
209 |
|
210 |
plan tests => ( $count * 2 ) + $count + 10; |
211 |
|
212 |
# All rules |
213 |
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?effective=0")->status_is(200); |
214 |
|
215 |
# Extract and decode the JSON response |
216 |
my $json = $t->tx->res->json; |
217 |
|
218 |
# Check if the response is an array |
219 |
is( ref $json, 'ARRAY', 'Response is an array' ); |
220 |
is( scalar( @{$json} ), 2, 'Response contains 2 rule sets' ); |
221 |
|
222 |
# Iterate over each hash in the array |
223 |
my $index = 0; |
224 |
foreach my $hash ( @{$json} ) { |
225 |
my $pointer = Mojo::JSON::Pointer->new($hash); |
226 |
|
227 |
# First rule set should march default, default, default |
228 |
if ( $index == 0 ) { |
229 |
ok( $pointer->get('/branchcode') eq "*" |
230 |
&& $pointer->get('/itemtype') eq '*' |
231 |
&& $pointer->get('/categorycode') eq '*', "Default rules returned first" ); |
232 |
} |
233 |
|
234 |
# Iterate over the list of expected keys for each hash |
235 |
foreach my $key ( @{$expected_keys} ) { |
236 |
ok( $pointer->contains( '/' . $key ), "Hash contains key '$key'" ); |
237 |
} |
238 |
|
239 |
$index++; |
240 |
} |
241 |
|
242 |
# Filter on library |
243 |
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?effective=0&library_id=$branchcode")->status_is(200); |
244 |
|
245 |
# Extract and decode the JSON response |
246 |
$json = $t->tx->res->json; |
247 |
|
248 |
# Check if the response is an array |
249 |
is( ref $json, 'ARRAY', 'Response is an array' ); |
250 |
is( scalar( @{$json} ), 1, 'Filtered response contains 1 rule set' ); |
251 |
|
252 |
$index = 0; |
253 |
foreach my $hash ( @{$json} ) { |
254 |
my $pointer = Mojo::JSON::Pointer->new($hash); |
255 |
|
256 |
# First (and only) rule set should match branchcode, default, default. |
257 |
if ( $index == 0 ) { |
258 |
ok( $pointer->get('/branchcode') eq $branchcode |
259 |
&& $pointer->get('/itemtype') eq '*' |
260 |
&& $pointer->get('/categorycode') eq '*', "Branchcode rule set returned when filtered" ); |
261 |
} |
262 |
|
263 |
# Iterate over the list of expected keys for each hash |
264 |
foreach my $key ( @{$expected_keys} ) { |
265 |
ok( $pointer->contains( '/' . $key ), "Hash contains key '$key'" ); |
266 |
} |
267 |
|
268 |
$index++; |
269 |
} |
270 |
|
271 |
}; |
205 |
$schema->storage->txn_rollback; |
272 |
$schema->storage->txn_rollback; |
206 |
}; |
273 |
}; |
207 |
- |
|
|