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

(-)a/t/db_dependent/api/v1/bookings.t (-16 / +17 lines)
Lines 27-33 use JSON qw(encode_json); Link Here
27
27
28
use Koha::Bookings;
28
use Koha::Bookings;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::DateUtils qw (dt_from_string);
30
use Koha::DateUtils qw (dt_from_string output_pref);
31
31
32
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
Lines 86-93 subtest 'list() tests' => sub { Link Here
86
    $t->get_ok("//$userid:$password@/api/v1/bookings")->status_is(200)->json_is( [ $booking_0->to_api ] );
86
    $t->get_ok("//$userid:$password@/api/v1/bookings")->status_is(200)->json_is( [ $booking_0->to_api ] );
87
87
88
    # More bookings
88
    # More bookings
89
    my $start_1 = dt_from_string->add( days => 1 )->truncate( to => 'day' );
89
    my $start_1   = dt_from_string->add( days => 1 )->truncate( to => 'day' );
90
    my $end_1   = dt_from_string->add( days => 6 )->truncate( to => 'day' );
90
    my $end_1     = dt_from_string->add( days => 6 )->truncate( to => 'day' );
91
    my $booking_1 = $builder->build_object(
91
    my $booking_1 = $builder->build_object(
92
        {
92
        {
93
            class => 'Koha::Bookings',
93
            class => 'Koha::Bookings',
Lines 98-105 subtest 'list() tests' => sub { Link Here
98
        }
98
        }
99
    );
99
    );
100
100
101
    my $start_2 = dt_from_string->add( days => 4 )->truncate( to => 'day' );
101
    my $start_2   = dt_from_string->add( days => 4 )->truncate( to => 'day' );
102
    my $end_2   = dt_from_string->add( days => 8 )->truncate( to => 'day' );
102
    my $end_2     = dt_from_string->add( days => 8 )->truncate( to => 'day' );
103
    my $booking_2 = $builder->build_object(
103
    my $booking_2 = $builder->build_object(
104
        {
104
        {
105
            class => 'Koha::Bookings',
105
            class => 'Koha::Bookings',
Lines 121-127 subtest 'list() tests' => sub { Link Here
121
    );
121
    );
122
122
123
    # Filtering works, two bookings after today
123
    # Filtering works, two bookings after today
124
    my $api_filter = encode_json( { 'me.start_date' => { '>=' => dt_from_string->rfc3339 } } );
124
    my $api_filter = encode_json(
125
        { 'me.start_date' => { '>=' => output_pref( { dateformat => "rfc3339", dt => dt_from_string } ) } } );
125
    $t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")->status_is(200)->json_is(
126
    $t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")->status_is(200)->json_is(
126
        '' => [
127
        '' => [
127
            $booking_1->to_api,
128
            $booking_1->to_api,
Lines 130-136 subtest 'list() tests' => sub { Link Here
130
        'filtered returns two future bookings'
131
        'filtered returns two future bookings'
131
    );
132
    );
132
133
133
    $api_filter = encode_json( { 'me.start_date' => { '<=' => dt_from_string->rfc3339 } } );
134
    $api_filter = encode_json(
135
        { 'me.start_date' => { '<=' => output_pref( { dateformat => "rfc3339", dt => dt_from_string } ) } } );
134
    $t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")->status_is(200)
136
    $t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")->status_is(200)
135
        ->json_is( '' => [ $booking_0->to_api ], 'filtering to before today also works' );
137
        ->json_is( '' => [ $booking_0->to_api ], 'filtering to before today also works' );
136
138
Lines 227-234 subtest 'add() tests' => sub { Link Here
227
        biblio_id  => $biblio->id,
229
        biblio_id  => $biblio->id,
228
        item_id    => undef,
230
        item_id    => undef,
229
        patron_id  => $patron->id,
231
        patron_id  => $patron->id,
230
        start_date => dt_from_string->add( days => 2 )->rfc3339,
232
        start_date => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 2 ) } ),
231
        end_date   => dt_from_string->add( days => 6 )->rfc3339,
233
        end_date   => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 6 ) } ),
232
    };
234
    };
233
235
234
    # Unauthorized attempt to write
236
    # Unauthorized attempt to write
Lines 324-331 subtest 'update() tests' => sub { Link Here
324
    my $booking_with_missing_field = {
326
    my $booking_with_missing_field = {
325
        item_id    => undef,
327
        item_id    => undef,
326
        patron_id  => $patron->id,
328
        patron_id  => $patron->id,
327
        start_date => dt_from_string->add( days => 2 )->rfc3339,
329
        start_date => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 2 ) } ),
328
        end_date   => dt_from_string->add( days => 6 )->rfc3339,
330
        end_date   => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 6 ) } ),
329
    };
331
    };
330
332
331
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_missing_field )
333
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_missing_field )
Lines 336-343 subtest 'update() tests' => sub { Link Here
336
        biblio_id  => $biblio->id,
338
        biblio_id  => $biblio->id,
337
        item_id    => undef,
339
        item_id    => undef,
338
        patron_id  => $patron->id,
340
        patron_id  => $patron->id,
339
        start_date => dt_from_string->add( days => 2 )->rfc3339,
341
        start_date => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 2 ) } ),
340
        end_date   => dt_from_string->add( days => 6 )->rfc3339,
342
        end_date   => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 6 ) } ),
341
    };
343
    };
342
344
343
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_updated_field )
345
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_updated_field )
Lines 349-356 subtest 'update() tests' => sub { Link Here
349
        biblio_id  => $biblio->id,
351
        biblio_id  => $biblio->id,
350
        item_id    => undef,
352
        item_id    => undef,
351
        patron_id  => $patron->id,
353
        patron_id  => $patron->id,
352
        start_date => dt_from_string->add( days => 2 )->rfc3339,
354
        start_date => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 2 ) } ),
353
        end_date   => dt_from_string->add( days => 6 )->rfc3339,
355
        end_date   => output_pref( { dateformat => "rfc3339", dt => dt_from_string->add( days => 6 ) } ),
354
    };
356
    };
355
357
356
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_invalid_field )
358
    $t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_invalid_field )
357
- 

Return to bug 35468