From 0b68d45da337a155d69fe2417a3c27a1689c5642 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Tue, 12 Oct 2021 14:40:09 +0200 Subject: [PATCH] =?utf8?q?CSV-Import=20Inventory=20mehr=20Testf=C3=A4lle?= =?utf8?q?=20(target=5Fqty=20und=20Kommentare)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- t/controllers/csvimport/inventory.t | 137 +++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 13 deletions(-) diff --git a/t/controllers/csvimport/inventory.t b/t/controllers/csvimport/inventory.t index 29b28766b..952210de1 100644 --- a/t/controllers/csvimport/inventory.t +++ b/t/controllers/csvimport/inventory.t @@ -29,8 +29,6 @@ sub reset_state { clear_up(); create_standard_stock(); - - } reset_state(); @@ -129,21 +127,23 @@ set_stock( is(SL::Helper::Inventory::get_stock(part => $part1), "25.00000", 'simple get_stock works'); is(SL::Helper::Inventory::get_onhand(part => $part1), "25.00000", 'simple get_onhand works'); +my ($trans_id, $inv_obj, $tt); +# add some stuff + $file = \<[0]; -diag Dumper($entry->{object}->trans_id); is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred"; is $entry->{object}->qty, "3.4", "Valid qty accepted"; # evals to text is(SL::Helper::Inventory::get_stock(part => $part1), "28.40000", 'simple add (stock) qty works'); is(SL::Helper::Inventory::get_onhand(part => $part1), "28.40000", 'simple add (onhand) qty works'); # now check the real Inventory entry -my $trans_id = $entry->{object}->trans_id; -my $inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); +$trans_id = $entry->{object}->trans_id; +$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); # we expect one entry for one trans_id is ref $inv_obj, "SL::DB::Inventory", "One inventory object, no array or undef"; @@ -153,12 +153,130 @@ is $inv_obj->employee_id, 1, "Employee valid"; # evals to is ref $inv_obj->shippingdate, 'DateTime', "Valid DateTime for shippingdate"; is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set"; -my $tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id); +$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id); is ref $tt, 'SL::DB::TransferType', "Valid TransferType, no undef"; is $tt->direction, 'in', "Transfer direction correct"; is $tt->description, 'correction', "Transfer description correct"; +# remove some stuff + +$file = \<[0]; +is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred"; +is $entry->{object}->qty, "-13.4", "Valid qty accepted"; # evals to text +is(SL::Helper::Inventory::get_stock(part => $part1), "15.00000", 'simple add (stock) qty works'); +is(SL::Helper::Inventory::get_onhand(part => $part1), "15.00000", 'simple add (onhand) qty works'); + +# now check the real Inventory entry +$trans_id = $entry->{object}->trans_id; +$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); + +# we expect one entry for one trans_id +is ref $inv_obj, "SL::DB::Inventory", "One inventory object, no array or undef"; +is $inv_obj->qty == -13.4, 1, "Valid qty accepted"; # evals to text +is $inv_obj->comment, 'Lager Inventur Standard', "Valid comment accepted"; # evals to text +is $inv_obj->employee_id, 1, "Employee valid"; # evals to text +is ref $inv_obj->shippingdate, 'DateTime', "Valid DateTime for shippingdate"; +is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set"; + +$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id); + +is ref $tt, 'SL::DB::TransferType', "Valid TransferType, no undef"; +is $tt->direction, 'out', "Transfer direction correct"; +is $tt->description, 'correction', "Transfer description correct"; + +# repeat both test cases but with target qty instead of qty (should throw an error for neg. case) +# and customise comment +# add some stuff + +$file = \<[0]; +is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred"; +is $entry->{object}->qty, "-11.6", "Valid qty accepted"; # evals to text qty = target_qty - actual_qty +is(SL::Helper::Inventory::get_stock(part => $part1), "3.40000", 'simple add (stock) qty works'); +is(SL::Helper::Inventory::get_onhand(part => $part1), "3.40000", 'simple add (onhand) qty works'); + +# now check the real Inventory entry +$trans_id = $entry->{object}->trans_id; +$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); + +# we expect one entry for one trans_id +is ref $inv_obj, "SL::DB::Inventory", "One inventory object, no array or undef"; +is $inv_obj->qty == -11.6, 1, "Valid qty accepted"; +is $inv_obj->comment, + "Alter, wir haben uns voll verhauen bei der aktuellen Zielmenge!", "Valid comment accepted"; +is $inv_obj->employee_id, 1, "Employee valid"; +is ref $inv_obj->shippingdate, 'DateTime', "Valid DateTime for shippingdate"; +is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set"; + +$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id); + +is ref $tt, 'SL::DB::TransferType', "Valid TransferType, no undef"; +is $tt->direction, 'out', "Transfer direction correct"; +is $tt->description, 'correction', "Transfer description correct"; + +# remove some stuff, but too much + +$file = \<[0]; +is scalar @{ $entry->{errors} }, 1, "One error for invalid data occurred"; +is $entry->{object}->qty, undef, "No data accepted"; # evals to text +is(SL::Helper::Inventory::get_stock(part => $part1), "3.40000", 'simple add (stock) qty works'); +is(SL::Helper::Inventory::get_onhand(part => $part1), "3.40000", 'simple add (onhand) qty works'); + +# now check the real Inventory entry +$trans_id = $entry->{object}->trans_id; +$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); + +is ref $trans_id, '', "No trans_id -> undef"; +is ref $inv_obj, '', "No inventory object -> undef"; + +# add some stuff, but realistic value + +$file = \<[0]; +is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred"; +is $entry->{object}->qty, "30.35", "Valid qty accepted"; # evals to text qty = target_qty - actual_qty +is(SL::Helper::Inventory::get_stock(part => $part1), "33.75000", 'simple add (stock) qty works'); +is(SL::Helper::Inventory::get_onhand(part => $part1), "33.75000", 'simple add (onhand) qty works'); + +# now check the real Inventory entry +$trans_id = $entry->{object}->trans_id; +$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id); + +# we expect one entry for one trans_id +is ref $inv_obj, "SL::DB::Inventory", "One inventory object, no array or undef"; +is $inv_obj->qty == 30.35, 1, "Valid qty accepted"; +is $inv_obj->comment, + "Jetzt wirklich", "Valid comment accepted"; +is $inv_obj->employee_id, 1, "Employee valid"; +is ref $inv_obj->shippingdate, 'DateTime', "Valid DateTime for shippingdate"; +is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set"; + +$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id); + +is ref $tt, 'SL::DB::TransferType', "Valid TransferType, no undef"; +is $tt->direction, 'in', "Transfer direction correct"; +is $tt->description, 'correction', "Transfer description correct"; + + clear_up(); # remove all data at end of tests # end of tests @@ -210,10 +328,3 @@ sub create_standard_stock { 1; - -##### -# vim: ft=perl -# set emacs to perl mode -# Local Variables: -# mode: perl -# End: -- 2.20.1