From 4fa543c6ab60e23546adff46afa266c1a1944d5e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 25 Feb 2022 20:04:14 +0000 Subject: [PATCH] Bug 22993: Unit tests Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi Signed-off-by: Fridolin Somers (cherry picked from commit c5577fa6ba3c7a29acbe83cde82b3195ef32ef86) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit bb9cf28aa201fa26d81cb7843da691c21551f86f) Signed-off-by: Victor Grousset/tuxayo --- t/db_dependent/api/v1/patrons.t | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 8b68cab6e0..11c929d683 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -26,6 +26,7 @@ use t::lib::Mocks; use t::lib::Dates; use C4::Auth; +use C4::Members::Messaging; use Koha::Database; use Koha::Old::Patrons; use Koha::Patron::Debarments qw/AddDebarment/; @@ -129,7 +130,7 @@ subtest 'add() tests' => sub { $schema->storage->txn_rollback; subtest 'librarian access tests' => sub { - plan tests => 21; + plan tests => 22; $schema->storage->txn_begin; @@ -212,6 +213,43 @@ subtest 'add() tests' => sub { ->json_like( '/conflict' => qr/(borrowers\.)?cardnumber/ ); } qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(borrowers\.)?cardnumber'/; + subtest 'default patron messaging preferences handling' => sub { + + plan tests => 3; + + t::lib::Mocks::mock_preference( 'EnhancedMessagingPreferences', 1 ); + + C4::Members::Messaging::SetMessagingPreference({ + categorycode => 'ST', + message_attribute_id => 1, + message_transport_types => ['email'], + wants_digest => 1 + }); + + my $patron_id = $t->post_ok( + "//$userid:$password@/api/v1/patrons" => json => { + "firstname" => "Nick", + "surname" => "Clemens", + "address" => "Somewhere", + "category_id" => "ST", + "city" => "Smallville", + "library_id" => "MPL", + } + )->status_is(201, 'Patron added')->tx->res->json->{patron_id}; + + my $messaging_preferences = C4::Members::Messaging::GetMessagingPreferences({ borrowernumber => $patron_id, message_name => 'Item_Due' }); + + is_deeply( + $messaging_preferences, + { + letter_code => 'DUEDGST', + wants_digest => 1, + transports => { email => 'DUEDGST' } + } , + 'Default messaging preferences set correctly' + ); + }; + $schema->storage->txn_rollback; }; }; -- 2.39.5