mts-booking-library 1.3.25 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/booking.d.ts +25 -1
- package/lib/booking/booking.js +66 -0
- package/lib/types/common/Extra.d.ts +13 -1
- package/lib/types/common/Tariffs.d.ts +2 -0
- package/lib/utils/apiCall.d.ts +1 -0
- package/lib/utils/apiCall.js +68 -7
- package/package.json +1 -1
- package/lib/SubscriptionBooking.d.ts +0 -0
- package/lib/SubscriptionBooking.js +0 -148
- package/lib/utils/testUtils.d.ts +0 -8
- package/lib/utils/testUtils.js +0 -19
package/lib/booking/booking.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { MTSConfig, MTSEnvs } from "../config";
|
2
2
|
import { ErrorResponse } from "../types/ErrorResponse";
|
3
|
-
import { processedStepsToStatus } from "../types/common/Cart";
|
3
|
+
import { Cart, processedStepsToStatus } from "../types/common/Cart";
|
4
|
+
import { GetExtrasForBookingResponse, GetExtrasResponse } from "../types/common/Extra";
|
4
5
|
import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueTicketsResponse } from "../types/common/Payment";
|
5
6
|
import { Buyer, GetBuyerPassengersDetailsResponse, GetBuyerRequest } from "../types/common/Person";
|
6
7
|
import { AddReductionRequest } from "../types/common/Reduction";
|
@@ -42,6 +43,7 @@ export declare abstract class Booking {
|
|
42
43
|
renewAccessToken(access_token: string): void;
|
43
44
|
callGetApi(url: string): Promise<ErrorResponse | any>;
|
44
45
|
callPostApi(url: string, body: any): Promise<any>;
|
46
|
+
callPutApi(url: string, body: any): Promise<any>;
|
45
47
|
callDeleteApi(url: string): Promise<ErrorResponse | any>;
|
46
48
|
getBookingStepsToStatus(): processedStepsToStatus;
|
47
49
|
changeCurrency(currency: Booking.Currencies): void;
|
@@ -82,6 +84,28 @@ export declare abstract class Booking {
|
|
82
84
|
* @returns An {@link IssueTicketsResponse} object.
|
83
85
|
*/
|
84
86
|
issueTickets(paymentMethod: PaymentMethods): Promise<ErrorResponse | IssueTicketsResponse>;
|
87
|
+
getExtras({ extraId, tariffPlanId }?: {
|
88
|
+
/** The extra object identifier. By default, all the extras of the seller are returned. */
|
89
|
+
extraId?: number;
|
90
|
+
/** If present, the extras that are part of that tariff plan are returned. */
|
91
|
+
tariffPlanId?: number;
|
92
|
+
}): Promise<ErrorResponse | GetExtrasResponse>;
|
93
|
+
/**
|
94
|
+
* Fetches extras tariffs for the given cart
|
95
|
+
* @param cartGuid The guid of the cart
|
96
|
+
* @param tripId The ID of the trip for which the extras are requested. Please note that this
|
97
|
+
* parameter is required when adding extras to a MLP or services cart.
|
98
|
+
*/
|
99
|
+
getExtrasForBooking(cartGuid: string, tripId?: number): Promise<ErrorResponse | GetExtrasForBookingResponse>;
|
100
|
+
/**
|
101
|
+
* Updates the extras associated with a cart, removing all previous ones.
|
102
|
+
* @param cartGuid The guid of the cart
|
103
|
+
* @param tariffIdToQuantity A map of tariff ids to the quantity of tickets to add for that tariff
|
104
|
+
*/
|
105
|
+
updateExtrasForCart(cartGuid: string, tariffIdToQuantity: Record<number, number>): Promise<ErrorResponse | {}>;
|
106
|
+
abstract getCart(): Cart | undefined;
|
107
|
+
abstract fetchAndSetCart(cartGuid: string): Promise<void>;
|
108
|
+
abstract fetchCart(cartGuid: string): Promise<Cart>;
|
85
109
|
}
|
86
110
|
export declare namespace Booking {
|
87
111
|
enum Currencies {
|
package/lib/booking/booking.js
CHANGED
@@ -125,6 +125,13 @@ var Booking = /** @class */ (function () {
|
|
125
125
|
(0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }));
|
126
126
|
return (0, apiCall_1.makePost)(url, completeBody);
|
127
127
|
};
|
128
|
+
Booking.prototype.callPutApi = function (url, body) {
|
129
|
+
var _a, _b, _c, _d;
|
130
|
+
// Add sellerId, resellerId and language to the query string
|
131
|
+
var completeBody = __assign(__assign(__assign({}, body), { sellerId: (_b = (_a = this.sellerId) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 0, resellerId: (_d = (_c = this.resellerId) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : 0, language: this.language }), ((0, config_1.getConfig)().ENV === config_1.MTSEnvs.DEV &&
|
132
|
+
(0, config_1.getConfig)().DB_TYPE && { databaseType: (0, config_1.getConfig)().DB_TYPE }));
|
133
|
+
return (0, apiCall_1.makePut)(url, completeBody);
|
134
|
+
};
|
128
135
|
Booking.prototype.callDeleteApi = function (url) {
|
129
136
|
var _a, _b, _c, _d;
|
130
137
|
// Add sellerId, resellerId and language to the query string.
|
@@ -350,6 +357,65 @@ var Booking = /** @class */ (function () {
|
|
350
357
|
});
|
351
358
|
});
|
352
359
|
};
|
360
|
+
//#endregion
|
361
|
+
// #region Extras
|
362
|
+
Booking.prototype.getExtras = function () {
|
363
|
+
return __awaiter(this, arguments, void 0, function (_a) {
|
364
|
+
var searchParams, url;
|
365
|
+
var _b = _a === void 0 ? {} : _a, extraId = _b.extraId, tariffPlanId = _b.tariffPlanId;
|
366
|
+
return __generator(this, function (_c) {
|
367
|
+
searchParams = new URLSearchParams(__assign(__assign({}, (extraId && { extraId: extraId.toString() })), (tariffPlanId && { tariffPlanId: tariffPlanId.toString() })));
|
368
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_resources/extras?").concat(searchParams);
|
369
|
+
return [2 /*return*/, this.callGetApi(url)];
|
370
|
+
});
|
371
|
+
});
|
372
|
+
};
|
373
|
+
/**
|
374
|
+
* Fetches extras tariffs for the given cart
|
375
|
+
* @param cartGuid The guid of the cart
|
376
|
+
* @param tripId The ID of the trip for which the extras are requested. Please note that this
|
377
|
+
* parameter is required when adding extras to a MLP or services cart.
|
378
|
+
*/
|
379
|
+
Booking.prototype.getExtrasForBooking = function (cartGuid, tripId) {
|
380
|
+
return __awaiter(this, void 0, void 0, function () {
|
381
|
+
var searchParams, url;
|
382
|
+
return __generator(this, function (_a) {
|
383
|
+
searchParams = new URLSearchParams(__assign({ cartGuid: cartGuid }, (tripId && { tripId: tripId.toString() })));
|
384
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/extras?").concat(searchParams);
|
385
|
+
return [2 /*return*/, this.callGetApi(url)];
|
386
|
+
});
|
387
|
+
});
|
388
|
+
};
|
389
|
+
/**
|
390
|
+
* Updates the extras associated with a cart, removing all previous ones.
|
391
|
+
* @param cartGuid The guid of the cart
|
392
|
+
* @param tariffIdToQuantity A map of tariff ids to the quantity of tickets to add for that tariff
|
393
|
+
*/
|
394
|
+
Booking.prototype.updateExtrasForCart = function (cartGuid, tariffIdToQuantity) {
|
395
|
+
return __awaiter(this, void 0, void 0, function () {
|
396
|
+
var body, url, res;
|
397
|
+
return __generator(this, function (_a) {
|
398
|
+
switch (_a.label) {
|
399
|
+
case 0:
|
400
|
+
body = {
|
401
|
+
cartGuid: cartGuid,
|
402
|
+
tariffIdToQuantity: tariffIdToQuantity
|
403
|
+
};
|
404
|
+
url = "".concat(this.config.API_ENDPOINT, "/v3_booking/extras");
|
405
|
+
return [4 /*yield*/, this.callPutApi(url, body)];
|
406
|
+
case 1:
|
407
|
+
res = _a.sent();
|
408
|
+
if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(res)) {
|
409
|
+
return [2 /*return*/, res];
|
410
|
+
}
|
411
|
+
return [4 /*yield*/, this.fetchAndSetCart(cartGuid)];
|
412
|
+
case 2:
|
413
|
+
_a.sent();
|
414
|
+
return [2 /*return*/, res];
|
415
|
+
}
|
416
|
+
});
|
417
|
+
});
|
418
|
+
};
|
353
419
|
return Booking;
|
354
420
|
}());
|
355
421
|
exports.Booking = Booking;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ExtraTariff } from "./Tariffs";
|
1
|
+
import { ExtraTariff, TariffsMatrix } from "./Tariffs";
|
2
2
|
/**
|
3
3
|
* @description this type represents an extra, which is an additional service that can be added to a cart. Extras are selected in the booking step `EXTRAS`.
|
4
4
|
*
|
@@ -18,3 +18,15 @@ export type Extra = {
|
|
18
18
|
notes: string;
|
19
19
|
tariff: ExtraTariff;
|
20
20
|
};
|
21
|
+
export type GetExtrasResponse = {
|
22
|
+
extras: {
|
23
|
+
id: number;
|
24
|
+
name: string;
|
25
|
+
description: string;
|
26
|
+
requiresNotes: boolean;
|
27
|
+
notes: string | null;
|
28
|
+
}[];
|
29
|
+
};
|
30
|
+
export type GetExtrasForBookingResponse = {
|
31
|
+
extraIdToTariffsMatrix: Record<number, TariffsMatrix>;
|
32
|
+
};
|
@@ -30,6 +30,8 @@ export type Tariff = {
|
|
30
30
|
chf: number | null;
|
31
31
|
id: number;
|
32
32
|
};
|
33
|
+
/** The user-friendly label of the tariff */
|
34
|
+
label: string;
|
33
35
|
/** The number of passengers to which this tariff applies */
|
34
36
|
quantity: number;
|
35
37
|
/** The custom code for one-way tickets */
|
package/lib/utils/apiCall.d.ts
CHANGED
@@ -8,4 +8,5 @@
|
|
8
8
|
import { ErrorResponse } from "../types/ErrorResponse";
|
9
9
|
export declare const makeGet: (url: string) => Promise<ErrorResponse | any>;
|
10
10
|
export declare const makePost: (url: string, data: any) => Promise<ErrorResponse | any>;
|
11
|
+
export declare const makePut: (url: string, data: any) => Promise<ErrorResponse | any>;
|
11
12
|
export declare const makeDelete: (url: string) => Promise<ErrorResponse | any>;
|
package/lib/utils/apiCall.js
CHANGED
@@ -54,7 +54,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
54
54
|
}
|
55
55
|
};
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
57
|
-
exports.makeDelete = exports.makePost = exports.makeGet = void 0;
|
57
|
+
exports.makeDelete = exports.makePut = exports.makePost = exports.makeGet = void 0;
|
58
58
|
var axios_1 = require("axios");
|
59
59
|
var config_1 = require("../config");
|
60
60
|
var utils_1 = require("./utils");
|
@@ -190,17 +190,17 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
190
190
|
});
|
191
191
|
}); };
|
192
192
|
exports.makePost = makePost;
|
193
|
-
var
|
193
|
+
var makePut = function (url, data) { return __awaiter(void 0, void 0, void 0, function () {
|
194
194
|
var debug, subKey, errorReport;
|
195
195
|
return __generator(this, function (_a) {
|
196
196
|
debug = (0, config_1.getConfig)().DEBUG;
|
197
197
|
if (debug) {
|
198
|
-
console.log("
|
198
|
+
console.log("PUT_RequestData", url, data);
|
199
199
|
}
|
200
200
|
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
201
201
|
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
202
202
|
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
203
|
-
throw new Error("MTS Library Error!
|
203
|
+
throw new Error("MTS Library Error! makePut: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
204
204
|
}
|
205
205
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
206
206
|
var response, filteredResponse, error_3, message, resError, resError;
|
@@ -209,14 +209,14 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
209
209
|
switch (_h.label) {
|
210
210
|
case 0:
|
211
211
|
_h.trys.push([0, 2, , 3]);
|
212
|
-
return [4 /*yield*/, axios_1.default.
|
212
|
+
return [4 /*yield*/, axios_1.default.put(url, data, {
|
213
213
|
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
214
214
|
})];
|
215
215
|
case 1:
|
216
216
|
response = _h.sent();
|
217
217
|
filteredResponse = removeNullError(response.data);
|
218
218
|
if (debug) {
|
219
|
-
console.log("
|
219
|
+
console.log("PUT_ResponseData", url, filteredResponse);
|
220
220
|
}
|
221
221
|
resolve(filteredResponse);
|
222
222
|
return [3 /*break*/, 3];
|
@@ -232,12 +232,73 @@ var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, funct
|
|
232
232
|
message: message || "Unknown error"
|
233
233
|
};
|
234
234
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
235
|
-
console.log("
|
235
|
+
console.log("PUT_ResponseAxiosError", url, resError);
|
236
236
|
}
|
237
237
|
reject(resError);
|
238
238
|
}
|
239
239
|
else {
|
240
240
|
resError = __assign(__assign({}, error_3), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
241
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
242
|
+
console.log("PUT_ResponseError", url, resError);
|
243
|
+
}
|
244
|
+
reject(resError);
|
245
|
+
}
|
246
|
+
return [3 /*break*/, 3];
|
247
|
+
case 3: return [2 /*return*/];
|
248
|
+
}
|
249
|
+
});
|
250
|
+
}); })];
|
251
|
+
});
|
252
|
+
}); };
|
253
|
+
exports.makePut = makePut;
|
254
|
+
var makeDelete = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
255
|
+
var debug, subKey, errorReport;
|
256
|
+
return __generator(this, function (_a) {
|
257
|
+
debug = (0, config_1.getConfig)().DEBUG;
|
258
|
+
if (debug) {
|
259
|
+
console.log("DELETE_RequestData", url);
|
260
|
+
}
|
261
|
+
subKey = (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY;
|
262
|
+
if ((0, utils_1.isNullOrWhiteSpace)(subKey)) {
|
263
|
+
errorReport = "Sub Key: ".concat(subKey, ", url: ").concat(url, ", access token: ").concat((0, config_1.getConfig)().ACCESS_TOKEN);
|
264
|
+
throw new Error("MTS Library Error! makeDelete: missing OCP SUBSCRIPTION KEY! ".concat(errorReport));
|
265
|
+
}
|
266
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
267
|
+
var response, filteredResponse, error_4, message, resError, resError;
|
268
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
269
|
+
return __generator(this, function (_h) {
|
270
|
+
switch (_h.label) {
|
271
|
+
case 0:
|
272
|
+
_h.trys.push([0, 2, , 3]);
|
273
|
+
return [4 /*yield*/, axios_1.default.delete(url, {
|
274
|
+
headers: __assign(__assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": subKey }, ((0, config_1.getConfig)().ACCESS_TOKEN && { Authorization: "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })), ((0, config_1.getConfig)().SESSION_ID && { SessionId: (0, config_1.getConfig)().SESSION_ID }))
|
275
|
+
})];
|
276
|
+
case 1:
|
277
|
+
response = _h.sent();
|
278
|
+
filteredResponse = removeNullError(response.data);
|
279
|
+
if (debug) {
|
280
|
+
console.log("DELETE_ResponseData", url, filteredResponse);
|
281
|
+
}
|
282
|
+
resolve(filteredResponse);
|
283
|
+
return [3 /*break*/, 3];
|
284
|
+
case 2:
|
285
|
+
error_4 = _h.sent();
|
286
|
+
if (axios_1.default.isAxiosError(error_4)) {
|
287
|
+
message = "error" in ((_a = error_4.response) === null || _a === void 0 ? void 0 : _a.data)
|
288
|
+
? (_b = error_4.response) === null || _b === void 0 ? void 0 : _b.data.error.message
|
289
|
+
: (_c = error_4.response) === null || _c === void 0 ? void 0 : _c.data.message;
|
290
|
+
resError = {
|
291
|
+
httpStatus: ((_d = error_4.response) === null || _d === void 0 ? void 0 : _d.status) || 0,
|
292
|
+
mtsCode: ((_g = (_f = (_e = error_4.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error) === null || _g === void 0 ? void 0 : _g.code) || 0,
|
293
|
+
message: message || "Unknown error"
|
294
|
+
};
|
295
|
+
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
296
|
+
console.log("DELETE_ResponseAxiosError", url, resError);
|
297
|
+
}
|
298
|
+
reject(resError);
|
299
|
+
}
|
300
|
+
else {
|
301
|
+
resError = __assign(__assign({}, error_4), { httpStatus: 0, mtsCode: 0, message: "Unknown error" });
|
241
302
|
if (debug || (0, config_1.getConfig)().ENV === config_1.MTSEnvs.TEST) {
|
242
303
|
console.log("DELETE_ResponseError", url, resError);
|
243
304
|
}
|
package/package.json
CHANGED
File without changes
|
@@ -1,148 +0,0 @@
|
|
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 and destinations
|
26
|
-
// const departures = await booking.getSubscriptionsDepartures() as string[];
|
27
|
-
// expect(departures.length).toBeGreaterThan(0);
|
28
|
-
// expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
|
29
|
-
// const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
|
30
|
-
// const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
|
31
|
-
// expect(destinations.length).toBeGreaterThan(0);
|
32
|
-
// expect(destinations).toContain("GARDA AUTOSTAZIONE");
|
33
|
-
// const selectedDestination = "GARDA AUTOSTAZIONE";
|
34
|
-
// // Then get the validity types
|
35
|
-
// const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
|
36
|
-
// expect(validityTypes.length).toBeGreaterThan(0);
|
37
|
-
// for (const validityType of validityTypes) {
|
38
|
-
// // Check that all returned validity types are valid
|
39
|
-
// expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
|
40
|
-
// }
|
41
|
-
// }, timeOut);
|
42
|
-
// const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
|
43
|
-
// const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
|
44
|
-
// const services = servicesResponse as Service[];
|
45
|
-
// // Build create cart request
|
46
|
-
// let tariffsMatrix = services[0].tariffsMatrix;
|
47
|
-
// tariffsMatrix[0][0].quantity = 1;
|
48
|
-
// const createServiceCartRequest: CreateServiceCartRequest = {
|
49
|
-
// currency: ServiceBooking.Currencies.EUR,
|
50
|
-
// service: {
|
51
|
-
// serviceId: services[0].id,
|
52
|
-
// tariffsMatrix: tariffsMatrix
|
53
|
-
// }
|
54
|
-
// };
|
55
|
-
// // Create cart
|
56
|
-
// const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
|
57
|
-
// return cart;
|
58
|
-
// }
|
59
|
-
// test("create_service_cart", async () => {
|
60
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
61
|
-
// const cart = await createCart(booking);
|
62
|
-
// // Check that the cartId was saved to the local storage
|
63
|
-
// expect(useTestState().getState().cartId).toBe(cart.id);
|
64
|
-
// expect(booking.cartId).toBe(cart.id);
|
65
|
-
// // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
|
66
|
-
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
|
67
|
-
// expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
|
68
|
-
// // Test booking due date
|
69
|
-
// expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
|
70
|
-
// // Test expired tickets
|
71
|
-
// expect(cart.hasIssuedTickets).toBe(false);
|
72
|
-
// // Test seller data
|
73
|
-
// expect(booking.getSellerId()).toBe(cart.sellerId);
|
74
|
-
// expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
|
75
|
-
// expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
|
76
|
-
// // Now try to get the cart
|
77
|
-
// const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
78
|
-
// expect(newBooking.cartId).toBe(cart.id);
|
79
|
-
// expect(newBooking.getCart()?.id).toBe(cart.id)
|
80
|
-
// expect(newBooking.getSellerId()).toBe(cart.sellerId);
|
81
|
-
// // Finally try to delete the cart
|
82
|
-
// await booking.deleteCart();
|
83
|
-
// expect(booking.getCart()).toBe(undefined);
|
84
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
85
|
-
// }, timeOut);
|
86
|
-
// test("get_edit_buyer_data", async () => {
|
87
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
88
|
-
// const cart = await createCart(booking);
|
89
|
-
// // First, try to get the buyer data
|
90
|
-
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
91
|
-
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
92
|
-
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
93
|
-
// expect(buyer).toBe(null);
|
94
|
-
// // Now try to edit the buyer data
|
95
|
-
// buyer = {
|
96
|
-
// id: 0,
|
97
|
-
// name: "TestName",
|
98
|
-
// lastName: "TestSurname",
|
99
|
-
// email: "testBookingLib@infos.it",
|
100
|
-
// phoneNumber: "+391234567890"
|
101
|
-
// }
|
102
|
-
// await booking.updateBuyerPassengersDetails(buyer);
|
103
|
-
// // Finally, get the buyer data again and check that the data was updated
|
104
|
-
// buyerDataResponse = await booking.getBuyerPassengersDetails();
|
105
|
-
// const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
106
|
-
// expect(updatedBuyer.id).toBeGreaterThan(0);
|
107
|
-
// expect(updatedBuyer.name).toBe(buyer.name);
|
108
|
-
// expect(updatedBuyer.lastName).toBe(buyer.lastName);
|
109
|
-
// expect(updatedBuyer.email).toBe(buyer.email);
|
110
|
-
// expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
|
111
|
-
// // Finally try to delete the cart
|
112
|
-
// await booking.deleteCart();
|
113
|
-
// expect(booking.getCart()).toBe(undefined);
|
114
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
115
|
-
// }, timeOut);
|
116
|
-
// test("get_gateway_info", async () => {
|
117
|
-
// const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
|
118
|
-
// const cart = await createCart(booking);
|
119
|
-
// booking.updateSellerId(cart.sellerId);
|
120
|
-
// // First, try to get the buyer data
|
121
|
-
// let buyerDataResponse = await booking.getBuyerPassengersDetails();
|
122
|
-
// expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
|
123
|
-
// let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
|
124
|
-
// expect(buyer).toBe(null);
|
125
|
-
// // Now try to edit the buyer data
|
126
|
-
// buyer = {
|
127
|
-
// id: 0,
|
128
|
-
// name: "TestName",
|
129
|
-
// lastName: "TestSurname",
|
130
|
-
// email: "testBookingLib@infos.it",
|
131
|
-
// phoneNumber: "+391234567890"
|
132
|
-
// }
|
133
|
-
// await booking.updateBuyerPassengersDetails(buyer);
|
134
|
-
// // Try to get the gateways
|
135
|
-
// const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
|
136
|
-
// if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
|
137
|
-
// throw new Error("No gateways found");
|
138
|
-
// }
|
139
|
-
// const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
|
140
|
-
// expect(gateway?.id).toBeGreaterThan(0);
|
141
|
-
// // Now try to get the info
|
142
|
-
// const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
|
143
|
-
// // Finally try to delete the cart
|
144
|
-
// await booking.deleteCart();
|
145
|
-
// expect(booking.getCart()).toBe(undefined);
|
146
|
-
// expect(useTestState().getState().cartId).toBe(undefined);
|
147
|
-
// }, timeOut);
|
148
|
-
// });
|
package/lib/utils/testUtils.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
3
|
-
* @param {Date | string} date the date to convert
|
4
|
-
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
5
|
-
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
6
|
-
* @returns {string} the ISO string
|
7
|
-
*/
|
8
|
-
export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
|
package/lib/utils/testUtils.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getISOStringWithoutGMT = void 0;
|
4
|
-
/**
|
5
|
-
* This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
|
6
|
-
* @param {Date | string} date the date to convert
|
7
|
-
* @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
|
8
|
-
* that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
|
9
|
-
* @returns {string} the ISO string
|
10
|
-
*/
|
11
|
-
var getISOStringWithoutGMT = function (date, removeTimezone) {
|
12
|
-
if (removeTimezone === void 0) { removeTimezone = true; }
|
13
|
-
if (!date)
|
14
|
-
return null;
|
15
|
-
var newDate = new Date(date);
|
16
|
-
var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
|
17
|
-
return removeTimezone ? isoString.slice(0, -1) : isoString;
|
18
|
-
};
|
19
|
-
exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
|