Enhance tender estimated value resolution and add unit tests

- 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.
This commit is contained in:
Mazyar
2026-06-20 12:29:47 +03:30
parent 6fb57c41c1
commit 4cfca5aa55
7 changed files with 259 additions and 26 deletions
+51
View File
@@ -0,0 +1,51 @@
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)
}
}