diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index aff93e092b..15a95045e4 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -581,7 +581,7 @@ subtest 'add() tests' => sub { subtest 'extended_attributes handling tests' => sub { - plan tests => 25; + plan tests => 29; $mocked_patron->mock( 'extended_attributes', @@ -617,6 +617,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 => {