From d0099a888307931f278964bf61d13d356829f4c1 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Mon, 21 Feb 2022 16:21:48 +0000
Subject: [PATCH] Bug 30130: Unit tests

This patch adds a unit test for the internal 'beginning_of_message'
method in Koha::Edifact::Order to check that the vendor standard
parameter is being interpreted coorectly.

Test plan
1. Run the tests, they should pass

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 t/db_dependent/Koha/Edifact/Order.t | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Koha/Edifact/Order.t b/t/db_dependent/Koha/Edifact/Order.t
index 32a07db8ba..f624907a52 100755
--- a/t/db_dependent/Koha/Edifact/Order.t
+++ b/t/db_dependent/Koha/Edifact/Order.t
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 use Koha::Edifact::Order;
 
@@ -29,6 +29,32 @@ my $schema = Koha::Database->new->schema;
 
 my $builder = t::lib::TestBuilder->new;
 
+subtest 'beggining_of_message tests' => sub {
+    plan tests => 2;
+
+    $schema->storage->txn_begin;
+
+    my $basketno = sprintf '%011d', '123456';
+    my $edi_vendor = $builder->build(
+        {
+            source => 'VendorEdiAccount',
+            value  => {
+                standard => 'EUR',
+            }
+        }
+    );
+    my $dbic_edi_vendor = $schema->resultset('VendorEdiAccount')->find($edi_vendor->{id});
+
+    my $bgm = Koha::Edifact::Order::beginning_of_message($basketno, $dbic_edi_vendor, 1);
+    is( $bgm, qq{BGM+220+$basketno+9'}, "When vendor is set to EDItEUR standard we use 220 in BGM segment");
+
+    $dbic_edi_vendor->update({ standard => 'BIC'});
+    $bgm = Koha::Edifact::Order::beginning_of_message($basketno, $dbic_edi_vendor, 1);
+    is( $bgm, qq{BGM+220+$basketno+9'}, "When vendor is set to BiC standard we use 22V in BGM segment");
+
+    $schema->storage->txn_rollback;
+};
+
 subtest 'order_line() tests' => sub {
     # TODO: Split up order_line() to smaller methods in order
     #       to allow better testing
-- 
2.30.2