View | Details | Raw Unified | Return to bug 37902
Collapse All | Expand All

(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +77 lines)
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
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
974
975
    my $patron =
976
        $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } );
977
    my $password = 'thePassword123';
978
    $patron->set_password( { password => $password, skip_validation => 1 } );
979
    my $userid = $patron->userid;
980
    t::lib::Mocks::mock_userenv( { patron => $patron } );
981
982
    my $now           = dt_from_string();
983
    my $one_hour_ago  = $now->clone->subtract( hours => 1 );
984
    my $one_day_ago   = $now->clone->subtract( days  => 1 );
985
    my $one_day_later = $now->clone->add( hours => 1 );
986
987
    # one hour ago job
988
    my $job_1 = $builder->build_object(
989
        {
990
            class => 'Koha::BackgroundJobs',
991
            value => {
992
                borrowernumber => $patron->borrowernumber,
993
                enqueued_on    => $one_hour_ago,
994
                data           => '{}',
995
            }
996
        }
997
    );
998
999
    # yesterday job
1000
    my $job_2 = $builder->build_object(
1001
        {
1002
            class => 'Koha::BackgroundJobs',
1003
            value => {
1004
                borrowernumber => $patron->borrowernumber,
1005
                enqueued_on    => $one_day_ago,
1006
                data           => '{}',
1007
            }
1008
        }
1009
    );
1010
1011
    # tomorrow job
1012
    my $job_3 = $builder->build_object(
1013
        {
1014
            class => 'Koha::BackgroundJobs',
1015
            value => {
1016
                borrowernumber => $patron->borrowernumber,
1017
                enqueued_on    => $one_day_later,
1018
                data           => '{}',
1019
            }
1020
        }
1021
    );
1022
1023
    my $t = Test::Mojo->new('Koha::REST::V1');
1024
    my $q = encode_json( { enqueued_on => $one_hour_ago->rfc3339, borrowernumber => $patron->id } );
1025
    $t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )->status_is(200)->json_is( '/0/job_id' => $job_1->id );
1026
    my $response_count = scalar @{ $t->tx->res->json };
1027
    is( $response_count, 1 );
1028
1029
    $q = encode_json(
1030
        {
1031
            enqueued_on    => [ { '>' => $now->rfc3339 }, { '=' => $one_hour_ago->rfc3339 } ],
1032
            borrowernumber => $patron->id
1033
        }
1034
    );
1035
    $t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )->status_is(200)->json_is( '/0/job_id' => $job_1->id )
1036
        ->json_is( '/1/job_id' => $job_3->id );
1037
    $response_count = scalar @{ $t->tx->res->json };
1038
    is( $response_count, 2 );
1039
1040
    $schema->storage->txn_rollback;
1041
};

Return to bug 37902