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

(-)a/t/db_dependent/Koha/Acquisition/Basket.t (-1 / +102 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 7;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
26
use C4::Acquisition;
26
use C4::Acquisition;
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
29
29
use_ok('Koha::Acquisition::Basket');
30
use_ok('Koha::Acquisition::Basket');
30
use_ok('Koha::Acquisition::Baskets');
31
use_ok('Koha::Acquisition::Baskets');
Lines 107-109 subtest 'basket_group' => sub { Link Here
107
108
108
    $schema->storage->txn_rollback;
109
    $schema->storage->txn_rollback;
109
};
110
};
111
112
subtest 'estimated_delivery_date' => sub {
113
    plan tests => 4;
114
115
    $schema->storage->txn_begin;
116
    my $bookseller = $builder->build_object(
117
        {
118
            class => 'Koha::Acquisition::Booksellers',
119
            value => {
120
                deliverytime => undef,   # Does not have a delivery time defined
121
            }
122
        }
123
    );
124
125
    my $basket = $builder->build_object(
126
        {
127
            class => 'Koha::Acquisition::Baskets',
128
            value => {
129
                booksellerid => $bookseller->id,
130
                closedate    => undef,             # Still open
131
            }
132
        }
133
    );
134
135
    my $now = dt_from_string;
136
    is( $basket->estimated_delivery_date,
137
        undef, 'return undef if closedate and deliverytime are not defined' );
138
139
    $basket->closedate( $now->clone->subtract( days => 1 ) )
140
      ->store;                                     #Closing the basket
141
    is( $basket->estimated_delivery_date,
142
        undef, 'return undef if deliverytime is not defined' );
143
144
    $basket->closedate(undef)->store;              #Reopening
145
    $bookseller->deliverytime(2)->store;           # 2 delivery days
146
    is( $basket->estimated_delivery_date,
147
        undef, 'return undef if closedate is not defined (basket stil open)' );
148
149
    $bookseller->deliverytime(2)->store;           # 2 delivery days
150
    $basket->closedate( $now->clone->subtract( days => 1 ) )->store; #Closing the basket
151
    is(
152
        $basket->get_from_storage->estimated_delivery_date,
153
        $now->clone->add( days => 1 )->truncate( to => 'day' ),
154
        'Estimated delivery date should be tomorrow if basket closed on yesterday and delivery takes 2 days'
155
    );
156
157
    $schema->storage->txn_rollback;
158
};
159
160
subtest 'late_since_days' => sub {
161
    plan tests => 3;
162
163
    $schema->storage->txn_begin;
164
    my $basket  = $builder->build_object(
165
        {
166
            class => 'Koha::Acquisition::Baskets',
167
        }
168
    );
169
170
    my $now = dt_from_string;
171
    $basket->closedate(undef)->store; # Basket is open
172
    is( $basket->late_since_days, undef, 'return undef if basket is still open');
173
174
    $basket->closedate( $now )->store; #Closing the basket today
175
    is( $basket->late_since_days, 0, 'return 0 if basket has been closed on today' );
176
177
    $basket->closedate( $now->clone->subtract( days => 2 ) )->store;
178
    is( $basket->late_since_days, 2, 'return 2 if basket has been closed 2 days ago' );
179
180
    $schema->storage->txn_rollback;
181
};
182
183
subtest 'authorizer' => sub {
184
    plan tests => 3;
185
186
    $schema->storage->txn_begin;
187
    my $basket = $builder->build_object(
188
        {
189
            class => 'Koha::Acquisition::Baskets',
190
            value => { authorisedby => undef },
191
        }
192
    );
193
194
    my $basket_creator = $builder->build_object( { class => 'Koha::Patrons' } );
195
196
    is( $basket->authorizer, undef,
197
        'authorisedby is null, ->authorized should return undef' );
198
199
    $basket->authorisedby( $basket_creator->borrowernumber )->store;
200
201
    is( ref( $basket->authorizer ),
202
        'Koha::Patron', '->authorized should return a Koha::Patron object' );
203
    is(
204
        $basket->authorizer->borrowernumber,
205
        $basket_creator->borrowernumber,
206
        '->authorized should return the correct creator'
207
    );
208
209
    $schema->storage->txn_rollback;
210
};
(-)a/t/db_dependent/Koha/Acquisition/Order.t (-2 / +183 lines)
Lines 19-30 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 => 8;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
29
29
my $schema  = Koha::Database->schema;
30
my $schema  = Koha::Database->schema;
30
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
Lines 250-252 subtest 'duplicate_to | add_item' => sub { Link Here
250
251
251
    $schema->storage->txn_rollback;
252
    $schema->storage->txn_rollback;
252
};
253
};
253
- 
254
255
subtest 'claim*' => sub {
256
    plan tests => 6;
257
258
    $schema->storage->txn_begin;
259
    my $order = $builder->build_object(
260
        {
261
            class => 'Koha::Acquisition::Orders',
262
        }
263
    );
264
265
    my $now = dt_from_string;
266
    is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set');
267
    is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0');
268
    is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef');
269
270
    my $claim_1 = $order->claim;
271
    my $claim_2 = $order->claim;
272
273
    $claim_1->claimed_on($now->clone->subtract(days => 1))->store;
274
275
    is( $order->claims->count, 2, '->claims should return the correct number of claims');
276
    is( $order->claims_count, 2, '->claims_count should return the correct number of claims');
277
    is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim');
278
279
    $schema->storage->txn_rollback;
280
};
281
282
subtest 'filter_by_late' => sub {
283
    plan tests => 16;
284
285
    $schema->storage->txn_begin;
286
    my $now        = dt_from_string;
287
    my $bookseller = $builder->build_object(
288
        {
289
            class => 'Koha::Acquisition::Booksellers',
290
            value => { deliverytime => 2 }
291
        }
292
    );
293
    my $basket_1 = $builder->build_object(
294
        {
295
            class => 'Koha::Acquisition::Baskets',
296
            value => {
297
                booksellerid => $bookseller->id,
298
                closedate    => undef,
299
            }
300
        }
301
    );
302
    my $order_1 = $builder->build_object(
303
        {
304
            class => 'Koha::Acquisition::Orders',
305
            value => {
306
                basketno                => $basket_1->basketno,
307
                datereceived            => undef,
308
                datecancellationprinted => undef,
309
            }
310
        }
311
    );
312
    my $basket_2 = $builder->build_object(    # expected tomorrow
313
        {
314
            class => 'Koha::Acquisition::Baskets',
315
            value => {
316
                booksellerid => $bookseller->id,
317
                closedate    => $now->clone->subtract( days => 1 ),
318
            }
319
        }
320
    );
321
    my $order_2 = $builder->build_object(
322
        {
323
            class => 'Koha::Acquisition::Orders',
324
            value => {
325
                basketno                => $basket_2->basketno,
326
                datereceived            => undef,
327
                datecancellationprinted => undef,
328
            }
329
        }
330
    );
331
    my $basket_3 = $builder->build_object(    # expected yesterday (1 day)
332
        {
333
            class => 'Koha::Acquisition::Baskets',
334
            value => {
335
                booksellerid => $bookseller->id,
336
                closedate    => $now->clone->subtract( days => 3 ),
337
            }
338
        }
339
    );
340
    my $order_3 = $builder->build_object(
341
        {
342
            class => 'Koha::Acquisition::Orders',
343
            value => {
344
                basketno                => $basket_3->basketno,
345
                datereceived            => undef,
346
                datecancellationprinted => undef,
347
            }
348
        }
349
    );
350
    my $basket_4 = $builder->build_object(    # expected 3 days ago
351
        {
352
            class => 'Koha::Acquisition::Baskets',
353
            value => {
354
                booksellerid => $bookseller->id,
355
                closedate    => $now->clone->subtract( days => 5 ),
356
            }
357
        }
358
    );
359
    my $order_4 = $builder->build_object(
360
        {
361
            class => 'Koha::Acquisition::Orders',
362
            value => {
363
                basketno                => $basket_4->basketno,
364
                datereceived            => undef,
365
                datecancellationprinted => undef,
366
            }
367
        }
368
    );
369
370
    my $orders = Koha::Acquisition::Orders->search(
371
        {
372
            ordernumber => {
373
                -in => [
374
                    $order_1->ordernumber, $order_2->ordernumber,
375
                    $order_3->ordernumber, $order_4->ordernumber,
376
                ]
377
            }
378
        }
379
    );
380
381
    my $late_orders = $orders->filter_by_lates;
382
    is( $late_orders->count, 3 );
383
384
    $late_orders = $orders->filter_by_lates( { delay => 0 } );
385
    is( $late_orders->count, 3 );
386
387
    $late_orders = $orders->filter_by_lates( { delay => 1 } );
388
    is( $late_orders->count, 3 );
389
390
    $late_orders = $orders->filter_by_lates( { delay => 3 } );
391
    is( $late_orders->count, 2 );
392
393
    $late_orders = $orders->filter_by_lates( { delay => 4 } );
394
    is( $late_orders->count, 1 );
395
396
    $late_orders = $orders->filter_by_lates( { delay => 5 } );
397
    is( $late_orders->count, 1 );
398
399
    $late_orders = $orders->filter_by_lates( { delay => 6 } );
400
    is( $late_orders->count, 0 );
401
402
    $late_orders = $orders->filter_by_lates(
403
        { estimated_from => $now->clone->subtract( days => 6 ) } );
404
    is( $late_orders->count,             2 );
405
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
406
407
    $late_orders = $orders->filter_by_lates(
408
        { estimated_from => $now->clone->subtract( days => 5 ) } );
409
    is( $late_orders->count,             2 );
410
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
411
412
    $late_orders = $orders->filter_by_lates(
413
        { estimated_from => $now->clone->subtract( days => 4 ) } );
414
    is( $late_orders->count,             2 );
415
    is( $late_orders->next->ordernumber, $order_3->ordernumber );
416
417
    $late_orders = $orders->filter_by_lates(
418
        { estimated_from => $now->clone->subtract( days => 3 ) } );
419
    is( $late_orders->count, 2 );
420
421
    $late_orders = $orders->filter_by_lates(
422
        { estimated_from => $now->clone->subtract( days => 1 ) } );
423
    is( $late_orders->count, 1 );
424
425
    $late_orders = $orders->filter_by_lates(
426
        {
427
            estimated_from => $now->clone->subtract( days => 4 ),
428
            estimated_to   => $now->clone->subtract( days => 3 )
429
        }
430
    );
431
    is( $late_orders->count, 1 );
432
433
    $schema->storage->txn_rollback;
434
};

Return to bug 24161