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 / +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