4cfca5aa55
- Updated the `ResolvedEstimatedValueAndCurrency` method to aggregate procurement lot values when the tender-level estimated value is not set, improving accuracy in value retrieval. - Introduced the `AggregateProcurementLotEstimatedValue` function to sum estimated values from procurement lots and return the first found currency. - Modified the `ToResponseWithLanguage` method to utilize the new estimated value resolution logic. - Added unit tests for the new functionality, ensuring correct behavior for various scenarios in the `entity_test.go` and `budget_test.go` files. This update improves the handling of estimated values in tenders, enhancing the overall reliability of the tender management system.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package tender
|
|
|
|
import "testing"
|
|
|
|
func TestAggregateProcurementLotEstimatedValue(t *testing.T) {
|
|
value, currency := AggregateProcurementLotEstimatedValue([]ProcurementLot{
|
|
{EstimatedValue: 100000, Currency: "EUR"},
|
|
{EstimatedValue: 250000, Currency: "EUR"},
|
|
})
|
|
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",
|
|
ProcurementLots: []ProcurementLot{
|
|
{LotID: "LOT-0001", EstimatedValue: 500000, Currency: "EUR"},
|
|
},
|
|
}
|
|
|
|
value, currency := tender.ResolvedEstimatedValueAndCurrency()
|
|
if value != 500000 {
|
|
t.Fatalf("expected 500000, got %v", value)
|
|
}
|
|
if currency != "EUR" {
|
|
t.Fatalf("expected EUR, got %q", currency)
|
|
}
|
|
}
|
|
|
|
func TestResolvedEstimatedValueAndCurrencyPrefersTopLevel(t *testing.T) {
|
|
tender := &Tender{
|
|
EstimatedValue: 900000,
|
|
Currency: "USD",
|
|
ProcurementLots: []ProcurementLot{
|
|
{EstimatedValue: 100000, Currency: "EUR"},
|
|
},
|
|
}
|
|
|
|
value, currency := tender.ResolvedEstimatedValueAndCurrency()
|
|
if value != 900000 {
|
|
t.Fatalf("expected 900000, got %v", value)
|
|
}
|
|
if currency != "USD" {
|
|
t.Fatalf("expected USD, got %q", currency)
|
|
}
|
|
}
|