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 => 5;
22
use Test::More tests => 8;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
Lines 141-143 subtest 'to_api() tests' => sub { Link Here
141
141
142
    $schema->storage->txn_rollback;
142
    $schema->storage->txn_rollback;
143
};
143
};
144
145
subtest 'estimated_delivery_date' => sub {
146
    plan tests => 4;
147
148
    $schema->storage->txn_begin;
149
    my $bookseller = $builder->build_object(
150
        {
151
            class => 'Koha::Acquisition::Booksellers',
152
            value => {
153
                deliverytime => undef,   # Does not have a delivery time defined
154
            }
155
        }
156
    );
157
158
    my $basket = $builder->build_object(
159
        {
160
            class => 'Koha::Acquisition::Baskets',
161
            value => {
162
                booksellerid => $bookseller->id,
163
                closedate    => undef,             # Still open
164
            }
165
        }
166
    );
167
168
    my $now = dt_from_string;
169
    is( $basket->estimated_delivery_date,
170
        undef, 'return undef if closedate and deliverytime are not defined' );
171
172
    $basket->closedate( $now->clone->subtract( days => 1 ) )
173
      ->store;                                     #Closing the basket
174
    is( $basket->estimated_delivery_date,
175
        undef, 'return undef if deliverytime is not defined' );
176
177
    $basket->closedate(undef)->store;              #Reopening
178
    $bookseller->deliverytime(2)->store;           # 2 delivery days
179
    is( $basket->estimated_delivery_date,
180
        undef, 'return undef if closedate is not defined (basket stil open)' );
181
182
    $bookseller->deliverytime(2)->store;           # 2 delivery days
183
    $basket->closedate( $now->clone->subtract( days => 1 ) )->store; #Closing the basket
184
    is(
185
        $basket->get_from_storage->estimated_delivery_date,
186
        $now->clone->add( days => 1 )->truncate( to => 'day' ),
187
        'Estimated delivery date should be tomorrow if basket closed on yesterday and delivery takes 2 days'
188
    );
189
190
    $schema->storage->txn_rollback;
191
};
192
193
subtest 'late_since_days' => sub {
194
    plan tests => 3;
195
196
    $schema->storage->txn_begin;
197
    my $basket  = $builder->build_object(
198
        {
199
            class => 'Koha::Acquisition::Baskets',
200
        }
201
    );
202
203
    my $now = dt_from_string;
204
    $basket->closedate(undef)->store; # Basket is open
205
    is( $basket->late_since_days, undef, 'return undef if basket is still open');
206
207
    $basket->closedate( $now )->store; #Closing the basket today
208
    is( $basket->late_since_days, 0, 'return 0 if basket has been closed on today' );
209
210
    $basket->closedate( $now->clone->subtract( days => 2 ) )->store;
211
    is( $basket->late_since_days, 2, 'return 2 if basket has been closed 2 days ago' );
212
213
    $schema->storage->txn_rollback;
214
};
215
216
subtest 'authorizer' => sub {
217
    plan tests => 3;
218
219
    $schema->storage->txn_begin;
220
    my $basket = $builder->build_object(
221
        {
222
            class => 'Koha::Acquisition::Baskets',
223
            value => { authorisedby => undef },
224
        }
225
    );
226
227
    my $basket_creator = $builder->build_object( { class => 'Koha::Patrons' } );
228
229
    is( $basket->authorizer, undef,
230
        'authorisedby is null, ->authorized should return undef' );
231
232
    $basket->authorisedby( $basket_creator->borrowernumber )->store;
233
234
    is( ref( $basket->authorizer ),
235
        'Koha::Patron', '->authorized should return a Koha::Patron object' );
236
    is(
237
        $basket->authorizer->borrowernumber,
238
        $basket_creator->borrowernumber,
239
        '->authorized should return the correct creator'
240
    );
241
242
    $schema->storage->txn_rollback;
243
};
(-)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 341-343 subtest 'current_item_level_holds() tests' => sub { Link Here
341
341
342
    $schema->storage->txn_rollback;
342
    $schema->storage->txn_rollback;
343
};
343
};
344
- 
344
345
subtest 'claim*' => sub {
346
    plan tests => 6;
347
348
    $schema->storage->txn_begin;
349
    my $order = $builder->build_object(
350
        {
351
            class => 'Koha::Acquisition::Orders',
352
        }
353
    );
354
355
    my $now = dt_from_string;
356
    is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set');
357
    is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0');
358
    is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef');
359
360
    my $claim_1 = $order->claim;
361
    my $claim_2 = $order->claim;
362
363
    $claim_1->claimed_on($now->clone->subtract(days => 1))->store;
364
365
    is( $order->claims->count, 2, '->claims should return the correct number of claims');
366
    is( $order->claims_count, 2, '->claims_count should return the correct number of claims');
367
    is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim');
368
369
    $schema->storage->txn_rollback;
370
};
371
372
subtest 'filter_by_late' => sub {
373
    plan tests => 16;
374
375
    $schema->storage->txn_begin;
376
    my $now        = dt_from_string;
377
    my $bookseller = $builder->build_object(
378
        {
379
            class => 'Koha::Acquisition::Booksellers',
380
            value => { deliverytime => 2 }
381
        }
382
    );
383
    my $basket_1 = $builder->build_object(
384
        {
385
            class => 'Koha::Acquisition::Baskets',
386
            value => {
387
                booksellerid => $bookseller->id,
388
                closedate    => undef,
389
            }
390
        }
391
    );
392
    my $order_1 = $builder->build_object(
393
        {
394
            class => 'Koha::Acquisition::Orders',
395
            value => {
396
                basketno                => $basket_1->basketno,
397
                datereceived            => undef,
398
                datecancellationprinted => undef,
399
            }
400
        }
401
    );
402
    my $basket_2 = $builder->build_object(    # expected tomorrow
403
        {
404
            class => 'Koha::Acquisition::Baskets',
405
            value => {
406
                booksellerid => $bookseller->id,
407
                closedate    => $now->clone->subtract( days => 1 ),
408
            }
409
        }
410
    );
411
    my $order_2 = $builder->build_object(
412
        {
413
            class => 'Koha::Acquisition::Orders',
414
            value => {
415
                basketno                => $basket_2->basketno,
416
                datereceived            => undef,
417
                datecancellationprinted => undef,
418
            }
419
        }
420
    );
421
    my $basket_3 = $builder->build_object(    # expected yesterday (1 day)
422
        {
423
            class => 'Koha::Acquisition::Baskets',
424
            value => {
425
                booksellerid => $bookseller->id,
426
                closedate    => $now->clone->subtract( days => 3 ),
427
            }
428
        }
429
    );
430
    my $order_3 = $builder->build_object(
431
        {
432
            class => 'Koha::Acquisition::Orders',
433
            value => {
434
                basketno                => $basket_3->basketno,
435
                datereceived            => undef,
436
                datecancellationprinted => undef,
437
            }
438
        }
439
    );
440
    my $basket_4 = $builder->build_object(    # expected 3 days ago
441
        {
442
            class => 'Koha::Acquisition::Baskets',
443
            value => {
444
                booksellerid => $bookseller->id,
445
                closedate    => $now->clone->subtract( days => 5 ),
446
            }
447
        }
448
    );
449
    my $order_4 = $builder->build_object(
450
        {
451
            class => 'Koha::Acquisition::Orders',
452
            value => {
453
                basketno                => $basket_4->basketno,
454
                datereceived            => undef,
455
                datecancellationprinted => undef,
456
            }
457
        }
458
    );
459
460
    my $orders = Koha::Acquisition::Orders->search(
461
        {
462
            ordernumber => {
463
                -in => [
464
                    $order_1->ordernumber, $order_2->ordernumber,
465
                    $order_3->ordernumber, $order_4->ordernumber,
466
                ]
467
            }
468
        }
469
    );
470
471
    my $late_orders = $orders->filter_by_lates;
472
    is( $late_orders->count, 3 );
473
474
    $late_orders = $orders->filter_by_lates( { delay => 0 } );
475
    is( $late_orders->count, 3 );
476
477
    $late_orders = $orders->filter_by_lates( { delay => 1 } );
478
    is( $late_orders->count, 3 );
479
480
    $late_orders = $orders->filter_by_lates( { delay => 3 } );
481
    is( $late_orders->count, 2 );
482
483
    $late_orders = $orders->filter_by_lates( { delay => 4 } );
484
    is( $late_orders->count, 1 );
485
486
    $late_orders = $orders->filter_by_lates( { delay => 5 } );
487
    is( $late_orders->count, 1 );
488
489
    $late_orders = $orders->filter_by_lates( { delay => 6 } );
490
    is( $late_orders->count, 0 );
491
492
    $late_orders = $orders->filter_by_lates(
493
        { estimated_from => $now->clone->subtract( days => 6 ) } );
494
    is( $late_orders->count,             2 );
495
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
496
497
    $late_orders = $orders->filter_by_lates(
498
        { estimated_from => $now->clone->subtract( days => 5 ) } );
499
    is( $late_orders->count,             2 );
500
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
501
502
    $late_orders = $orders->filter_by_lates(
503
        { estimated_from => $now->clone->subtract( days => 4 ) } );
504
    is( $late_orders->count,             2 );
505
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
506
507
    $late_orders = $orders->filter_by_lates(
508
        { estimated_from => $now->clone->subtract( days => 3 ) } );
509
    is( $late_orders->count, 2 );
510
511
    $late_orders = $orders->filter_by_lates(
512
        { estimated_from => $now->clone->subtract( days => 1 ) } );
513
    is( $late_orders->count, 1 );
514
515
    $late_orders = $orders->filter_by_lates(
516
        {
517
            estimated_from => $now->clone->subtract( days => 4 ),
518
            estimated_to   => $now->clone->subtract( days => 3 )
519
        }
520
    );
521
    is( $late_orders->count, 1 );
522
523
    $schema->storage->txn_rollback;
524
};

Return to bug 24161