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 16, 2018
1 parent 1ef4a4e commit 7f69725
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 571 deletions.
4 changes: 2 additions & 2 deletions hotelws/hotel_rate_desc_rq.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func SetHotelRateDescRqStruct(rpc *RatePlanCandidates) (HotelRateDescBody, error
}, nil
}

// BuildHotelRateDescRequest to make hotel property description request, done after hotel property description IF hrd required for sell is true.
// BuildHotelRateDescRequest to make hotel property description request, done after hotel property description iff HRD_RequiredForSell=true.
func BuildHotelRateDescRequest(from, pcc, binsectoken, convid, mid, time string, propDesc HotelRateDescBody) HotelRateDescRequest {
return HotelRateDescRequest{
Envelope: srvc.CreateEnvelope(),
Expand Down Expand Up @@ -106,7 +106,7 @@ type HotelRateDescResponse struct {
ErrorSabreXML ErrorSabreXML
}

// CallHotelRateDesc to sabre web services retrieve hotel rates using HotelRateDescriptionLLSRQ.
// CallHotelRateDesc to sabre web services retrieve hotel rates using HotelRateDescriptionLLSRQ. This call only supports requests that contain an RPH from a previous hotel_property_desc call, see BuildHotelRateDescRequest.
func CallHotelRateDesc(serviceURL string, req HotelRateDescRequest) (HotelRateDescResponse, error) {
propResp := HotelRateDescResponse{}
byteReq, _ := xml.Marshal(req)
Expand Down
34 changes: 28 additions & 6 deletions hotelws/hotel_rate_desc_rq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ 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"}
var additionalCards = []string{"DS", "CA", "MC", "CB", "VI", "VS", "AX", "JC", "DC"}
var guaranteeCards = []struct {
code string
name string
}{
{"AX", "AMERICAN EXPRESS"},
{"CA", "MASTERCARD"},
{"CB", "CARTE BLANCHE"},
{"DC", "DINERS CLUB CARD"},
{"DS", "DISCOVER CARD"},
{"JC", "JCB CREDIT CARD"},
{"VI", "VISA"},
}

func TestRateDescCall(t *testing.T) {
// assume RPH is from previous hotel property description call
Expand All @@ -52,6 +64,16 @@ func TestRateDescCall(t *testing.T) {
if resp.Body.Fault.String != "" {
t.Errorf("Body.Fault.String expect empty: '%s', got: %s", "", resp.Body.Fault.String)
}

for i, cg := range resp.Body.HotelDesc.RoomStay.Guarantee.DepositsAccepted.PaymentCards {
if cg.Code != guaranteeCards[i].code {
t.Errorf("Guarantee.DepositsAccepted.PaymentCards[%d].Code expect: %s, got: %s", i, guaranteeCards[i].code, cg.Code)
}
if cg.Type != guaranteeCards[i].name {
t.Errorf("Guarantee.DepositsAccepted.PaymentCards[%d].Type expect: %s, got: %s", i, guaranteeCards[i].name, cg.Type)
}
}

roomStayRates := resp.Body.HotelDesc.RoomStay.RoomRates
numRoomRates := len(roomStayRates)
if numRoomRates != 1 {
Expand All @@ -65,12 +87,12 @@ 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)
if len(rr.AdditionalInfo.PaymentCards) != 9 {
t.Errorf("AdditionalInfo.PaymentCards count is wrong: %v", rr.AdditionalInfo)
}
for idx, card := range rr.AdditionalInfo.PaymentCard {
if card.Code != ccards[idx] {
t.Errorf("AdditionalInfo.PaymentCard expect: %s, got: %s", ccards[idx], card.Code)
for idx, card := range rr.AdditionalInfo.PaymentCards {
if card.Code != additionalCards[idx] {
t.Errorf("AdditionalInfo.PaymentCards expect: %s, got: %s", additionalCards[idx], card.Code)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/xml"
)

// BasicPropertyInfo contains all info relevant to property. It is the root-level element after service element for hotel_avail; and is embedded in the RoomStay element.
type BasicPropertyInfo struct {
XMLName xml.Name `xml:"BasicPropertyInfo"`
AreadID string `xml:"AreadID,attr"`
Expand Down Expand Up @@ -41,6 +42,9 @@ type BasicPropertyInfo struct {
SpecialOffers struct {
Ind bool `xml:"Ind,attr"`
} `xml:"SpecialOffers"`
Taxes struct {
Text []string `xml:"Text"`
} `xml:"Taxes"`
VendorMessages VendorMessages
RateRange struct {
CurrencyCode string `xml:"CurrencyCode,attr"`
Expand Down Expand Up @@ -96,70 +100,27 @@ type Rate struct {
HotelPricing HotelPricing
}

type AdditionalInfo struct {
XMLName xml.Name `xml:"AdditionalInfo"`
Commission struct {
NonCommission string `xml:"NonCommission,attr"`
Val string `xml:",char"`
} `xml:"Commission"`
DCACancellation struct {
Text []string `xml:"Text"`
} `xml:"DCA_Cancellation"`
DCAGuarantee struct {
Text []string `xml:"Text"`
} `xml:"DCA_Guarantee"`
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
Option string `xml:"Option,attr"`
} `xml:"CancelPolicy"`
Text []string `xml:"Text"`
}

type RoomRate struct {
XMLName xml.Name `xml:"RoomRate"`
DirectConnect string `xml:"RDirectConnect,attr"`
GuaranteeSurcharge string `xml:"GuaranteeSurchargeRequired,attr"`
GuaranteedRate string `xml:"GuaranteedRateProgram,attr"`
IATA_Character string `xml:"IATA_CharacteristicIdentification,attr"`
IATA_Product string `xml:"IATA_ProductIdentification,attr"`
LowInventory string `xml:"LowInventoryThreshold,attr"`
RateLevelCode string `xml:"RateLevelCode,attr"`
RPH int `xml:"RPH,attr"`
RateChangeInd string `xml:"RateChangeInd,attr"`
RateConversionInd string `xml:"RateConversionInd,attr"`
SpecialOffer string `xml:"SpecialOffer,attr"`
Rates []Rate `xml:"Rates>Rate"`
AdditionalInfo AdditionalInfo
HotelRateCode string `xml:"HotelRateCode"`
}

type VendorMessages struct {
XMLName xml.Name `xml:"VendorMessages"`
Attractions Attractions `xml:"Attractions"`
Awards Awards `xml:"Awards"`
Cancellation Cancellation `xml:"Cancellation"`
Deposit Deposit `xml:"Deposit"`
Description Description `xnl:"Description"`
Dining Dining `xml:"Dining"`
Directions Directions `xml:"Directions"`
Facilities Facilities `xml:"Facilities"`
Guarantee Guarantee `xml:"Guarantee"`
Location Location `xml:"Location"`
MarketingInformation MarketingInformation `xml:"MarketingInformation"`
MiscServices MiscServices `xml:"MiscServices"`
Policies Policies `xml:"Policies"`
Recreation Recreation `xml:"Recreation"`
Rooms Rooms `xml:"Rooms"`
Safety Safety `xml:"Safety"`
Services Services `xml:"Services"`
Transportation Transportation `xml:"Transportation"`
XMLName xml.Name `xml:"VendorMessages"`
Attractions Attractions `xml:"Attractions"`
AdditionalAttractions AdditionalAttractions `xml:"AdditionalAttractions"`
Awards Awards `xml:"Awards"`
Cancellation Cancellation `xml:"Cancellation"`
Deposit Deposit `xml:"Deposit"`
Description Description `xnl:"Description"`
Dining Dining `xml:"Dining"`
Directions Directions `xml:"Directions"`
Facilities Facilities `xml:"Facilities"`
Guarantee VendorGuarantee `xml:"Guarantee"`
Location Location `xml:"Location"`
MarketingInformation MarketingInformation `xml:"MarketingInformation"`
MiscServices MiscServices `xml:"MiscServices"`
Policies Policies `xml:"Policies"`
Recreation Recreation `xml:"Recreation"`
Rooms Rooms `xml:"Rooms"`
Safety Safety `xml:"Safety"`
Services Services `xml:"Services"`
Transportation Transportation `xml:"Transportation"`
}

type Transportation struct {
Expand Down Expand Up @@ -189,7 +150,9 @@ type MarketingInformation struct {
type Location struct {
Text []string `xml:"Text"`
}
type Guarantee struct {
type VendorGuarantee struct {
//this is Guarantee under BasciPropertyInfo.VendorMessages
//not Guarantee element in RoomStay
Text []string `xml:"Text"`
}
type Facilities struct {
Expand All @@ -216,6 +179,9 @@ type Awards struct {
type Attractions struct {
Text []string `xml:"Text"`
}
type AdditionalAttractions struct {
Text []string `xml:"Text"`
}

type IndexD struct {
XMLName xml.Name `xml:"Index"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package hotelws
import "encoding/xml"

/*
Implement Sabre hotel searching through various criteria. Many criterion exist that are not yet implemented: (Award, ContactNumbers, CommissionProgram, HotelAmenity, PointOfInterest, RefPoint, RoomAmenity, HotelFeaturesCriterion). To add more criterion create a criterion type (e.g, XCriterion) as well as its accompanying function to handle the data params (e.g., XSearch); see examples in hotel_search_criteria.go.
Implement Sabre hotel searching through various criteria. Many criterion exist that are not yet implemented: (Award, ContactNumbers, CommissionProgram, HotelAmenity, PointOfInterest, RefPoint, RoomAmenity, HotelFeaturesCriterion). To add more criterion create a criterion type (e.g, XCriterion) as well as its accompanying function to handle the data params (e.g., XSearch); see examples in hotel_search_criteria.go.
*/

// HotelSearchCriteria top level element for criterion
type HotelSearchCriteria struct {
XMLName xml.Name `xml:"HotelSearchCriteria"`
Criterion Criterion
}

// QuerySearchParams is a typed function to support optional query params on creation of new search criterion
type QuerySearchParams func(*HotelSearchCriteria) error

Expand All @@ -21,12 +27,6 @@ type PropertyTypeCriterion []string
// PackageCriterion slice of property type strings (GF, HM, BB)
type PackageCriterion []string

// HotelSearchCriteria top level element for criterion
type HotelSearchCriteria struct {
XMLName xml.Name `xml:"HotelSearchCriteria"`
Criterion Criterion
}

// HotelRef contains any number of search criteria under the HotelRef element.
type HotelRef struct {
XMLName xml.Name `xml:"HotelRef,omitempty"`
Expand Down
85 changes: 62 additions & 23 deletions hotelws/struct_room_stay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,75 @@ package hotelws

import "encoding/xml"

type PaymentCard struct {
XMLName xml.Name `xml:"PaymentCard"`
Code string `xml:"Code,attr"`
Type string `xml:"Type,attr"`
}

type DepositsAccepted struct {
XMLName xml.Name `xml:"DepositsAccepted"`
PaymentCards []PaymentCard
}

type GuaranteesAccepted struct {
XMLName xml.Name `xml:"GuaranteesAccepted"`
PaymentCards []PaymentCard
}

type GuaranteeAccepted struct {
XMLName xml.Name `xml:"Guarantee"`
Guarantees GuaranteesAccepted
Deposits DepositsAccepted
}

// RoomStay contains all info relevant to the property's available rooms. It is the root-level element after service element for hotel_rate_desc and hotel_property_desc.
type RoomStay struct {
XMLName xml.Name `xml:"RoomStay"`
BasicPropertyInfo BasicPropertyInfo
GuaranteeAccepted GuaranteeAccepted
Guarantee Guarantee
RoomRates []RoomRate `xml:"RoomRates>RoomRate"`
TimeSpan struct {
Duration string `xml:"Duration,attr"` //string 0001 or int 1?
End string `xml:"End,attr"`
Start string `xml:"Start,attr"`
} `xml:"TimeSpan"`
}

// Guarantee shows forms of payment accepted by property
type Guarantee struct {
XMLName xml.Name `xml:"Guarantee"`
GuaranteesAccepted GuaranteesAccepted
DepositsAccepted DepositsAccepted
}
type GuaranteesAccepted struct {
XMLName xml.Name `xml:"GuaranteesAccepted"`
PaymentCards []PaymentCard `xml:"PaymentCard"`
}
type DepositsAccepted struct {
XMLName xml.Name `xml:"DepositsAccepted"`
PaymentCards []PaymentCard `xml:"PaymentCard"`
}
type PaymentCard struct {
Code string `xml:"Code,attr"`
Type string `xml:"Type,attr"`
}

type RoomRate struct {
XMLName xml.Name `xml:"RoomRate"`
DirectConnect string `xml:"RDirectConnect,attr"`
GuaranteeSurcharge string `xml:"GuaranteeSurchargeRequired,attr"`
GuaranteedRate string `xml:"GuaranteedRateProgram,attr"`
IATA_Character string `xml:"IATA_CharacteristicIdentification,attr"`
IATA_Product string `xml:"IATA_ProductIdentification,attr"`
LowInventory string `xml:"LowInventoryThreshold,attr"`
RateLevelCode string `xml:"RateLevelCode,attr"`
RPH int `xml:"RPH,attr"`
RateChangeInd string `xml:"RateChangeInd,attr"`
RateConversionInd string `xml:"RateConversionInd,attr"`
SpecialOffer string `xml:"SpecialOffer,attr"`
Rates []Rate `xml:"Rates>Rate"`
AdditionalInfo AdditionalInfo
HotelRateCode string `xml:"HotelRateCode"`
}
type AdditionalInfo struct {
XMLName xml.Name `xml:"AdditionalInfo"`
Commission struct {
NonCommission string `xml:"NonCommission,attr"`
Val string `xml:",char"`
} `xml:"Commission"`
DCACancellation struct {
Text []string `xml:"Text"`
} `xml:"DCA_Cancellation"`
DCAGuarantee struct {
Text []string `xml:"Text"`
} `xml:"DCA_Guarantee"`
DCAOther struct {
Text []string `xml:"Text"`
} `xml:"DCA_Other"`
PaymentCards []PaymentCard `xml:"PaymentCard"`
Taxes string `xml:"Taxes"`
CancelPolicy struct {
Numeric int `xml:"Numeric,attr"` //string? 001 versus 1
Option string `xml:"Option,attr"`
} `xml:"CancelPolicy"`
Text []string `xml:"Text"`
}
Loading

0 comments on commit 7f69725

Please sign in to comment.