rentease/internal/service/booking/sync_test.go

59 lines
3.1 KiB
Go

package booking_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/rjNemo/rentease/internal/service/booking"
)
const content = " Date d'arrivée jeu. 3 avr. 2025 Date de départ dim. 6 avr. 2025 Durée de séjour : 3 nuits Nombre de personnes : \n 2\n Nombre d'hébergements \n 1\n Montant total € 186 Nom du client : \n Olga Korovina\n \n ru\n \n okorov.905387@guest.booking.com\n Contactez vos clients ! Indiquez-leur l'heure à laquelle vous souhaitez les accueillir ou l'endroit où ils récupéreront leurs clés. Un simple appel suffit : Afficher le numéro de téléphone Vous pouvez également leur envoyer un e-mail ou un message. Langue préférée \n russe\n Canal : Booking.com Code IATA/TIDS : \n PC029090\n Numéro de réservation : \n 4453602306\n Montant soumis à commission : € 177 Reçu jeu. 2 janv. 2025 Commission : € 31,86 Bloc-notes (usage interne) Ajoutez une note ici \n\n Maison 1 Chambre T2 - VillaFleurie au bourg du Gosier)\n € 186 jeu. 3 avr. 2025 dim. 6 avr. 2025 Nom du client \n Olga Korovina\n Occupation maximum 2 adultes, 2 enfants (3 personnes max.) Photo de l'hébergement Date Tarif Tarif par nuit \n 03 - 04 avril\n \n Standard Rate\n € 59\n 04 - 05 avril\n \n Standard Rate\n € 59\n 05 - 06 avril\n \n Standard Rate\n € 59Sous-total € 177\n Taxe de séjour\n € 1.50 par personne et par nuit € 9Tarif total de l'hébergement € 186 Le tarif comprend 8.9 % de TVA Conversation avec le client \n Aucun message\n \n Les conversations avec vos clients apparaîtront ici.\n Booking.com reçoit tous les messages écrits ici et les traite selon sa Charte de confidentialité et informations sur les cookies Conditions "
func TestParseFromApi(t *testing.T) {
externalId := "4453602306"
tests := []struct {
name string
rawContent string
expected *booking.Booking
}{
{
name: "parse booking from raw content",
rawContent: content,
expected: &booking.Booking{
From: time.Date(2025, time.April, 3, 0, 0, 0, 0, time.UTC),
To: time.Date(2025, time.April, 6, 0, 0, 0, 0, time.UTC),
Name: "Olga Korovina",
Email: "okorov.905387@guest.booking.com",
Platform: "Booking",
CustomerNumber: 2,
PlatformFees: 31.86,
ExternalId: &externalId,
Canceled: false,
Items: []booking.Item{
{
BookingId: 0,
Item: "T2",
Quantity: 3,
Price: 59.0,
PaymentMethod: "Card",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
bs, _ := booking.NewService(&booking.MockStore{}, nil, nil, nil)
actual, err := bs.ParseFromApi(tt.rawContent)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
assert.Equal(t, tt.expected, actual, "expected %v, got %v", tt.expected, actual)
})
}
}