mts-booking-library 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ // import { MTSEnvs } from "../config";
3
+ // import { ServiceBooking } from "../booking/serviceBooking";
4
+ // import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
5
+ // import { Service, ServiceTripsResponse } from "../types/services/Service";
6
+ // import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
7
+ // import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
8
+ // import { useTestState } from "../mtsStorage";
9
+ // import { SubscriptionBooking } from "../booking/subscriptionBooking";
10
+ // // Load .env file
11
+ // require('dotenv').config();
12
+ // // How to run the test: npm run test -- SubscriptionBooking.test.ts
13
+ // describe("SubscriptionBooking", () => {
14
+ // const timeOut = 120000;
15
+ // const sub_key = process.env.OCP_SUB_KEY_MTS;
16
+ // const access_token = process.env.ACCESS_TOKEN;
17
+ // const sellerId = 8; // ATV
18
+ // // Define localStorage for local testing
19
+ // if (typeof localStorage === "undefined" || localStorage === null) {
20
+ // var LocalStorage = require("node-localstorage").LocalStorage;
21
+ // global.localStorage = new LocalStorage("./scratch");
22
+ // }
23
+ // test("search_tpl", async () => {
24
+ // const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
25
+ // // First, get the departures
26
+ // const departures = await booking.getSubscriptionsDepartures() as string[];
27
+ // expect(departures.length).toBeGreaterThan(0);
28
+ // expect(departures).toContain("APT TREVISO CANOVA");
29
+ // const selectedDeparture = "APT TREVISO CANOVA";
30
+ // const destinations = await booking.getJourneysDestinations(selectedDeparture);
31
+ // expect(destinations).toContain("MESTRE FFSS");
32
+ // }, timeOut);
33
+ // const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
34
+ // const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
35
+ // const services = servicesResponse as Service[];
36
+ // // Build create cart request
37
+ // let tariffsMatrix = services[0].tariffsMatrix;
38
+ // tariffsMatrix[0][0].quantity = 1;
39
+ // const createServiceCartRequest: CreateServiceCartRequest = {
40
+ // currency: ServiceBooking.Currencies.EUR,
41
+ // service: {
42
+ // serviceId: services[0].id,
43
+ // tariffsMatrix: tariffsMatrix
44
+ // }
45
+ // };
46
+ // // Create cart
47
+ // const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
48
+ // return cart;
49
+ // }
50
+ // test("create_service_cart", async () => {
51
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
52
+ // const cart = await createCart(booking);
53
+ // // Check that the cartId was saved to the local storage
54
+ // expect(useTestState().getState().cartId).toBe(cart.id);
55
+ // expect(booking.cartId).toBe(cart.id);
56
+ // // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
57
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
58
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
59
+ // // Test booking due date
60
+ // expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
61
+ // // Test expired tickets
62
+ // expect(cart.hasIssuedTickets).toBe(false);
63
+ // // Test seller data
64
+ // expect(booking.getSellerId()).toBe(cart.sellerId);
65
+ // expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
66
+ // expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
67
+ // // Now try to get the cart
68
+ // const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
69
+ // expect(newBooking.cartId).toBe(cart.id);
70
+ // expect(newBooking.getCart()?.id).toBe(cart.id)
71
+ // expect(newBooking.getSellerId()).toBe(cart.sellerId);
72
+ // // Finally try to delete the cart
73
+ // await booking.deleteCart();
74
+ // expect(booking.getCart()).toBe(undefined);
75
+ // expect(useTestState().getState().cartId).toBe(undefined);
76
+ // }, timeOut);
77
+ // test("get_edit_buyer_data", async () => {
78
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
79
+ // const cart = await createCart(booking);
80
+ // // First, try to get the buyer data
81
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
82
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
83
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
84
+ // expect(buyer).toBe(null);
85
+ // // Now try to edit the buyer data
86
+ // buyer = {
87
+ // id: 0,
88
+ // name: "TestName",
89
+ // lastName: "TestSurname",
90
+ // email: "testBookingLib@infos.it",
91
+ // phoneNumber: "+391234567890"
92
+ // }
93
+ // await booking.updateBuyerPassengersDetails(buyer);
94
+ // // Finally, get the buyer data again and check that the data was updated
95
+ // buyerDataResponse = await booking.getBuyerPassengersDetails();
96
+ // const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
97
+ // expect(updatedBuyer.id).toBeGreaterThan(0);
98
+ // expect(updatedBuyer.name).toBe(buyer.name);
99
+ // expect(updatedBuyer.lastName).toBe(buyer.lastName);
100
+ // expect(updatedBuyer.email).toBe(buyer.email);
101
+ // expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
102
+ // // Finally try to delete the cart
103
+ // await booking.deleteCart();
104
+ // expect(booking.getCart()).toBe(undefined);
105
+ // expect(useTestState().getState().cartId).toBe(undefined);
106
+ // }, timeOut);
107
+ // test("get_gateway_info", async () => {
108
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
109
+ // const cart = await createCart(booking);
110
+ // booking.updateSellerId(cart.sellerId);
111
+ // // First, try to get the buyer data
112
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
113
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
114
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
115
+ // expect(buyer).toBe(null);
116
+ // // Now try to edit the buyer data
117
+ // buyer = {
118
+ // id: 0,
119
+ // name: "TestName",
120
+ // lastName: "TestSurname",
121
+ // email: "testBookingLib@infos.it",
122
+ // phoneNumber: "+391234567890"
123
+ // }
124
+ // await booking.updateBuyerPassengersDetails(buyer);
125
+ // // Try to get the gateways
126
+ // const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
127
+ // if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
128
+ // throw new Error("No gateways found");
129
+ // }
130
+ // const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
131
+ // expect(gateway?.id).toBeGreaterThan(0);
132
+ // // Now try to get the info
133
+ // const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
134
+ // // Finally try to delete the cart
135
+ // await booking.deleteCart();
136
+ // expect(booking.getCart()).toBe(undefined);
137
+ // expect(useTestState().getState().cartId).toBe(undefined);
138
+ // }, timeOut);
139
+ // });
@@ -133,11 +133,12 @@ var JourneyBooking = /** @class */ (function (_super) {
133
133
  switch (_a.label) {
134
134
  case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
135
135
  if (cart) {
136
- var cartDate = new Date(cart.bookingDueDate);
137
- if (cartDate > new Date() && !cart.hasIssuedTickets) {
136
+ var cartDueDate = new Date();
137
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
138
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
138
139
  _this.cart = cart;
139
140
  _this.cartId = cart.id;
140
- _this.bookingDueDate = cartDate; // See Booking class
141
+ _this.bookingDueDate = cartDueDate; // See Booking class
141
142
  // Update the sellerId. This is particularly important in Linkavel
142
143
  _this.updateSellerId(cart.sellerId);
143
144
  // Fill the booking process status
@@ -133,11 +133,12 @@ var ServiceBooking = /** @class */ (function (_super) {
133
133
  switch (_a.label) {
134
134
  case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
135
135
  if (cart) {
136
- var cartDate = new Date(cart.bookingDueDate);
137
- if (cartDate > new Date() && !cart.hasIssuedTickets) {
136
+ var cartDueDate = new Date();
137
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
138
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
138
139
  _this.cart = cart;
139
140
  _this.cartId = cart.id;
140
- _this.bookingDueDate = cartDate; // See Booking class
141
+ _this.bookingDueDate = cartDueDate; // See Booking class
141
142
  // Update the sellerId. This is particularly important in Linkavel
142
143
  _this.updateSellerId(cart.sellerId);
143
144
  // Fill the booking process status
@@ -133,11 +133,12 @@ var SubscriptionBooking = /** @class */ (function (_super) {
133
133
  switch (_a.label) {
134
134
  case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
135
135
  if (cart) {
136
- var cartDate = new Date(cart.bookingDueDate);
137
- if (cartDate > new Date() && !cart.hasIssuedTickets) {
136
+ var cartDueDate = new Date();
137
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
138
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
138
139
  _this.cart = cart;
139
140
  _this.cartId = cart.id;
140
- _this.bookingDueDate = cartDate; // See Booking class
141
+ _this.bookingDueDate = cartDueDate; // See Booking class
141
142
  // Update the sellerId. This is particularly important in Linkavel
142
143
  _this.updateSellerId(cart.sellerId);
143
144
  // Fill the booking process status
@@ -133,11 +133,12 @@ var TplBooking = /** @class */ (function (_super) {
133
133
  switch (_a.label) {
134
134
  case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
135
135
  if (cart) {
136
- var cartDate = new Date(cart.bookingDueDate);
137
- if (cartDate > new Date() && !cart.hasIssuedTickets) {
136
+ var cartDueDate = new Date();
137
+ cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
138
+ if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
138
139
  _this.cart = cart;
139
140
  _this.cartId = cart.id;
140
- _this.bookingDueDate = cartDate; // See Booking class
141
+ _this.bookingDueDate = cartDueDate; // See Booking class
141
142
  // Update the sellerId. This is particularly important in Linkavel
142
143
  _this.updateSellerId(cart.sellerId);
143
144
  // Fill the booking process status
@@ -21,6 +21,7 @@ import { Extra } from "./Extra";
21
21
  * - The second tells whether the section is completed.
22
22
  * - The third tells whether the section is required.
23
23
  * @property {Booking.Currencies} currency The currency of the cart. See {@link Booking.Currencies}
24
+ * @property {number} bookingDueDateRemainingSeconds The number of seconds remaining before the cart expires. This should be equivalent `bookingDueDate`
24
25
  * @property {string} bookingDueDate The date and time when the cart expires
25
26
  * @property {Reduction[]} reductions The list of reductions applied to the cart
26
27
  * @property {Extra[]} extras The list of extras services of the cart
@@ -42,6 +43,7 @@ export type Cart = {
42
43
  stepsToStatus: Map<string, boolean[]>;
43
44
  currency: Booking.Currencies;
44
45
  bookingDueDate: string;
46
+ bookingDueDateRemainingSeconds: number;
45
47
  reductions: Reduction[];
46
48
  extras: Extra[];
47
49
  sellingMethod: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",