@@ -, +, @@ --- Koha/SMTP/Server.pm | 18 ++++++++++++++++++ t/db_dependent/Koha/SMTP/Server.t | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) --- a/Koha/SMTP/Server.pm +++ a/Koha/SMTP/Server.pm @@ -99,6 +99,24 @@ sub is_system_default { return $self->{_is_system_default}; } +=head3 to_api + + my $json = $smtp_server->to_api; + +Overloaded method that returns a JSON representation of the Koha::SMTP::Server object, +suitable for API output. + +=cut + +sub to_api { + my ( $self, $params ) = @_; + + my $json = $self->SUPER::to_api( $params ); + delete $json->{password}; + + return $json; +} + =head3 to_api_mapping This method returns the mapping for representing a Koha::SMTP::Server object --- a/t/db_dependent/Koha/SMTP/Server.t +++ a/t/db_dependent/Koha/SMTP/Server.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use Test::Exception; use Test::Warn; @@ -70,3 +70,15 @@ subtest 'is_system_default() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'to_api() tests' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $smtp_server = $builder->build_object({ class => 'Koha::SMTP::Servers' }); + ok( !exists $smtp_server->to_api->{password}, 'Password is not part of the API representation' ); + + $schema->storage->txn_rollback; +}; --