Bugzilla – Attachment 102116 Details for
Bug 24161
Add ability to track the claim dates of later orders
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24161: Add tests
Bug-24161-Add-tests.patch (text/plain), 10.61 KB, created by
Martin Renvoize (ashimema)
on 2020-03-31 09:50:38 UTC
(
hide
)
Description:
Bug 24161: Add tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-03-31 09:50:38 UTC
Size:
10.61 KB
patch
obsolete
>From b634b8e8b0a96d702ff41379721bc024dae45bec Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 8 Jan 2020 23:47:02 +0100 >Subject: [PATCH] Bug 24161: Add tests > >Sponsored-by: Cork Institute of Technology >--- > t/db_dependent/Koha/Acquisition/Basket.t | 102 ++++++++++++- > t/db_dependent/Koha/Acquisition/Order.t | 183 ++++++++++++++++++++++- > 2 files changed, 283 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t >index dfa7b6fab3..dc2232de2d 100644 >--- a/t/db_dependent/Koha/Acquisition/Basket.t >+++ b/t/db_dependent/Koha/Acquisition/Basket.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 9; > use t::lib::TestBuilder; > use t::lib::Mocks; > >@@ -171,3 +171,103 @@ subtest 'to_api() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'estimated_delivery_date' => sub { >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ my $bookseller = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Booksellers', >+ value => { >+ deliverytime => undef, # Does not have a delivery time defined >+ } >+ } >+ ); >+ >+ my $basket = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { >+ booksellerid => $bookseller->id, >+ closedate => undef, # Still open >+ } >+ } >+ ); >+ >+ my $now = dt_from_string; >+ is( $basket->estimated_delivery_date, >+ undef, 'return undef if closedate and deliverytime are not defined' ); >+ >+ $basket->closedate( $now->clone->subtract( days => 1 ) ) >+ ->store; #Closing the basket >+ is( $basket->estimated_delivery_date, >+ undef, 'return undef if deliverytime is not defined' ); >+ >+ $basket->closedate(undef)->store; #Reopening >+ $bookseller->deliverytime(2)->store; # 2 delivery days >+ is( $basket->estimated_delivery_date, >+ undef, 'return undef if closedate is not defined (basket stil open)' ); >+ >+ $bookseller->deliverytime(2)->store; # 2 delivery days >+ $basket->closedate( $now->clone->subtract( days => 1 ) )->store; #Closing the basket >+ is( >+ $basket->get_from_storage->estimated_delivery_date, >+ $now->clone->add( days => 1 )->truncate( to => 'day' ), >+ 'Estimated delivery date should be tomorrow if basket closed on yesterday and delivery takes 2 days' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'late_since_days' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ my $basket = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Baskets', >+ } >+ ); >+ >+ my $now = dt_from_string; >+ $basket->closedate(undef)->store; # Basket is open >+ is( $basket->late_since_days, undef, 'return undef if basket is still open'); >+ >+ $basket->closedate( $now )->store; #Closing the basket today >+ is( $basket->late_since_days, 0, 'return 0 if basket has been closed on today' ); >+ >+ $basket->closedate( $now->clone->subtract( days => 2 ) )->store; >+ is( $basket->late_since_days, 2, 'return 2 if basket has been closed 2 days ago' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'authorizer' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ my $basket = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { authorisedby => undef }, >+ } >+ ); >+ >+ my $basket_creator = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ is( $basket->authorizer, undef, >+ 'authorisedby is null, ->authorized should return undef' ); >+ >+ $basket->authorisedby( $basket_creator->borrowernumber )->store; >+ >+ is( ref( $basket->authorizer ), >+ 'Koha::Patron', '->authorized should return a Koha::Patron object' ); >+ is( >+ $basket->authorizer->borrowernumber, >+ $basket_creator->borrowernumber, >+ '->authorized should return the correct creator' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t >index f62f3ebcf2..4acccfa0c6 100644 >--- a/t/db_dependent/Koha/Acquisition/Order.t >+++ b/t/db_dependent/Koha/Acquisition/Order.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 10; > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -347,3 +347,184 @@ subtest 'current_item_level_holds() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'claim*' => sub { >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ my $order = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ } >+ ); >+ >+ my $now = dt_from_string; >+ is( $order->claims->count, 0, 'No claim yet, ->claims should return an empty set'); >+ is( $order->claims_count, 0, 'No claim yet, ->claims_count should return 0'); >+ is( $order->claimed_date, undef, 'No claim yet, ->claimed_date should return undef'); >+ >+ my $claim_1 = $order->claim; >+ my $claim_2 = $order->claim; >+ >+ $claim_1->claimed_on($now->clone->subtract(days => 1))->store; >+ >+ is( $order->claims->count, 2, '->claims should return the correct number of claims'); >+ is( $order->claims_count, 2, '->claims_count should return the correct number of claims'); >+ is( dt_from_string($order->claimed_date), $now, '->claimed_date should return the date of the last claim'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'filter_by_late' => sub { >+ plan tests => 16; >+ >+ $schema->storage->txn_begin; >+ my $now = dt_from_string; >+ my $bookseller = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Booksellers', >+ value => { deliverytime => 2 } >+ } >+ ); >+ my $basket_1 = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { >+ booksellerid => $bookseller->id, >+ closedate => undef, >+ } >+ } >+ ); >+ my $order_1 = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ basketno => $basket_1->basketno, >+ datereceived => undef, >+ datecancellationprinted => undef, >+ } >+ } >+ ); >+ my $basket_2 = $builder->build_object( # expected tomorrow >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { >+ booksellerid => $bookseller->id, >+ closedate => $now->clone->subtract( days => 1 ), >+ } >+ } >+ ); >+ my $order_2 = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ basketno => $basket_2->basketno, >+ datereceived => undef, >+ datecancellationprinted => undef, >+ } >+ } >+ ); >+ my $basket_3 = $builder->build_object( # expected yesterday (1 day) >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { >+ booksellerid => $bookseller->id, >+ closedate => $now->clone->subtract( days => 3 ), >+ } >+ } >+ ); >+ my $order_3 = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ basketno => $basket_3->basketno, >+ datereceived => undef, >+ datecancellationprinted => undef, >+ } >+ } >+ ); >+ my $basket_4 = $builder->build_object( # expected 3 days ago >+ { >+ class => 'Koha::Acquisition::Baskets', >+ value => { >+ booksellerid => $bookseller->id, >+ closedate => $now->clone->subtract( days => 5 ), >+ } >+ } >+ ); >+ my $order_4 = $builder->build_object( >+ { >+ class => 'Koha::Acquisition::Orders', >+ value => { >+ basketno => $basket_4->basketno, >+ datereceived => undef, >+ datecancellationprinted => undef, >+ } >+ } >+ ); >+ >+ my $orders = Koha::Acquisition::Orders->search( >+ { >+ ordernumber => { >+ -in => [ >+ $order_1->ordernumber, $order_2->ordernumber, >+ $order_3->ordernumber, $order_4->ordernumber, >+ ] >+ } >+ } >+ ); >+ >+ my $late_orders = $orders->filter_by_lates; >+ is( $late_orders->count, 3 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 0 } ); >+ is( $late_orders->count, 3 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 1 } ); >+ is( $late_orders->count, 3 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 3 } ); >+ is( $late_orders->count, 2 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 4 } ); >+ is( $late_orders->count, 1 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 5 } ); >+ is( $late_orders->count, 1 ); >+ >+ $late_orders = $orders->filter_by_lates( { delay => 6 } ); >+ is( $late_orders->count, 0 ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { estimated_from => $now->clone->subtract( days => 6 ) } ); >+ is( $late_orders->count, 2 ); >+ is( $late_orders->next->ordernumber, $order_3->ordernumber ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { estimated_from => $now->clone->subtract( days => 5 ) } ); >+ is( $late_orders->count, 2 ); >+ is( $late_orders->next->ordernumber, $order_3->ordernumber ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { estimated_from => $now->clone->subtract( days => 4 ) } ); >+ is( $late_orders->count, 2 ); >+ is( $late_orders->next->ordernumber, $order_3->ordernumber ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { estimated_from => $now->clone->subtract( days => 3 ) } ); >+ is( $late_orders->count, 2 ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { estimated_from => $now->clone->subtract( days => 1 ) } ); >+ is( $late_orders->count, 1 ); >+ >+ $late_orders = $orders->filter_by_lates( >+ { >+ estimated_from => $now->clone->subtract( days => 4 ), >+ estimated_to => $now->clone->subtract( days => 3 ) >+ } >+ ); >+ is( $late_orders->count, 1 ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24161
:
97114
|
97115
|
97116
|
97117
|
97118
|
97119
|
97470
|
97471
|
97472
|
98280
|
98522
|
98523
|
98524
|
98525
|
98526
|
98527
|
102111
|
102112
|
102113
|
102114
|
102115
|
102116
|
102220
|
102222
|
103567
|
103568
|
103569
|
103570
|
103571
|
103588
|
103589
|
103590
|
103591
|
103592
|
103593
|
103594
|
103595
|
104190
|
104191
|
104207
|
104208
|
104209
|
104210
|
104211
|
104212
|
104213
|
104214
|
104215
|
104216
|
104258
|
104259
|
104265
|
104826
|
104848