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.
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package ted
|
|
|
|
import "testing"
|
|
|
|
func TestCurrencyTextAmountAndCurrency(t *testing.T) {
|
|
t.Run("chardata", func(t *testing.T) {
|
|
amount, currency := (CurrencyText{CurrencyID: "EUR", Text: "1 234,56"}).AmountAndCurrency()
|
|
if amount != "1 234,56" {
|
|
t.Fatalf("unexpected amount %q", amount)
|
|
}
|
|
if currency != "EUR" {
|
|
t.Fatalf("unexpected currency %q", currency)
|
|
}
|
|
})
|
|
|
|
t.Run("value child", func(t *testing.T) {
|
|
amount, currency := (CurrencyText{CurrencyID: "EUR", Value: "500000"}).AmountAndCurrency()
|
|
if amount != "500000" {
|
|
t.Fatalf("unexpected amount %q", amount)
|
|
}
|
|
if currency != "EUR" {
|
|
t.Fatalf("unexpected currency %q", currency)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestContractNoticeGetBudgetSumsAllLots(t *testing.T) {
|
|
cn := ContractNotice{
|
|
ProcurementProjectLots: []ProcurementProjectLot{
|
|
{
|
|
ProcurementProject: &ProcurementProject{
|
|
RequestedTenderTotal: &RequestedTenderTotal{
|
|
EstimatedOverallContractAmount: CurrencyText{CurrencyID: "EUR", Text: "100000"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ProcurementProject: &ProcurementProject{
|
|
RequestedTenderTotal: &RequestedTenderTotal{
|
|
EstimatedOverallContractAmount: CurrencyText{CurrencyID: "EUR", Text: "250000"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
amount, currency := cn.GetBudget()
|
|
value, ok := ParseEuropeanAmount(amount)
|
|
if !ok {
|
|
t.Fatalf("failed to parse budget amount %q", amount)
|
|
}
|
|
if value != 350000 {
|
|
t.Fatalf("expected 350000, got %v", value)
|
|
}
|
|
if currency != "EUR" {
|
|
t.Fatalf("expected EUR, got %q", currency)
|
|
}
|
|
}
|
|
|
|
func TestContractNoticeGetBudgetRejectsMixedCurrencies(t *testing.T) {
|
|
cn := ContractNotice{
|
|
ProcurementProjectLots: []ProcurementProjectLot{
|
|
{
|
|
ProcurementProject: &ProcurementProject{
|
|
RequestedTenderTotal: &RequestedTenderTotal{
|
|
EstimatedOverallContractAmount: CurrencyText{CurrencyID: "EUR", Text: "100000"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
ProcurementProject: &ProcurementProject{
|
|
RequestedTenderTotal: &RequestedTenderTotal{
|
|
EstimatedOverallContractAmount: CurrencyText{CurrencyID: "USD", Text: "250000"},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
amount, currency := cn.GetBudget()
|
|
if amount != "" || currency != "" {
|
|
t.Fatalf("expected no budget for mixed currencies, got amount=%q currency=%q", amount, currency)
|
|
}
|
|
}
|