From 868e901c8eabd9017bfe1b030791bed1ee23e148 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Mon, 21 Jun 2021 16:20:22 +0100
Subject: [PATCH] Bug 22435: (QA follow-up) Add missing test for manager
 relation

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 t/db_dependent/Koha/Account/Line.t | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t
index ce1e8fea4f..ee82a21038 100755
--- a/t/db_dependent/Koha/Account/Line.t
+++ b/t/db_dependent/Koha/Account/Line.t
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 14;
+use Test::More tests => 15;
 use Test::Exception;
 use Test::MockModule;
 
@@ -66,6 +66,34 @@ subtest 'patron() tests' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest 'manager() tests' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $library = $builder->build( { source => 'Branch' } );
+    my $manager = $builder->build( { source => 'Borrower' } );
+
+    my $line = Koha::Account::Line->new(
+    {
+        manager_id      => $manager->{borrowernumber},
+        debit_type_code => "OVERDUE",
+        status          => "RETURNED",
+        amount          => 10,
+        interface       => 'commandline',
+    })->store;
+
+    my $account_line_manager = $line->manager;
+    is( ref( $account_line_manager ), 'Koha::Patron', 'Koha::Account::Line->manager should return a Koha::Patron' );
+    is( $line->manager_id, $account_line_manager->borrowernumber, 'Koha::Account::Line->manager should return the correct staff' );
+
+    $line->manager_id(undef)->store;
+    is( $line->manager, undef, 'Koha::Account::Line->manager should return undef if no staff linked' );
+
+    $schema->storage->txn_rollback;
+};
+
 subtest 'item() tests' => sub {
 
     plan tests => 3;
-- 
2.20.1