Add unit tests for backfilling notice location from buyer
- Introduced `mapper_test.go` to validate the functionality of backfilling notice location details from the buyer organization. - Implemented two test cases: one to ensure the location fields are correctly populated from the buyer when they are empty, and another to verify that existing values are not overwritten. - Enhanced the `mapper.go` file by adding the `backfillNoticeLocationFromBuyer` function to facilitate this logic. This update improves the reliability of notice data handling within the tender management system by ensuring accurate location information is maintained.
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
|
||||
|
||||
Reference in New Issue
Block a user