From c6e5467e5f1cb58bed76b18bc38675a82aad11c9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 22 Nov 2022 18:23:07 -0300 Subject: [PATCH] Bug 31378: Tests shouldn't remove all patrons Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/REST/Plugin/Auth/IdP.t | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t b/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t index 006415f07f..d3579cf9c1 100755 --- a/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t +++ b/t/db_dependent/Koha/REST/Plugin/Auth/IdP.t @@ -86,19 +86,33 @@ subtest 'auth.register helper' => sub { $schema->storage->txn_begin; - # Remove existing patrons - Koha::Patrons->delete; - my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); + # generate a random patron + my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' }); + my $userid = $patron_to_delete->userid; + # delete patron + $patron_to_delete->delete; + + my $provider = $builder->build_object( { class => 'Koha::Auth::Identity::Providers', value => { matchpoint => 'email' } } ); + my $domain_with_register = $builder->build_object( - { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => 'domain1.com', auto_register => 1 } } ); + { class => 'Koha::Auth::Identity::Provider::Domains', + value => { identity_provider_id => $provider->id, domain => 'domain1.com', auto_register => 1 } + } + ); + my $domain_without_register = $builder->build_object( - { class => 'Koha::Auth::Identity::Provider::Domains', value => { identity_provider_id => $provider->id, domain => 'domain2.com', auto_register => 0 } } ); + { class => 'Koha::Auth::Identity::Provider::Domains', + value => { identity_provider_id => $provider->id, domain => 'domain2.com', auto_register => 0 } + } + ); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); + my $user_data = { firstname => 'test', surname => 'test', - userid => 'id1', + userid => $userid, branchcode => $library->branchcode, categorycode => $category->categorycode }; @@ -110,6 +124,7 @@ subtest 'auth.register helper' => sub { $t->post_ok( '/register_user' => json => { data => $user_data, domain_id => $domain_without_register->identity_provider_domain_id, interface => 'opac' } )->status_is(401) ->json_has( '/message', 'unauthorized' ); + $schema->storage->txn_rollback; }; @@ -118,8 +133,6 @@ subtest 'auth.session helper' => sub { $schema->storage->txn_begin; - # Remove existing patrons - Koha::Patrons->delete; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $t = Test::Mojo->new; -- 2.39.5