ee5414bc10
- 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.
75 lines
2.1 KiB
Go
75 lines
2.1 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 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",
|
|
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)
|
|
}
|
|
}
|