From: G. Richardson Date: Sat, 12 Nov 2016 13:19:41 +0000 (+0100) Subject: Assortment und Assembly Tests nutzen SL::Dev::Part X-Git-Tag: release-3.5.4~1871 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=35777fef0fc261135acbd4f5457aeadb098b48d3;p=kivitendo-erp.git Assortment und Assembly Tests nutzen SL::Dev::Part --- diff --git a/t/part/assembly.t b/t/part/assembly.t index 314d1ccbd..ad2a5050d 100644 --- a/t/part/assembly.t +++ b/t/part/assembly.t @@ -7,25 +7,26 @@ use Test::Exception; use SL::DB::Unit; use SL::DB::Part; use SL::DB::Assembly; +use SL::Dev::Part; Support::TestSetup::login(); clear_up(); reset_state(); -is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3"); +is( SL::DB::Manager::Part->get_all_count(), 4, "total number of parts created is 4"); -my $assembly_part = SL::DB::Manager::Part->find_by( partnumber => 'as1' ); -my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => '19000' ); +my $assembly_part = SL::DB::Manager::Part->find_by( partnumber => '19000' ) || die "Can't find part 19000"; +my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => 'ap1' ); is($assembly_part->part_type, 'assembly', 'assembly has correct type'); -is( scalar @{$assembly_part->assemblies}, 2, 'assembly consists of two parts' ); +is( scalar @{$assembly_part->assemblies}, 3, 'assembly consists of two parts' ); # fetch assembly item corresponding to partnumber 19000 my $assembly_items = $assembly_part->find_assemblies( { parts_id => $assembly_item_part->id } ) || die "can't find assembly_item"; my $assembly_item = $assembly_items->[0]; -is($assembly_item->part->partnumber, '19000', 'assembly part part relation works'); -is($assembly_item->assembly_part->partnumber, 'as1', 'assembly part assembly part relation works'); +is($assembly_item->part->partnumber, 'ap1', 'assembly part part relation works'); +is($assembly_item->assembly_part->partnumber, '19000', 'assembly part assembly part relation works'); clear_up(); done_testing; @@ -38,26 +39,7 @@ sub clear_up { sub reset_state { my %params = @_; - # create an assembly that consists of two parts - my ($part1, $part2, $unit, $assembly_part, $assembly_1, $assembly_2); - $unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; - - $part1 = SL::DB::Part->new_part(partnumber => '19000', - unit => $unit->name, - part_type => 'part', - )->save; - $part2 = $part1->clone_and_reset($part1); - $part2->partnumber($part1->partnumber + 1); - $part2->save; - - $assembly_part = SL::DB::Part->new_assembly(partnumber => 'as1', - description => 'assembly', - unit => $unit->name, - ); - $assembly_1 = SL::DB::Assembly->new(parts_id => $part1->id, qty => 3, bom => 1); - $assembly_2 = SL::DB::Assembly->new(parts_id => $part2->id, qty => 3, bom => 1); - $assembly_part->add_assemblies($assembly_1, $assembly_2); - $assembly_part->save; + my $assembly = SL::Dev::Part::create_assembly( partnumber => '19000' )->save; }; 1; diff --git a/t/part/assortment.t b/t/part/assortment.t index 540d0f716..e67afe82a 100644 --- a/t/part/assortment.t +++ b/t/part/assortment.t @@ -5,60 +5,33 @@ use lib 't'; use Support::TestSetup; use Carp; use Test::Exception; -use SL::DB::Unit; use SL::DB::Part; -use Data::Dumper; +use SL::Dev::Part; Support::TestSetup::login(); clear_up(); -reset_state(); -is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3"); +my $assortment = SL::Dev::Part::create_assortment( partnumber => 'aso1', + description => "Assortment 1", + number_of_parts => 10, + )->save; -my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'as1' ); +is( SL::DB::Manager::Part->get_all_count(), 11, "total number of parts created is 11"); + +my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'aso1' ) or die "Can't find assortment with partnumber aso1"; is($assortment->part_type, 'assortment', 'assortment has correct part_type'); -is(scalar @{$assortment->assortment_items}, 2, 'assortment has two parts'); -is($assortment->items_sellprice_sum, 19.98, 'assortment sellprice sum ok'); -is($assortment->items_lastcost_sum, 13.32, 'assortment lastcost sum ok'); +is(scalar @{$assortment->assortment_items}, 10, 'assortment has 10 parts'); +is($assortment->items_sellprice_sum, 100, 'assortment sellprice sum ok'); +is($assortment->items_lastcost_sum, 50, 'assortment lastcost sum ok'); my $assortment_item = $assortment->assortment_items->[0]; -is( $assortment_item->assortment->partnumber, 'as1', "assortment_item links back to correct assortment"); +is( $assortment_item->assortment->partnumber, 'aso1', "assortment_item links back to correct assortment"); clear_up(); done_testing; -sub reset_state { - my %params = @_; - - # SL::DB::Manager::AssortmentItem->delete_all(all => 1); - # SL::DB::Manager::Part->delete_all(all => 1); - my ($part1, $part2, $unit, $assortment_part, $assortment_1, $assortment_2); - - $unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; - $part1 = SL::DB::Part->new_part( partnumber => '7777', - description => "assortment part 1", - unit => $unit->name, - sellprice => '3.33', - lastcost => '2.22', - )->save; - $part2 = $part1->clone_and_reset($part1); - $part2->partnumber( $part1->partnumber + 1 ); - $part2->description( "assortment part 2" ); - $part2->save; - - $assortment_part = SL::DB::Part->new_assortment( partnumber => 'as1', - description => 'assortment', - sellprice => '0', - unit => $unit->name); - $assortment_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); - $assortment_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); - $assortment_part->add_assortment_items($assortment_1, $assortment_2); - $assortment_part->save or die "Couldn't save assortment"; - -}; - sub clear_up { SL::DB::Manager::AssortmentItem->delete_all(all => 1); SL::DB::Manager::Part->delete_all( all => 1);