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 <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d1e82657f4)
Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2025-12-15 10:32:38 +00:00 committed by Jacob O'Mara
parent a244d7a6a0
commit e8b4fa90eb
No known key found for this signature in database
1 changed files with 18 additions and 1 deletions

View File

@ -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 => {