Skip to content

Commit

Permalink
more tests for rate desc
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowles committed May 15, 2018
1 parent a2013f2 commit 1ef4a4e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
76 changes: 45 additions & 31 deletions hotelws/hotel_rate_desc_rq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestHotelRateDescMarshal(t *testing.T) {
//fmt.Printf("content marshal \n%s\n", b)
}

var ccards = []string{"DS", "CA", "MC", "CB", "VI", "VS", "AX", "JC", "DC"}

func TestRateDescCall(t *testing.T) {
// assume RPH is from previous hotel property description call
rpc := SetRateParams(
Expand All @@ -39,9 +41,9 @@ func TestRateDescCall(t *testing.T) {
},
},
)
rate, _ := SetHotelRateDescRqStruct(rpc)
raterq, _ := SetHotelRateDescRqStruct(rpc)

req := BuildHotelRateDescRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, rate)
req := BuildHotelRateDescRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, raterq)

resp, err := CallHotelRateDesc(serverHotelRateDesc.URL, req)
if err != nil {
Expand All @@ -53,7 +55,7 @@ func TestRateDescCall(t *testing.T) {
roomStayRates := resp.Body.HotelDesc.RoomStay.RoomRates
numRoomRates := len(roomStayRates)
if numRoomRates != 1 {
t.Errorf("Number of room rates is wrong, expect %d got %d", 1, numRoomRates)
t.Error("Number of room rates is wrong")
}

rr := roomStayRates[0]
Expand All @@ -63,6 +65,15 @@ func TestRateDescCall(t *testing.T) {
if rr.GuaranteeSurcharge != "G" {
t.Errorf("GuaranteeSurcharge expected %s, got %s", "G", rr.GuaranteeSurcharge)
}
if len(rr.AdditionalInfo.PaymentCard) != 9 {
t.Errorf("AdditionalInfo.PaymentCard count is wrong: %v", rr.AdditionalInfo.PaymentCard)
}
for idx, card := range rr.AdditionalInfo.PaymentCard {
if card.Code != ccards[idx] {
t.Errorf("AdditionalInfo.PaymentCard expect: %s, got: %s", ccards[idx], card.Code)
}
}

cnum := rr.AdditionalInfo.CancelPolicy.Numeric
copt := rr.AdditionalInfo.CancelPolicy.Option
if cnum != 2 {
Expand All @@ -72,34 +83,37 @@ func TestRateDescCall(t *testing.T) {
t.Errorf("RoomRate expected cancel policy option %s, got %s", "D", copt)
}

/*
indexRoomRate := numRoomRates - 1
numRates := len(roomStayRates[indexRoomRate].Rates)
if numRates != 1 {
t.Error("Number of rates is wrong")
}
for _, rate := range roomStayRates[indexRoomRate].Rates {
if rate.Amount != "400.00" {
t.Errorf("Rate expected %s, got %s", "400.00", rate.Amount)
}
if rate.CurrencyCode != "SGD" {
t.Errorf("CurrencyCode expected %s, got %s", "SGD", rate.CurrencyCode)
}
if rate.HRD_RequiredForSell != "false" {
t.Errorf("CurrencyCode expected %s, got %s", "false", rate.HRD_RequiredForSell)
}
numRates := len(roomStayRates[0].Rates)
if numRates != 1 {
t.Error("Number of rates is wrong")
}
rate := rr.Rates[0]
if rate.Amount != "274.55" {
t.Errorf("Rate expected %s, got %s", "274.55", rate.Amount)
}
if rate.CurrencyCode != "USD" {
t.Errorf("CurrencyCode expected %s, got %s", "USD", rate.CurrencyCode)
}
if rate.HRD_RequiredForSell != "false" {
t.Errorf("CurrencyCode expected %s, got %s", "false", rate.HRD_RequiredForSell)
}

hprice := rate.HotelPricing
if hprice.Amount != "470.80" {
t.Errorf("HotelPricing expected %s, got %s", "470.80", hprice.Amount)
}
if hprice.TotalSurcharges.Amount != "40.00" {
t.Errorf("TotalSurcharges expected %s, got %s", "40.00", hprice.TotalSurcharges.Amount)
}
if hprice.TotalTaxes.Amount != "30.80" {
t.Errorf("TotalTaxes expected %s, got %s", "30.80", hprice.TotalTaxes.Amount)
}
}
hprice := rate.HotelPricing
if hprice.Amount != "307.50" {
t.Errorf("HotelPricing expected empty %s, got %s", "307.50", hprice.Amount)
}
if hprice.TotalSurcharges.Amount != "" {
t.Errorf("TotalSurcharges expected %s, got %s", "", hprice.TotalSurcharges.Amount)
}
if hprice.TotalTaxes.Amount != "32.95" {
t.Errorf("TotalTaxes expected %s, got %s", "32.95", hprice.TotalTaxes.Amount)
}

if hprice.TotalTaxes.TaxFieldOne != "19.22" {
t.Errorf("TaxeFieldOnw expected %s, got %s", "19.22", hprice.TotalTaxes.TaxFieldOne)
}
if hprice.TotalTaxes.TaxFieldTwo != "13.73" {
t.Errorf("TaxFieldTwo expected %s, got %s", "13.73", hprice.TotalTaxes.TaxFieldTwo)
}

*/
}
10 changes: 8 additions & 2 deletions hotelws/struct_hotel_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ type TotalSurcharges struct {
Amount string `xml:"Amount,attr"`
}
type TotalTaxes struct {
XMLName xml.Name `xml:"TotalTaxes"`
Amount string `xml:"Amount,attr"`
XMLName xml.Name `xml:"TotalTaxes"`
Amount string `xml:"Amount,attr"`
TaxFieldOne string `xml:"TaxFieldOne"`
TaxFieldTwo string `xml:"TaxFieldTwo"`
Text []string `xml:"Text"`
}

type HotelPricing struct {
Expand Down Expand Up @@ -108,6 +111,9 @@ type AdditionalInfo struct {
DCAOther struct {
Text []string `xml:"Text"`
} `xml:"DCA_Other"`
PaymentCard []struct {
Code string `xml:"Code,attr"`
} `xml:"PaymentCard"`
Taxes string `xml:"Taxes"`
CancelPolicy struct {
Numeric int `xml:"Numeric,attr"` //string? 001 versus 1
Expand Down

0 comments on commit 1ef4a4e

Please sign in to comment.