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 347-349 subtest 'current_item_level_holds() tests' => sub { Link Here
347
347
348
    $schema->storage->txn_rollback;
348
    $schema->storage->txn_rollback;
349
};
349
};
350
- 
350
351
subtest 'claim*' => sub {
352
    plan tests => 6;
353
354
    $schema->storage->txn_begin;
355
    my $order = $builder->build_object(
356
        {
357
            class => 'Koha::Acquisition::Orders',
358
        }
359
    );
360
361
    my $now = dt_from_string;
362
    is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set');
363
    is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0');
364
    is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef');
365
366
    my $claim_1 = $order->claim;
367
    my $claim_2 = $order->claim;
368
369
    $claim_1->claimed_on($now->clone->subtract(days => 1))->store;
370
371
    is( $order->claims->count, 2, '->claims should return the correct number of claims');
372
    is( $order->claims_count, 2, '->claims_count should return the correct number of claims');
373
    is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim');
374
375
    $schema->storage->txn_rollback;
376
};
377
378
subtest 'filter_by_late' => sub {
379
    plan tests => 16;
380
381
    $schema->storage->txn_begin;
382
    my $now        = dt_from_string;
383
    my $bookseller = $builder->build_object(
384
        {
385
            class => 'Koha::Acquisition::Booksellers',
386
            value => { deliverytime => 2 }
387
        }
388
    );
389
    my $basket_1 = $builder->build_object(
390
        {
391
            class => 'Koha::Acquisition::Baskets',
392
            value => {
393
                booksellerid => $bookseller->id,
394
                closedate    => undef,
395
            }
396
        }
397
    );
398
    my $order_1 = $builder->build_object(
399
        {
400
            class => 'Koha::Acquisition::Orders',
401
            value => {
402
                basketno                => $basket_1->basketno,
403
                datereceived            => undef,
404
                datecancellationprinted => undef,
405
            }
406
        }
407
    );
408
    my $basket_2 = $builder->build_object(    # expected tomorrow
409
        {
410
            class => 'Koha::Acquisition::Baskets',
411
            value => {
412
                booksellerid => $bookseller->id,
413
                closedate    => $now->clone->subtract( days => 1 ),
414
            }
415
        }
416
    );
417
    my $order_2 = $builder->build_object(
418
        {
419
            class => 'Koha::Acquisition::Orders',
420
            value => {
421
                basketno                => $basket_2->basketno,
422
                datereceived            => undef,
423
                datecancellationprinted => undef,
424
            }
425
        }
426
    );
427
    my $basket_3 = $builder->build_object(    # expected yesterday (1 day)
428
        {
429
            class => 'Koha::Acquisition::Baskets',
430
            value => {
431
                booksellerid => $bookseller->id,
432
                closedate    => $now->clone->subtract( days => 3 ),
433
            }
434
        }
435
    );
436
    my $order_3 = $builder->build_object(
437
        {
438
            class => 'Koha::Acquisition::Orders',
439
            value => {
440
                basketno                => $basket_3->basketno,
441
                datereceived            => undef,
442
                datecancellationprinted => undef,
443
            }
444
        }
445
    );
446
    my $basket_4 = $builder->build_object(    # expected 3 days ago
447
        {
448
            class => 'Koha::Acquisition::Baskets',
449
            value => {
450
                booksellerid => $bookseller->id,
451
                closedate    => $now->clone->subtract( days => 5 ),
452
            }
453
        }
454
    );
455
    my $order_4 = $builder->build_object(
456
        {
457
            class => 'Koha::Acquisition::Orders',
458
            value => {
459
                basketno                => $basket_4->basketno,
460
                datereceived            => undef,
461
                datecancellationprinted => undef,
462
            }
463
        }
464
    );
465
466
    my $orders = Koha::Acquisition::Orders->search(
467
        {
468
            ordernumber => {
469
                -in => [
470
                    $order_1->ordernumber, $order_2->ordernumber,
471
                    $order_3->ordernumber, $order_4->ordernumber,
472
                ]
473
            }
474
        }
475
    );
476
477
    my $late_orders = $orders->filter_by_lates;
478
    is( $late_orders->count, 3 );
479
480
    $late_orders = $orders->filter_by_lates( { delay => 0 } );
481
    is( $late_orders->count, 3 );
482
483
    $late_orders = $orders->filter_by_lates( { delay => 1 } );
484
    is( $late_orders->count, 3 );
485
486
    $late_orders = $orders->filter_by_lates( { delay => 3 } );
487
    is( $late_orders->count, 2 );
488
489
    $late_orders = $orders->filter_by_lates( { delay => 4 } );
490
    is( $late_orders->count, 1 );
491
492
    $late_orders = $orders->filter_by_lates( { delay => 5 } );
493
    is( $late_orders->count, 1 );
494
495
    $late_orders = $orders->filter_by_lates( { delay => 6 } );
496
    is( $late_orders->count, 0 );
497
498
    $late_orders = $orders->filter_by_lates(
499
        { estimated_from => $now->clone->subtract( days => 6 ) } );
500
    is( $late_orders->count,             2 );
501
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
502
503
    $late_orders = $orders->filter_by_lates(
504
        { estimated_from => $now->clone->subtract( days => 5 ) } );
505
    is( $late_orders->count,             2 );
506
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
507
508
    $late_orders = $orders->filter_by_lates(
509
        { estimated_from => $now->clone->subtract( days => 4 ) } );
510
    is( $late_orders->count,             2 );
511
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
512
513
    $late_orders = $orders->filter_by_lates(
514
        { estimated_from => $now->clone->subtract( days => 3 ) } );
515
    is( $late_orders->count, 2 );
516
517
    $late_orders = $orders->filter_by_lates(
518
        { estimated_from => $now->clone->subtract( days => 1 ) } );
519
    is( $late_orders->count, 1 );
520
521
    $late_orders = $orders->filter_by_lates(
522
        {
523
            estimated_from => $now->clone->subtract( days => 4 ),
524
            estimated_to   => $now->clone->subtract( days => 3 )
525
        }
526
    );
527
    is( $late_orders->count, 1 );
528
529
    $schema->storage->txn_rollback;
530
};

Return to bug 24161