ff6bdfcb09
continuous-integration/drone/push Build is passing
- Implemented the IsRecommendable method in the Tender entity to determine if a tender should be included in AI recommendations based on its status and deadline. - Added unit tests for the IsRecommendable method to cover various scenarios, ensuring accurate recommendation logic. - Updated the Recommend method in the tender service to utilize the new IsRecommendable method for improved clarity and functionality. This update enhances the recommendation logic for tenders, ensuring only appropriate tenders are considered for AI recommendations based on their status and deadlines.
124 lines
3.2 KiB
Go
124 lines
3.2 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)
|
|
}
|
|
}
|
|
|
|
func TestTenderIsRecommendable(t *testing.T) {
|
|
now := int64(1_700_000_000)
|
|
|
|
tests := []struct {
|
|
name string
|
|
tender Tender
|
|
want bool
|
|
}{
|
|
{
|
|
name: "active with future deadline",
|
|
tender: Tender{Status: TenderStatusActive, TenderDeadline: now + 3600},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "active with past deadline",
|
|
tender: Tender{Status: TenderStatusActive, TenderDeadline: now - 3600},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "active with deadline at now",
|
|
tender: Tender{Status: TenderStatusActive, TenderDeadline: now},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "active without deadline",
|
|
tender: Tender{Status: TenderStatusActive, TenderDeadline: 0},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "expired status with future deadline",
|
|
tender: Tender{Status: TenderStatusExpired, TenderDeadline: now + 3600},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "awarded with future deadline",
|
|
tender: Tender{Status: TenderStatusAwarded, TenderDeadline: now + 3600},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := tt.tender.IsRecommendable(now); got != tt.want {
|
|
t.Fatalf("IsRecommendable() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|