Files
hardlink/cms/hotel_details_test.go
T

61 lines
2.9 KiB
Go

package cms
import (
"encoding/json"
"net/http"
"reflect"
"sync/atomic"
"testing"
"gitea.futuresens.co.uk/futuresens/cmstypes"
)
func TestReadHotelDetailsRetainsCMSPaymentConfiguration(t *testing.T) {
var calls atomic.Int32
hotel := cmstypes.Hotel{Currency: cmstypes.CurrencyRec{Code: "GBP", NumDecimals: 2}}
hotel.Updated = 1
hotel.ReservationSystem = cmstypes.ReservationSystemRec{PaymentSystem: cmstypes.PaySystemTrustPayments, PaymentGatewayURL: "https://sandbox.link.trustpayments.com/trustpayments/rest", PaymentGatewaySiteIDEPOS: "SYNTH-SITE", PaymentGatewayPasswordEPOS: "SYNTH-PASSWORD", TimeZone: "Europe/London", PDQs: []cmstypes.PDQRec{{Kiosk: 9, Serial: "SYNTH-PED"}}}
server := newCMSMockServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
calls.Add(1)
if r.Method != http.MethodPost || r.URL.Path != cmstypes.APIHotelDetails {
t.Errorf("CMS request = %s %s, want existing hotel-details POST", r.Method, r.URL.Path)
}
var request cmstypes.RequestRec
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
t.Error(err)
}
if request.Auth.Hotel != "SYNTH-HOTEL" || request.Data != "SYNTH-HOTEL" {
t.Error("CMS hotel identity changed")
}
response := cmstypes.HotelResponseRec{TheHotel: hotel}
response.Status.Code = cmstypes.StatusSuccessCode
if err := json.NewEncoder(w).Encode(response); err != nil {
t.Error(err)
}
}))
defer server.Close()
got, err := ReadHotelDetails("SYNTH-HOTEL", server.URL)
if err != nil || !reflect.DeepEqual(got, hotel) || calls.Load() != 1 {
t.Fatalf("ReadHotelDetails = %+v/%v requests=%d, want complete CMS hotel in one request", got, err, calls.Load())
}
}
func TestReadHotelProjectionPreservesOtherProviderSettings(t *testing.T) {
for _, provider := range []int{cmstypes.PaySystemCreditCall, cmstypes.PaySystemDojo, cmstypes.PaySystemPayBridge} {
t.Run(cmstypes.PaySystemNames[provider], func(t *testing.T) {
var calls atomic.Int32
response := cmstypes.HotelResponseRec{}
response.Status.Code = cmstypes.StatusSuccessCode
response.TheHotel.Updated = 1
response.TheHotel.Currency = cmstypes.CurrencyRec{Code: "GBP", NumDecimals: 2}
response.TheHotel.ReservationSystem = cmstypes.ReservationSystemRec{PaymentSystem: provider, PaymentGatewayURL: "https://synthetic.invalid", PaymentGatewayAPIKeyWeb: "SYNTH-API", PaymentGatewaySiteIDEPOS: "SYNTH-SITE", PaymentGatewayPasswordEPOS: "SYNTH-PASSWORD", PDQs: []cmstypes.PDQRec{{Kiosk: 9, Serial: "SYNTH-PED"}}}
server := newCMSMockServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { calls.Add(1); _ = json.NewEncoder(w).Encode(response) }))
defer server.Close()
got, err := ReadHotel("SYNTH-HOTEL", server.URL)
if err != nil || !reflect.DeepEqual(got, response.TheHotel.ReservationSystem) || calls.Load() != 1 {
t.Fatalf("ReadHotel projection = %+v/%v calls=%d, want unchanged provider settings and one request", got, err, calls.Load())
}
})
}
}