|
Lines 23-28
use Koha::AuthorisedValues;
Link Here
|
| 23 |
use Koha::Cities; |
23 |
use Koha::Cities; |
| 24 |
use Koha::Biblios; |
24 |
use Koha::Biblios; |
| 25 |
use Koha::Patrons; |
25 |
use Koha::Patrons; |
|
|
26 |
use Koha::DateUtils qw(dt_from_string); |
| 26 |
|
27 |
|
| 27 |
use Mojo::JSON qw(encode_json); |
28 |
use Mojo::JSON qw(encode_json); |
| 28 |
|
29 |
|
|
Lines 139-145
get '/cities/:city_id/rs' => sub {
Link Here
|
| 139 |
}; |
140 |
}; |
| 140 |
|
141 |
|
| 141 |
# The tests |
142 |
# The tests |
| 142 |
use Test::More tests => 17; |
143 |
use Test::More tests => 18; |
| 143 |
use Test::Mojo; |
144 |
use Test::Mojo; |
| 144 |
|
145 |
|
| 145 |
use t::lib::Mocks; |
146 |
use t::lib::Mocks; |
|
Lines 963-965
subtest 'objects.find_rs helper' => sub {
Link Here
|
| 963 |
|
964 |
|
| 964 |
$schema->storage->txn_rollback; |
965 |
$schema->storage->txn_rollback; |
| 965 |
}; |
966 |
}; |
| 966 |
- |
967 |
|
|
|
968 |
subtest 'date handling' => sub { |
| 969 |
plan tests => 9; |
| 970 |
|
| 971 |
$schema->storage->txn_begin; |
| 972 |
|
| 973 |
my $patron = |
| 974 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
| 975 |
my $password = 'thePassword123'; |
| 976 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 977 |
my $userid = $patron->userid; |
| 978 |
t::lib::Mocks::mock_userenv( { patron => $patron } ); |
| 979 |
|
| 980 |
my $now = dt_from_string(); |
| 981 |
my $one_hour_ago = $now->clone->subtract( hours => 1 ); |
| 982 |
my $one_day_ago = $now->clone->subtract( days => 1 ); |
| 983 |
my $one_day_later = $now->clone->add( hours => 1 ); |
| 984 |
|
| 985 |
# one hour ago job |
| 986 |
my $job_1 = $builder->build_object( |
| 987 |
{ |
| 988 |
class => 'Koha::BackgroundJobs', |
| 989 |
value => { |
| 990 |
borrowernumber => $patron->borrowernumber, |
| 991 |
enqueued_on => $one_hour_ago, |
| 992 |
data => '{}', |
| 993 |
} |
| 994 |
} |
| 995 |
); |
| 996 |
|
| 997 |
# yesterday job |
| 998 |
my $job_2 = $builder->build_object( |
| 999 |
{ |
| 1000 |
class => 'Koha::BackgroundJobs', |
| 1001 |
value => { |
| 1002 |
borrowernumber => $patron->borrowernumber, |
| 1003 |
enqueued_on => $one_day_ago, |
| 1004 |
data => '{}', |
| 1005 |
} |
| 1006 |
} |
| 1007 |
); |
| 1008 |
|
| 1009 |
# tomorrow job |
| 1010 |
my $job_3 = $builder->build_object( |
| 1011 |
{ |
| 1012 |
class => 'Koha::BackgroundJobs', |
| 1013 |
value => { |
| 1014 |
borrowernumber => $patron->borrowernumber, |
| 1015 |
enqueued_on => $one_day_later, |
| 1016 |
data => '{}', |
| 1017 |
} |
| 1018 |
} |
| 1019 |
); |
| 1020 |
|
| 1021 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 1022 |
my $q = encode_json( { enqueued_on => $one_hour_ago->rfc3339, borrowernumber => $patron->id } ); |
| 1023 |
$t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )->status_is(200)->json_is( '/0/job_id' => $job_1->id ); |
| 1024 |
my $response_count = scalar @{ $t->tx->res->json }; |
| 1025 |
is( $response_count, 1 ); |
| 1026 |
|
| 1027 |
$q = encode_json( |
| 1028 |
{ |
| 1029 |
enqueued_on => [ { '>' => $now->rfc3339 }, { '=' => $one_hour_ago->rfc3339 } ], |
| 1030 |
borrowernumber => $patron->id |
| 1031 |
} |
| 1032 |
); |
| 1033 |
$t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )->status_is(200)->json_is( '/0/job_id' => $job_1->id ) |
| 1034 |
->json_is( '/1/job_id' => $job_3->id ); |
| 1035 |
$response_count = scalar @{ $t->tx->res->json }; |
| 1036 |
is( $response_count, 2 ); |
| 1037 |
|
| 1038 |
$schema->storage->txn_rollback; |
| 1039 |
}; |