Skip to content

Commit

Permalink
Merge pull request #4 from ailgroup/hotel_res
Browse files Browse the repository at this point in the history
Hotel res
  • Loading branch information
jbowles authored Jun 9, 2018
2 parents f43a92f + b11d5f5 commit 1865981
Show file tree
Hide file tree
Showing 29 changed files with 1,853 additions and 1,339 deletions.
21 changes: 12 additions & 9 deletions hotelws/hotel_avail.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (a *OTAHotelAvailRQ) addCustomerID(cID string) {
}
}

// SetHotelAvailRqStruct hotel availability request using input parameters
func SetHotelAvailRqStruct(guestCount int, query *HotelSearchCriteria, arrive, depart string) HotelAvailBody {
a, d := arriveDepartParser(arrive, depart)
// SetHotelAvailBody hotel availability request using input parameters
func SetHotelAvailBody(guestCount int, query *HotelSearchCriteria, arrive, depart string) HotelAvailBody {
ts := TimeSpanFormatter(arrive, depart, TimeFormatMD, TimeFormatMD)
return HotelAvailBody{
OTAHotelAvailRQ: OTAHotelAvailRQ{
Version: hotelRQVersion,
Expand All @@ -65,10 +65,7 @@ func SetHotelAvailRqStruct(guestCount int, query *HotelSearchCriteria, arrive, d
Avail: AvailRequestSegment{
GuestCounts: &GuestCounts{Count: guestCount},
HotelSearchCriteria: query,
TimeSpan: &TimeSpan{
Depart: d.Format(timeSpanFormatter),
Arrive: a.Format(timeSpanFormatter),
},
TimeSpan: &ts,
},
},
}
Expand Down Expand Up @@ -113,7 +110,7 @@ type AvailabilityOptions struct {
}

type AvailabilityOption struct {
RPH int `xml:"RPH,attr"` //string? 001 versus 1
RPH string `xml:"RPH,attr"` //string? 001 versus 1
PropertyInfo BasicPropertyInfo
}

Expand All @@ -132,7 +129,7 @@ type OTAHotelAvailRS struct {
AvailOpts AvailabilityOptions
}

// HotelAvailResponse is wrapper with namespace prefix definitions for payload
// HotelAvailResponse for parsing hote availability response
type HotelAvailResponse struct {
Envelope srvc.EnvelopeUnMarsh
Header srvc.SessionHeaderUnmarsh
Expand Down Expand Up @@ -168,5 +165,11 @@ func CallHotelAvail(serviceURL string, req HotelAvailRequest) (HotelAvailRespons
availResp.ErrorSabreXML = sbrerr.NewErrorSabreXML(err.Error(), sbrerr.ErrCallHotelAvail, sbrerr.BadParse)
return availResp, availResp.ErrorSabreXML
}
if !availResp.Body.Fault.Ok() {
return availResp, availResp.Body.Fault.Format()
}
if !availResp.Body.HotelAvail.Result.Ok() {
return availResp, availResp.Body.HotelAvail.Result.ErrFormat()
}
return availResp, nil
}
27 changes: 14 additions & 13 deletions hotelws/hotel_avail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hotelws

import (
"encoding/xml"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -175,7 +176,7 @@ func TestMultipleHotelCriteria(t *testing.T) {
}

func TestSetHotelAvailRqStructMarshal(t *testing.T) {
availBody := SetHotelAvailRqStruct(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
avail := availBody.OTAHotelAvailRQ
avail.addCorporateID(sampleCID)

Expand All @@ -199,7 +200,7 @@ func TestSetHotelAvailRqStructMarshal(t *testing.T) {
}

func TestSetHotelAvailRqStructCorpID(t *testing.T) {
availBody := SetHotelAvailRqStruct(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
avail := availBody.OTAHotelAvailRQ
avail.addCorporateID(sampleCID)

Expand All @@ -219,7 +220,7 @@ func TestAvailIdsMarshal(t *testing.T) {
HotelRefSearch(hqids),
)
gcount := 4
availBody := SetHotelAvailRqStruct(gcount, q, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(gcount, q, sampleArrive, sampleDepart)

avail := availBody.OTAHotelAvailRQ
avail.addCorporateID(sampleCID)
Expand Down Expand Up @@ -248,7 +249,7 @@ func TestAvailCitiesMarshal(t *testing.T) {
HotelRefSearch(hqcity),
)
gcount := 3
availBody := SetHotelAvailRqStruct(gcount, q, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(gcount, q, sampleArrive, sampleDepart)
avail := availBody.OTAHotelAvailRQ
avail.addCustomerID(sampleCID)

Expand All @@ -274,7 +275,7 @@ func TestAvailLatLngMarshal(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqltln),
)
availBody := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := availBody.OTAHotelAvailRQ

if avail.Avail.GuestCounts.Count != sampleGuestCount {
Expand All @@ -300,7 +301,7 @@ func TestAvailPropertyTypesPackagesMarshal(t *testing.T) {
PackageSearch(samplePackages),
PropertyTypeSearch(samplePropertyTypes),
)
availBody := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
availBody := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := availBody.OTAHotelAvailRQ

b, err := xml.Marshal(avail)
Expand All @@ -317,7 +318,7 @@ func TestBuildHotelAvailRequestMarshal(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqids),
)
avail := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelAvailRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, avail)

b, err := xml.Marshal(req)
Expand Down Expand Up @@ -347,7 +348,7 @@ func TestHotelAvailUnmarshal(t *testing.T) {
}

options := avail.Body.HotelAvail.AvailOpts.AvailableOptions[0]
if options.RPH != 1 {
if options.RPH != "1" {
t.Errorf("First Availability option should be 1")
}
rr := options.PropertyInfo.RoomRateAvail
Expand Down Expand Up @@ -378,7 +379,7 @@ func TestHotelAvailCallByIDs(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqids),
)
avail := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelAvailRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, avail)
resp, err := CallHotelAvail(serverHotelAvailability.URL, req)
if err != nil {
Expand All @@ -389,8 +390,8 @@ func TestHotelAvailCallByIDs(t *testing.T) {
}

for idx, o := range resp.Body.HotelAvail.AvailOpts.AvailableOptions {
if o.RPH != idx+1 {
t.Errorf("AvailableOptions %d RPH expected %d, got %d", idx, idx+1, o.RPH)
if o.RPH != fmt.Sprintf("%d", idx+1) {
t.Errorf("AvailableOptions %d RPH expected %d, got %s", idx, idx+1, o.RPH)
}
if o.PropertyInfo.HotelCityCode != "TUL" {
t.Errorf("AvailableOptions %d HotelCityCode expected %s, got %s", idx, "TUL", o.PropertyInfo.HotelCityCode)
Expand All @@ -403,7 +404,7 @@ func TestHotelAvailCallDown(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqids),
)
avail := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelAvailRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, avail)
resp, err := CallHotelAvail(serverHotelDown.URL, req)
if err == nil {
Expand All @@ -424,7 +425,7 @@ func TestHotelAvailCallBadResponseBody(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqids),
)
avail := SetHotelAvailRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
avail := SetHotelAvailBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelAvailRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, avail)
resp, err := CallHotelAvail(serverBadBody.URL, req)
if err == nil {
Expand Down
17 changes: 10 additions & 7 deletions hotelws/hotel_prop_desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func (a *HotelPropDescRQ) addCustomerID(cID string) {
}
}

// SetHotelPropDescRqStruct hotel availability request using input parameters
func SetHotelPropDescRqStruct(guestCount int, query *HotelSearchCriteria, arrive, depart string) (HotelPropDescBody, error) {
// SetHotelPropDescBody hotel availability request using input parameters
func SetHotelPropDescBody(guestCount int, query *HotelSearchCriteria, arrive, depart string) (HotelPropDescBody, error) {
err := query.validatePropertyRequest()
if err != nil {
return HotelPropDescBody{}, err
}
a, d := arriveDepartParser(arrive, depart)
ts := TimeSpanFormatter(arrive, depart, TimeFormatMD, TimeFormatMD)
return HotelPropDescBody{
HotelPropDescRQ: HotelPropDescRQ{
Version: hotelRQVersion,
Expand All @@ -69,10 +69,7 @@ func SetHotelPropDescRqStruct(guestCount int, query *HotelSearchCriteria, arrive
Avail: AvailRequestSegment{
GuestCounts: &GuestCounts{Count: guestCount},
HotelSearchCriteria: query,
TimeSpan: &TimeSpan{
Depart: d.Format(timeSpanFormatter),
Arrive: a.Format(timeSpanFormatter),
},
TimeSpan: &ts,
},
},
}, nil
Expand Down Expand Up @@ -158,5 +155,11 @@ func CallHotelPropDesc(serviceURL string, req HotelPropDescRequest) (HotelPropDe
propResp.ErrorSabreXML = sbrerr.NewErrorSabreXML(err.Error(), sbrerr.ErrCallHotelPropDesc, sbrerr.BadParse)
return propResp, propResp.ErrorSabreXML
}
if !propResp.Body.Fault.Ok() {
return propResp, propResp.Body.Fault.Format()
}
if !propResp.Body.HotelDesc.Result.Ok() {
return propResp, propResp.Body.HotelDesc.Result.ErrFormat()
}
return propResp, nil
}
18 changes: 9 additions & 9 deletions hotelws/hotel_prop_desc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestPropDescValidReqCityCode(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqcity),
)
_, err := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
_, err := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
if err != sbrerr.ErrPropDescCityCode {
t.Error("ErrPropDescCityCode should return")
}
Expand All @@ -23,7 +23,7 @@ func TestPropDescValidReqLatLng(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqltln),
)
_, err := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
_, err := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
if err != sbrerr.ErrPropDescLatLng {
t.Error("ErrPropDescLatLng should return")
}
Expand All @@ -34,7 +34,7 @@ func TestPropDescValidMultiHotelRefs(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hqids),
)
_, err := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
_, err := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
if err != sbrerr.ErrPropDescHotelRefs {
t.Error("ErrPropDescHotelRefs should return error")
}
Expand All @@ -46,7 +46,7 @@ func TestPropDescBuildHotelPropDescMarshal(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hotelid),
)
prop, err := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
prop, err := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
if err != nil {
t.Error("Error SetHotelPropDescRqStruct: ", err)
}
Expand All @@ -64,7 +64,7 @@ func TestPropDescBuildHotelPropDescMarshal(t *testing.T) {
}

func TestSetHotelPropDescRqStructCorpID(t *testing.T) {
body, _ := SetHotelPropDescRqStruct(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
body, _ := SetHotelPropDescBody(sampleGuestCount, &HotelSearchCriteria{}, sampleArrive, sampleDepart)
prop := body.HotelPropDescRQ
prop.addCorporateID(sampleCID)

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestPropDescUnmarshal(t *testing.T) {
rate0 := roomStayRates[0]
sample0 := rateSamples[0]
if rate0.RPH != sample0.rph {
t.Errorf("RPH expected %d, got %d", sample0.rph, rate0.RPH)
t.Errorf("RPH expected %s, got %s", sample0.rph, rate0.RPH)
}
if rate0.GuaranteedRate != sample0.guarrate {
t.Errorf("GuaranteedRate expected %s, got %s", sample0.guarrate, rate0.GuaranteedRate)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestPropDescCall(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hotelid),
)
prop, _ := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
prop, _ := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelPropDescRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, prop)

resp, err := CallHotelPropDesc(serverHotelPropertyDesc.URL, req)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestHotelPropDescCallDown(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hotelid),
)
prop, _ := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
prop, _ := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelPropDescRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, prop)

resp, err := CallHotelPropDesc(serverHotelDown.URL, req)
Expand All @@ -243,7 +243,7 @@ func TestHotelPropDescCallBadResponseBody(t *testing.T) {
q, _ := NewHotelSearchCriteria(
HotelRefSearch(hotelid),
)
prop, _ := SetHotelPropDescRqStruct(sampleGuestCount, q, sampleArrive, sampleDepart)
prop, _ := SetHotelPropDescBody(sampleGuestCount, q, sampleArrive, sampleDepart)
req := BuildHotelPropDescRequest(samplesite, samplepcc, samplebinsectoken, sampleconvid, samplemid, sampletime, prop)

resp, err := CallHotelPropDesc(serverBadBody.URL, req)
Expand Down
10 changes: 8 additions & 2 deletions hotelws/hotel_rate_desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type HotelRateDescRQ struct {
Avail AvailRequestSegment
}

// SetHotelRateDescRqStruct hotel rate description request using input parameters
func SetHotelRateDescRqStruct(rpc *RatePlanCandidates) (HotelRateDescBody, error) {
// SetHotelRateDescBody hotel rate description request using input parameters
func SetHotelRateDescBody(rpc *RatePlanCandidates) (HotelRateDescBody, error) {
return HotelRateDescBody{
HotelRateDescRQ: HotelRateDescRQ{
Version: hotelRQVersion,
Expand Down Expand Up @@ -130,5 +130,11 @@ func CallHotelRateDesc(serviceURL string, req HotelRateDescRequest) (HotelRateDe
rateResp.ErrorSabreXML = sbrerr.NewErrorSabreXML(err.Error(), sbrerr.ErrCallHotelRateDesc, sbrerr.BadParse)
return rateResp, rateResp.ErrorSabreXML
}
if !rateResp.Body.Fault.Ok() {
return rateResp, rateResp.Body.Fault.Format()
}
if !rateResp.Body.HotelDesc.Result.Ok() {
return rateResp, rateResp.Body.HotelDesc.Result.ErrFormat()
}
return rateResp, nil
}
Loading

0 comments on commit 1865981

Please sign in to comment.