mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-18 17:31:35 +00:00
Deduplicate BOM entry price logic into ProjectBuildHelper
The private getBomEntryUnitPrice() in ProjectBomEntriesDataTable was identical to the one in ProjectBuildHelper. Replaced it with a new public getEntryUnitPrice() on ProjectBuildHelper (returns BigDecimal, never null) and delegate to it from the DataTable. This eliminates the duplicate code and brings the DataTable lines under the existing ProjectBuildHelper test coverage. Added three tests for getEntryUnitPrice() covering the no-pricing, non-part, and part cases.
This commit is contained in:
parent
5d669da932
commit
fa1e5549f0
3 changed files with 45 additions and 20 deletions
|
|
@ -264,6 +264,37 @@ final class ProjectBuildHelperTest extends WebTestCase
|
|||
$this->assertTrue(BigDecimal::of('11.00')->isEqualTo($result));
|
||||
}
|
||||
|
||||
public function testGetEntryUnitPriceReturnsZeroForNoPricingData(): void
|
||||
{
|
||||
$entry = new ProjectBOMEntry();
|
||||
$entry->setPart(new Part()); // part with no orderdetails
|
||||
$entry->setQuantity(5);
|
||||
|
||||
$result = $this->service->getEntryUnitPrice($entry);
|
||||
$this->assertTrue(BigDecimal::zero()->isEqualTo($result));
|
||||
}
|
||||
|
||||
public function testGetEntryUnitPriceNonPartEntry(): void
|
||||
{
|
||||
$entry = new ProjectBOMEntry();
|
||||
$entry->setName('Wire');
|
||||
$entry->setQuantity(2);
|
||||
$entry->setPrice(BigDecimal::of('1.25'));
|
||||
|
||||
$result = $this->service->getEntryUnitPrice($entry);
|
||||
$this->assertTrue(BigDecimal::of('1.25')->isEqualTo($result));
|
||||
}
|
||||
|
||||
public function testGetEntryUnitPriceWithPart(): void
|
||||
{
|
||||
$entry = new ProjectBOMEntry();
|
||||
$entry->setPart($this->makePartWithPrice(2.00));
|
||||
$entry->setQuantity(3);
|
||||
|
||||
$result = $this->service->getEntryUnitPrice($entry);
|
||||
$this->assertTrue(BigDecimal::of('2.00')->isEqualTo($result));
|
||||
}
|
||||
|
||||
public function testCalculateTotalBuildPriceRespectsMinOrderAmount(): void
|
||||
{
|
||||
$project = new Project();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue