From bdc2deba999e8a9b74d53108a66a9cc88732cf9f Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 11 Apr 2023 12:04:17 -0300 Subject: [PATCH] Bug 31795: (follow-up) Mock call to FindDuplicateAuthority When running against Zebra, this tests fail because it requires the record to be indexed timely. In theory, a 5 seconds delay should be enough for the indexer to pick up. But that's not the point of the test, and we should better just mock the query in this case. To test: 1. Have ktd launch with zebra: $ ktd up -d 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/authorities.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Launch ktd with ES: $ ktd down $ ktd --es7 up -d 6. Repeat 2 => SUCCESS: Tests pass! 7. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1/Authorities.pm | 2 +- t/db_dependent/api/v1/authorities.t | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Authorities.pm b/Koha/REST/V1/Authorities.pm index 8a6c24b2c1..b46be125b7 100644 --- a/Koha/REST/V1/Authorities.pm +++ b/Koha/REST/V1/Authorities.pm @@ -169,7 +169,7 @@ sub add { } unless ( $overrides->{any} || $overrides->{duplicate} ) { - my ( $duplicateauthid, $duplicateauthvalue ) = FindDuplicateAuthority( $record, $authtypecode ); + my ( $duplicateauthid, $duplicateauthvalue ) = C4::AuthoritiesMarc::FindDuplicateAuthority( $record, $authtypecode ); return $c->render( status => 409, diff --git a/t/db_dependent/api/v1/authorities.t b/t/db_dependent/api/v1/authorities.t index 3da737e9ad..8c8056323b 100755 --- a/t/db_dependent/api/v1/authorities.t +++ b/t/db_dependent/api/v1/authorities.t @@ -159,6 +159,9 @@ subtest 'post() tests' => sub { $schema->storage->txn_begin; + my $authorities_mock = Test::MockModule->new('C4::AuthoritiesMarc'); + $authorities_mock->mock( 'FindDuplicateAuthority', sub { return 1234; } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', -- 2.39.5