Enhance procurement lot estimated value aggregation and add unit tests
- Updated the `AggregateProcurementLotEstimatedValue` function to reject mixed currencies and allow empty lot currencies, ensuring accurate aggregation of estimated values. - Introduced new unit tests in `entity_test.go` to validate the behavior of the aggregation function under various scenarios, including mixed currencies and empty lot currencies. - Refactored budget calculation in `budget_test.go` to utilize the new aggregation logic, improving consistency in budget retrieval. This update improves the handling of estimated values in procurement lots, enhancing the reliability of the tender management system.
This commit is contained in:
@@ -15,6 +15,29 @@ func TestAggregateProcurementLotEstimatedValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateProcurementLotEstimatedValueRejectsMixedCurrencies(t *testing.T) {
|
||||
value, currency := AggregateProcurementLotEstimatedValue([]ProcurementLot{
|
||||
{EstimatedValue: 100000, Currency: "EUR"},
|
||||
{EstimatedValue: 250000, Currency: "USD"},
|
||||
})
|
||||
if value != 0 || currency != "" {
|
||||
t.Fatalf("expected no aggregation for mixed currencies, got value=%v currency=%q", value, currency)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateProcurementLotEstimatedValueAllowsEmptyLotCurrency(t *testing.T) {
|
||||
value, currency := AggregateProcurementLotEstimatedValue([]ProcurementLot{
|
||||
{EstimatedValue: 100000, Currency: "EUR"},
|
||||
{EstimatedValue: 250000},
|
||||
})
|
||||
if value != 350000 {
|
||||
t.Fatalf("expected total 350000, got %v", value)
|
||||
}
|
||||
if currency != "EUR" {
|
||||
t.Fatalf("expected currency EUR, got %q", currency)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvedEstimatedValueAndCurrencyUsesLotsWhenTopLevelMissing(t *testing.T) {
|
||||
tender := &Tender{
|
||||
Currency: "EUR",
|
||||
|
||||
Reference in New Issue
Block a user