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

(-)a/t/db_dependent/Koha/Acquisition/Basket.t (-1 / +101 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 9;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
Lines 171-173 subtest 'to_api() tests' => sub { Link Here
171
171
172
    $schema->storage->txn_rollback;
172
    $schema->storage->txn_rollback;
173
};
173
};
174
175
subtest 'estimated_delivery_date' => sub {
176
    plan tests => 4;
177
178
    $schema->storage->txn_begin;
179
    my $bookseller = $builder->build_object(
180
        {
181
            class => 'Koha::Acquisition::Booksellers',
182
            value => {
183
                deliverytime => undef,   # Does not have a delivery time defined
184
            }
185
        }
186
    );
187
188
    my $basket = $builder->build_object(
189
        {
190
            class => 'Koha::Acquisition::Baskets',
191
            value => {
192
                booksellerid => $bookseller->id,
193
                closedate    => undef,             # Still open
194
            }
195
        }
196
    );
197
198
    my $now = dt_from_string;
199
    is( $basket->estimated_delivery_date,
200
        undef, 'return undef if closedate and deliverytime are not defined' );
201
202
    $basket->closedate( $now->clone->subtract( days => 1 ) )
203
      ->store;                                     #Closing the basket
204
    is( $basket->estimated_delivery_date,
205
        undef, 'return undef if deliverytime is not defined' );
206
207
    $basket->closedate(undef)->store;              #Reopening
208
    $bookseller->deliverytime(2)->store;           # 2 delivery days
209
    is( $basket->estimated_delivery_date,
210
        undef, 'return undef if closedate is not defined (basket stil open)' );
211
212
    $bookseller->deliverytime(2)->store;           # 2 delivery days
213
    $basket->closedate( $now->clone->subtract( days => 1 ) )->store; #Closing the basket
214
    is(
215
        $basket->get_from_storage->estimated_delivery_date,
216
        $now->clone->add( days => 1 )->truncate( to => 'day' ),
217
        'Estimated delivery date should be tomorrow if basket closed on yesterday and delivery takes 2 days'
218
    );
219
220
    $schema->storage->txn_rollback;
221
};
222
223
subtest 'late_since_days' => sub {
224
    plan tests => 3;
225
226
    $schema->storage->txn_begin;
227
    my $basket  = $builder->build_object(
228
        {
229
            class => 'Koha::Acquisition::Baskets',
230
        }
231
    );
232
233
    my $now = dt_from_string;
234
    $basket->closedate(undef)->store; # Basket is open
235
    is( $basket->late_since_days, undef, 'return undef if basket is still open');
236
237
    $basket->closedate( $now )->store; #Closing the basket today
238
    is( $basket->late_since_days, 0, 'return 0 if basket has been closed on today' );
239
240
    $basket->closedate( $now->clone->subtract( days => 2 ) )->store;
241
    is( $basket->late_since_days, 2, 'return 2 if basket has been closed 2 days ago' );
242
243
    $schema->storage->txn_rollback;
244
};
245
246
subtest 'authorizer' => sub {
247
    plan tests => 3;
248
249
    $schema->storage->txn_begin;
250
    my $basket = $builder->build_object(
251
        {
252
            class => 'Koha::Acquisition::Baskets',
253
            value => { authorisedby => undef },
254
        }
255
    );
256
257
    my $basket_creator = $builder->build_object( { class => 'Koha::Patrons' } );
258
259
    is( $basket->authorizer, undef,
260
        'authorisedby is null, ->authorized should return undef' );
261
262
    $basket->authorisedby( $basket_creator->borrowernumber )->store;
263
264
    is( ref( $basket->authorizer ),
265
        'Koha::Patron', '->authorized should return a Koha::Patron object' );
266
    is(
267
        $basket->authorizer->borrowernumber,
268
        $basket_creator->borrowernumber,
269
        '->authorized should return the correct creator'
270
    );
271
272
    $schema->storage->txn_rollback;
273
};
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-2 / +182 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 10;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 354-356 subtest 'current_item_level_holds() tests' => sub { Link Here
354
354
355
    $schema->storage->txn_rollback;
355
    $schema->storage->txn_rollback;
356
};
356
};
357
- 
357
358
subtest 'claim*' => sub {
359
    plan tests => 6;
360
361
    $schema->storage->txn_begin;
362
    my $order = $builder->build_object(
363
        {
364
            class => 'Koha::Acquisition::Orders',
365
        }
366
    );
367
368
    my $now = dt_from_string;
369
    is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set');
370
    is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0');
371
    is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef');
372
373
    my $claim_1 = $order->claim;
374
    my $claim_2 = $order->claim;
375
376
    $claim_1->claimed_on($now->clone->subtract(days => 1))->store;
377
378
    is( $order->claims->count, 2, '->claims should return the correct number of claims');
379
    is( $order->claims_count, 2, '->claims_count should return the correct number of claims');
380
    is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim');
381
382
    $schema->storage->txn_rollback;
383
};
384
385
subtest 'filter_by_late' => sub {
386
    plan tests => 16;
387
388
    $schema->storage->txn_begin;
389
    my $now        = dt_from_string;
390
    my $bookseller = $builder->build_object(
391
        {
392
            class => 'Koha::Acquisition::Booksellers',
393
            value => { deliverytime => 2 }
394
        }
395
    );
396
    my $basket_1 = $builder->build_object(
397
        {
398
            class => 'Koha::Acquisition::Baskets',
399
            value => {
400
                booksellerid => $bookseller->id,
401
                closedate    => undef,
402
            }
403
        }
404
    );
405
    my $order_1 = $builder->build_object(
406
        {
407
            class => 'Koha::Acquisition::Orders',
408
            value => {
409
                basketno                => $basket_1->basketno,
410
                datereceived            => undef,
411
                datecancellationprinted => undef,
412
            }
413
        }
414
    );
415
    my $basket_2 = $builder->build_object(    # expected tomorrow
416
        {
417
            class => 'Koha::Acquisition::Baskets',
418
            value => {
419
                booksellerid => $bookseller->id,
420
                closedate    => $now->clone->subtract( days => 1 ),
421
            }
422
        }
423
    );
424
    my $order_2 = $builder->build_object(
425
        {
426
            class => 'Koha::Acquisition::Orders',
427
            value => {
428
                basketno                => $basket_2->basketno,
429
                datereceived            => undef,
430
                datecancellationprinted => undef,
431
            }
432
        }
433
    );
434
    my $basket_3 = $builder->build_object(    # expected yesterday (1 day)
435
        {
436
            class => 'Koha::Acquisition::Baskets',
437
            value => {
438
                booksellerid => $bookseller->id,
439
                closedate    => $now->clone->subtract( days => 3 ),
440
            }
441
        }
442
    );
443
    my $order_3 = $builder->build_object(
444
        {
445
            class => 'Koha::Acquisition::Orders',
446
            value => {
447
                basketno                => $basket_3->basketno,
448
                datereceived            => undef,
449
                datecancellationprinted => undef,
450
            }
451
        }
452
    );
453
    my $basket_4 = $builder->build_object(    # expected 3 days ago
454
        {
455
            class => 'Koha::Acquisition::Baskets',
456
            value => {
457
                booksellerid => $bookseller->id,
458
                closedate    => $now->clone->subtract( days => 5 ),
459
            }
460
        }
461
    );
462
    my $order_4 = $builder->build_object(
463
        {
464
            class => 'Koha::Acquisition::Orders',
465
            value => {
466
                basketno                => $basket_4->basketno,
467
                datereceived            => undef,
468
                datecancellationprinted => undef,
469
            }
470
        }
471
    );
472
473
    my $orders = Koha::Acquisition::Orders->search(
474
        {
475
            ordernumber => {
476
                -in => [
477
                    $order_1->ordernumber, $order_2->ordernumber,
478
                    $order_3->ordernumber, $order_4->ordernumber,
479
                ]
480
            }
481
        }
482
    );
483
484
    my $late_orders = $orders->filter_by_lates;
485
    is( $late_orders->count, 3 );
486
487
    $late_orders = $orders->filter_by_lates( { delay => 0 } );
488
    is( $late_orders->count, 3 );
489
490
    $late_orders = $orders->filter_by_lates( { delay => 1 } );
491
    is( $late_orders->count, 3 );
492
493
    $late_orders = $orders->filter_by_lates( { delay => 3 } );
494
    is( $late_orders->count, 2 );
495
496
    $late_orders = $orders->filter_by_lates( { delay => 4 } );
497
    is( $late_orders->count, 1 );
498
499
    $late_orders = $orders->filter_by_lates( { delay => 5 } );
500
    is( $late_orders->count, 1 );
501
502
    $late_orders = $orders->filter_by_lates( { delay => 6 } );
503
    is( $late_orders->count, 0 );
504
505
    $late_orders = $orders->filter_by_lates(
506
        { estimated_from => $now->clone->subtract( days => 6 ) } );
507
    is( $late_orders->count,             2 );
508
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
509
510
    $late_orders = $orders->filter_by_lates(
511
        { estimated_from => $now->clone->subtract( days => 5 ) } );
512
    is( $late_orders->count,             2 );
513
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
514
515
    $late_orders = $orders->filter_by_lates(
516
        { estimated_from => $now->clone->subtract( days => 4 ) } );
517
    is( $late_orders->count,             2 );
518
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
519
520
    $late_orders = $orders->filter_by_lates(
521
        { estimated_from => $now->clone->subtract( days => 3 ) } );
522
    is( $late_orders->count, 2 );
523
524
    $late_orders = $orders->filter_by_lates(
525
        { estimated_from => $now->clone->subtract( days => 1 ) } );
526
    is( $late_orders->count, 1 );
527
528
    $late_orders = $orders->filter_by_lates(
529
        {
530
            estimated_from => $now->clone->subtract( days => 4 ),
531
            estimated_to   => $now->clone->subtract( days => 3 )
532
        }
533
    );
534
    is( $late_orders->count, 1 );
535
536
    $schema->storage->txn_rollback;
537
};

Return to bug 24161