Bugzilla – Attachment 134858 Details for
Bug 30728
Allow real-time holds queue opt-out
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30728: Add unit tests
Bug-30728-Add-unit-tests.patch (text/plain), 13.80 KB, created by
Martin Renvoize (ashimema)
on 2022-05-11 10:02:12 UTC
(
hide
)
Description:
Bug 30728: Add unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-05-11 10:02:12 UTC
Size:
13.80 KB
patch
obsolete
>From 9132d9e8270854299e2e39639d34613b8c879c0d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 10 May 2022 14:17:37 -0300 >Subject: [PATCH] Bug 30728: Add unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Biblio.t | 9 ++--- > t/db_dependent/Biblio_holdsqueue.t | 24 +++++++++++++ > t/db_dependent/Circulation_holdsqueue.t | 9 +++++ > .../Koha/BackgroundJobs/BatchDeleteBiblio.t | 29 +++++++++++++++- > .../Koha/BackgroundJobs/BatchDeleteItem.t | 34 +++++++++++++++++-- > t/db_dependent/Koha/Hold.t | 29 ++++++++++++++++ > t/db_dependent/Koha/Item.t | 6 ++++ > t/db_dependent/Reserves.t | 27 +++++++++++++++ > 8 files changed, 158 insertions(+), 9 deletions(-) > >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index 1ffa0143cb..7afa3e29f4 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -251,8 +251,7 @@ sub run_tests { > # roll back ES index changes. > t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); > >- my $bgj_mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >- $bgj_mock->mock( 'enqueue', undef ); >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); > > my $isbn = '0590353403'; > my $title = 'Foundation'; >@@ -639,8 +638,7 @@ subtest 'IsMarcStructureInternal' => sub { > subtest 'deletedbiblio_metadata' => sub { > plan tests => 2; > >- my $bgj_mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >- $bgj_mock->mock( 'enqueue', undef ); >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); > > my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); > my $biblio_metadata = C4::Biblio::GetXmlBiblio( $biblionumber ); >@@ -655,8 +653,7 @@ subtest 'DelBiblio' => sub { > > plan tests => 5; > >- my $bgj_mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >- $bgj_mock->mock( 'enqueue', undef ); >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); > > my ($biblionumber, $biblioitemnumber) = C4::Biblio::AddBiblio(MARC::Record->new, ''); > my $deleted = C4::Biblio::DelBiblio( $biblionumber ); >diff --git a/t/db_dependent/Biblio_holdsqueue.t b/t/db_dependent/Biblio_holdsqueue.t >index 5753a3ca94..4c687a69ba 100755 >--- a/t/db_dependent/Biblio_holdsqueue.t >+++ b/t/db_dependent/Biblio_holdsqueue.t >@@ -36,6 +36,8 @@ subtest 'ModBiblio() + holds_queue update tests' => sub { > > my $biblio = $builder->build_sample_biblio; > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); > $mock->mock( 'enqueue', sub { > my ( $self, $args ) = @_; >@@ -69,6 +71,20 @@ subtest 'ModBiblio() + holds_queue update tests' => sub { > $biblio->frameworkcode, { skip_holds_queue => 1 } > ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ # this call should not trigger the mocked 'enqueue' >+ C4::Biblio::ModBiblio( >+ $biblio->metadata->record, $biblio->id, >+ $biblio->frameworkcode, { skip_holds_queue => 0 } >+ ); >+ >+ # this call shoul not trigger the mocked 'enqueue' >+ C4::Biblio::ModBiblio( >+ $biblio->metadata->record, $biblio->id, >+ $biblio->frameworkcode, { skip_holds_queue => 1 } >+ ); >+ > $schema->storage->txn_rollback; > }; > >@@ -78,6 +94,8 @@ subtest 'DelBiblio + holds_queue update tests' => sub { > > $schema->storage->txn_begin; > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > my $biblio = $builder->build_sample_biblio; > > my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >@@ -102,5 +120,11 @@ subtest 'DelBiblio + holds_queue update tests' => sub { > > C4::Biblio::DelBiblio( $biblio->id ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $biblio = $builder->build_sample_biblio; >+ >+ C4::Biblio::DelBiblio( $biblio->id ); >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Circulation_holdsqueue.t b/t/db_dependent/Circulation_holdsqueue.t >index 3b542f9913..61d8294076 100755 >--- a/t/db_dependent/Circulation_holdsqueue.t >+++ b/t/db_dependent/Circulation_holdsqueue.t >@@ -42,6 +42,7 @@ subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { > > t::lib::Mocks::mock_userenv({ branchcode => $library->id }); > t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 ); >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); > > my $action; > >@@ -62,5 +63,13 @@ subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { > $action = 'AddReturn'; > AddReturn( $item->barcode ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $action = 'AddIssue'; >+ AddIssue( $patron->unblessed, $item->barcode, ); >+ >+ $action = 'AddReturn'; >+ AddReturn( $item->barcode ); >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteBiblio.t b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteBiblio.t >index b2d80491aa..60e60ed049 100755 >--- a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteBiblio.t >+++ b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteBiblio.t >@@ -28,6 +28,7 @@ use Koha::Database; > use Koha::BackgroundJob::BatchDeleteBiblio; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >@@ -35,7 +36,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest "process() tests" => sub { > >- plan tests => 1; >+ plan tests => 2; > > $schema->storage->txn_begin; > >@@ -72,6 +73,8 @@ subtest "process() tests" => sub { > } > ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > $job->process( > { > record_ids => [ $biblio->id ], >@@ -80,5 +83,29 @@ subtest "process() tests" => sub { > > is( $counter, 1, 'Holds queue update is enqueued only once' ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $biblio = $builder->build_sample_biblio; >+ >+ $job = Koha::BackgroundJob::BatchDeleteBiblio->new( >+ { >+ status => 'new', >+ size => 1, >+ borrowernumber => undef, >+ type => 'batch_biblio_record_deletion', >+ data => encode_json { >+ record_ids => [ $biblio->id ], >+ } >+ } >+ ); >+ >+ $job->process( >+ { >+ record_ids => [ $biblio->id ], >+ } >+ ); >+ >+ is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' ); >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t >index a3779f0b1f..ee40088c8c 100755 >--- a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t >+++ b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t >@@ -25,6 +25,7 @@ use JSON qw( encode_json ); > use Koha::Database; > use Koha::BackgroundJob::BatchDeleteItem; > >+use t::lib::Mocks; > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >@@ -32,7 +33,7 @@ my $builder = t::lib::TestBuilder->new; > > subtest "process() tests" => sub { > >- plan tests => 1; >+ plan tests => 2; > > $schema->storage->txn_begin; > >@@ -47,12 +48,14 @@ subtest "process() tests" => sub { > $counter++; > }); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > my $job = Koha::BackgroundJob::BatchDeleteItem->new( > { > status => 'new', > size => 2, > borrowernumber => undef, >- type => 'batch_biblio_record_modification', >+ type => 'batch_item_record_deletion', > data => encode_json { > record_ids => [ $item_1->id, $item_2->id ], > delete_biblios => 1, >@@ -69,5 +72,32 @@ subtest "process() tests" => sub { > > is( $counter, 1, 'Holds queue update is enqueued only once' ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $biblio = $builder->build_sample_biblio; >+ my $item = $builder->build_sample_item({ biblionumber => $biblio->id }); >+ >+ $job = Koha::BackgroundJob::BatchDeleteItem->new( >+ { >+ status => 'new', >+ size => 2, >+ borrowernumber => undef, >+ type => 'batch_item_record_deletion', >+ data => encode_json { >+ record_ids => [ $item->id ], >+ delete_biblios => 1, >+ } >+ } >+ ); >+ >+ $job->process( >+ { >+ record_ids => [ $item->id ], >+ delete_biblios => 1, >+ } >+ ); >+ >+ is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' ); >+ > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 9547e353a2..8c32bda3f7 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -249,6 +249,19 @@ subtest 'fill() tests' => sub { > ); > } ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ >+ $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ )->fill; >+ >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ # this call shouldn't add a new test > $builder->build_object( > { > class => 'Koha::Holds', >@@ -558,6 +571,8 @@ subtest 'cancel() tests' => sub { > > my $biblio = $builder->build_sample_biblio; > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); > $mock->mock( 'enqueue', sub { > my ( $self, $args ) = @_; >@@ -586,6 +601,17 @@ subtest 'cancel() tests' => sub { > } > } > )->cancel({ skip_holds_queue => 1 }); >+ >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $biblio->id, >+ } >+ } >+ )->cancel({ skip_holds_queue => 0 }); > }; > > $schema->storage->txn_rollback; >@@ -600,6 +626,8 @@ subtest 'suspend_hold() and resume() tests' => sub { > my $biblio = $builder->build_sample_biblio; > my $action; > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); > $mock->mock( 'enqueue', sub { > my ( $self, $args ) = @_; >@@ -615,6 +643,7 @@ subtest 'suspend_hold() and resume() tests' => sub { > class => 'Koha::Holds', > value => { > biblionumber => $biblio->id, >+ found => undef, > } > } > ); >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index c449b30032..8be4d4525c 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -1243,12 +1243,18 @@ subtest 'store() tests' => sub { > ); > } ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > # new item > my $item = $builder->build_sample_item({ biblionumber => $biblio->id }); > > # updated item > $item->set({ reserves => 1 })->store; > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ # updated item >+ $item->set({ reserves => 0 })->store; >+ > $schema->storage->txn_rollback; > }; > }; >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index cfac978aeb..5bda45c4fa 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -961,6 +961,8 @@ subtest 'reserves.item_level_hold' => sub { > ); > } ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ > # Revert the waiting status > C4::Reserves::RevertWaitingStatus( > { itemnumber => $item->itemnumber } ); >@@ -969,6 +971,14 @@ subtest 'reserves.item_level_hold' => sub { > > is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should not be removed when the waiting status is revert' ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ $hold->set_waiting; >+ >+ # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test >+ C4::Reserves::RevertWaitingStatus( >+ { itemnumber => $item->itemnumber } ); >+ > $hold->delete; # cleanup > }; > >@@ -1428,6 +1438,18 @@ subtest 'AddReserve() tests' => sub { > ); > } ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ >+ AddReserve( >+ { >+ branchcode => $library->branchcode, >+ borrowernumber => $patron->id, >+ biblionumber => $biblio->id, >+ } >+ ); >+ >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ > AddReserve( > { > branchcode => $library->branchcode, >@@ -1483,6 +1505,7 @@ subtest 'AlterPriorty() tests' => sub { > ); > } ); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); > > AlterPriority( "bottom", $reserve_id, 1, 2, 1, 3 ); > >@@ -1490,5 +1513,9 @@ subtest 'AlterPriorty() tests' => sub { > > is($hold->priority,3,'Successfully altered priority to bottom'); > >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ AlterPriority( "bottom", $reserve_id, 1, 2, 1, 3 ); >+ > $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 30728
:
134823
|
134824
|
134825
|
134826
|
134827
|
134828
|
134829
|
134831
|
134832
|
134833
|
134834
|
134857
| 134858 |
134859
|
134860
|
134967