Merge pull request 'Add unit tests for backfilling notice location from buyer' (#53) from TM-485 into develop
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Reviewed-on: https://repo.ravanertebat.com/TM/tm_back/pulls/53 Reviewed-by: Hadi Barzegar <barzagarhadi@gmail.com>
This commit is contained in:
@@ -226,6 +226,7 @@ func (s *TEDScraper) mapPriorInformationNoticeToTender(pin *PriorInformationNoti
|
||||
t.BuyerOrganization = s.mapOrganization(buyerOrg, "buyer")
|
||||
}
|
||||
}
|
||||
backfillNoticeLocationFromBuyer(t)
|
||||
|
||||
reviewID := pin.GetReviewOrganizationID()
|
||||
if reviewID != "" {
|
||||
@@ -407,6 +408,7 @@ func (s *TEDScraper) mapToTender(cn *ContractNotice, sourceFileURL, sourceFileNa
|
||||
t.BuyerOrganization = s.mapOrganization(buyerOrg, "buyer")
|
||||
}
|
||||
}
|
||||
backfillNoticeLocationFromBuyer(t)
|
||||
|
||||
// Set review organization
|
||||
reviewID := cn.GetReviewOrganizationID()
|
||||
@@ -570,6 +572,7 @@ func (s *TEDScraper) mapContractAwardNoticeToTender(can *ContractAwardNotice, so
|
||||
t.BuyerOrganization = s.mapOrganization(buyerOrg, "buyer")
|
||||
}
|
||||
}
|
||||
backfillNoticeLocationFromBuyer(t)
|
||||
|
||||
// Set all organizations
|
||||
if orgs := can.GetOrganizations(); orgs != nil {
|
||||
@@ -667,6 +670,25 @@ func (s *TEDScraper) mapOrganization(tedOrg *Organization, role string) *notice.
|
||||
return org
|
||||
}
|
||||
|
||||
func backfillNoticeLocationFromBuyer(t *notice.Notice) {
|
||||
if t == nil || t.BuyerOrganization == nil {
|
||||
return
|
||||
}
|
||||
buyer := t.BuyerOrganization.Address
|
||||
if strings.TrimSpace(t.CountryCode) == "" && strings.TrimSpace(buyer.CountryCode) != "" {
|
||||
t.CountryCode = strings.TrimSpace(buyer.CountryCode)
|
||||
}
|
||||
if strings.TrimSpace(t.CityName) == "" && strings.TrimSpace(buyer.CityName) != "" {
|
||||
t.CityName = strings.TrimSpace(buyer.CityName)
|
||||
}
|
||||
if strings.TrimSpace(t.PostalCode) == "" && strings.TrimSpace(buyer.PostalZone) != "" {
|
||||
t.PostalCode = strings.TrimSpace(buyer.PostalZone)
|
||||
}
|
||||
if strings.TrimSpace(t.RegionCode) == "" && strings.TrimSpace(buyer.CountrySubentityCode) != "" {
|
||||
t.RegionCode = strings.TrimSpace(buyer.CountrySubentityCode)
|
||||
}
|
||||
}
|
||||
|
||||
func backfillNoticeEstimatedValueFromLots(t *notice.Notice) {
|
||||
if t == nil || t.EstimatedValue > 0 {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package ted
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"tm/internal/notice"
|
||||
)
|
||||
|
||||
func TestBackfillNoticeLocationFromBuyer(t *testing.T) {
|
||||
n := ¬ice.Notice{
|
||||
BuyerOrganization: ¬ice.Organization{
|
||||
Address: notice.Address{
|
||||
CountryCode: "POL",
|
||||
CityName: "Warsaw",
|
||||
PostalZone: "00-001",
|
||||
CountrySubentityCode: "PL14",
|
||||
},
|
||||
},
|
||||
}
|
||||
backfillNoticeLocationFromBuyer(n)
|
||||
|
||||
if n.CountryCode != "POL" {
|
||||
t.Fatalf("expected country POL, got %q", n.CountryCode)
|
||||
}
|
||||
if n.CityName != "Warsaw" {
|
||||
t.Fatalf("expected city Warsaw, got %q", n.CityName)
|
||||
}
|
||||
if n.PostalCode != "00-001" {
|
||||
t.Fatalf("expected postal 00-001, got %q", n.PostalCode)
|
||||
}
|
||||
if n.RegionCode != "PL14" {
|
||||
t.Fatalf("expected region PL14, got %q", n.RegionCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackfillNoticeLocationFromBuyerDoesNotOverwrite(t *testing.T) {
|
||||
n := ¬ice.Notice{
|
||||
CountryCode: "DEU",
|
||||
CityName: "Berlin",
|
||||
PostalCode: "10115",
|
||||
RegionCode: "DE300",
|
||||
BuyerOrganization: ¬ice.Organization{
|
||||
Address: notice.Address{
|
||||
CountryCode: "POL",
|
||||
CityName: "Warsaw",
|
||||
PostalZone: "00-001",
|
||||
CountrySubentityCode: "PL14",
|
||||
},
|
||||
},
|
||||
}
|
||||
backfillNoticeLocationFromBuyer(n)
|
||||
|
||||
if n.CountryCode != "DEU" {
|
||||
t.Fatalf("expected country DEU, got %q", n.CountryCode)
|
||||
}
|
||||
if n.CityName != "Berlin" {
|
||||
t.Fatalf("expected city Berlin, got %q", n.CityName)
|
||||
}
|
||||
if n.PostalCode != "10115" {
|
||||
t.Fatalf("expected postal 10115, got %q", n.PostalCode)
|
||||
}
|
||||
if n.RegionCode != "DE300" {
|
||||
t.Fatalf("expected region DE300, got %q", n.RegionCode)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user