From 63fe38c244824323de740b8ef38726781a6d8e6e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 15 Dec 2025 10:32:38 +0000 Subject: [PATCH] Bug 40219: Add unit test to verify welcome email is not sent on validation failure This test ensures that when extended attribute validation fails during patron creation via the API, no welcome email is sent. This validates the fix where extended_attributes() validation was moved before the welcome email is enqueued. Test plan: 1. Apply this patch 2. Run: prove t/db_dependent/api/v1/patrons.t 3. Verify all tests pass, including the new test that confirms no welcome email is sent when extended attribute validation fails Signed-off-by: Martin Renvoize --- t/db_dependent/api/v1/patrons.t | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 82e579af404..6673030c371 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -586,7 +586,7 @@ subtest 'add() tests' => sub { subtest 'extended_attributes handling tests' => sub { - plan tests => 25; + plan tests => 29; $mocked_patron->mock( 'extended_attributes', @@ -622,6 +622,23 @@ subtest 'add() tests' => sub { is( Koha::Patrons->search->count, $patrons_count, 'No patron added' ); + # Bug 40219: Test that welcome email is not sent when extended attribute validation fails + t::lib::Mocks::mock_preference( 'AutoEmailNewUser', 1 ); + $letter_enqueued = 0; + $extended_attrs_exception = 'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute'; + $t->post_ok( + "//$userid:$password\@/api/v1/patrons" => json => { + "firstname" => "Bug", + "surname" => "FortyZeroTwoOneNine", + "address" => "Somewhere", + "category_id" => "ST", + "city" => "TestCity", + "library_id" => "MPL", + "email" => 'bug40219@test.com' + } + )->status_is(400)->json_is( '/error' => "Missing mandatory extended attribute (type=$type)" ); + is( $letter_enqueued, 0, 'Bug 40219: No welcome email sent when extended attribute validation fails' ); + $extended_attrs_exception = 'Koha::Exceptions::Patron::Attribute::InvalidType'; $t->post_ok( "//$userid:$password@/api/v1/patrons" => json => { -- 2.52.0