turf-common 1.4.2-beta.13 → 1.4.2-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/jest.config.js +2 -1
- package/build/src/models/booking-code-model.d.ts +2 -1
- package/build/src/models/booking-code-model.js +14 -31
- package/build/src/models/charge-model.d.ts +2 -0
- package/build/src/models/charge-model.js +20 -2
- package/build/src/utils/constant.d.ts +1 -1
- package/build/src/utils/constant.js +1 -1
- package/build/src/utils/date-util.d.ts +2 -1
- package/build/src/utils/date-util.js +7 -2
- package/build/tests/booking-code/method.spec.d.ts +1 -0
- package/build/tests/booking-code/method.spec.js +11 -0
- package/build/tests/unit/charges/discount-relative/basic.spec.d.ts +1 -0
- package/build/tests/unit/charges/discount-relative/basic.spec.js +209 -0
- package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.d.ts +1 -0
- package/build/tests/unit/charges/extension/basic.amount-fully-paid.spec.js +208 -0
- package/build/tests/unit/charges/extension/basic.spec.d.ts +1 -0
- package/build/tests/unit/charges/extension/basic.spec.js +209 -0
- package/package.json +2 -2
package/build/jest.config.js
CHANGED
|
@@ -45,7 +45,7 @@ export declare class BookingCode {
|
|
|
45
45
|
static getWeekday(dateCode: number): number;
|
|
46
46
|
static convertToDate(str: string): Date;
|
|
47
47
|
static previousDateChecker(fromDate: number, index: number, errorKey?: string): void;
|
|
48
|
-
static previousTimeChecker(fromTime: string, fromDate: number, index: number, bookingDelayInMinutes?: number): void;
|
|
48
|
+
static previousTimeChecker(fromTime: string, fromDate: number, index: number, bookingDelayInMinutes?: number, date?: Date): void;
|
|
49
49
|
static getDateCodesByWeek(fromDate: number, toDate: number, selectedWeekday: number): string[];
|
|
50
50
|
static getDatesByWeek(fromDate: number, toDate: number, selectedWeekday: number): Date[];
|
|
51
51
|
static isValidTimeRange(timeSlot: string): boolean;
|
|
@@ -141,4 +141,5 @@ export declare class BookingCode {
|
|
|
141
141
|
* Additionally, the pitch number and turf ID must match between the two codes.
|
|
142
142
|
*/
|
|
143
143
|
isAdjacentBookingCode(nextBookingCode: BookingCode): boolean;
|
|
144
|
+
static getInstanceByComponents(turfId: number, pitchCode: number, dateCode: number, fromTimeCode: string, toTimeCode: string, priceCsv: string): BookingCode;
|
|
144
145
|
}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.BookingCode = void 0;
|
|
15
4
|
var time_slot_model_1 = require("./time-slot-model");
|
|
@@ -233,27 +222,18 @@ var BookingCode = /** @class */ (function () {
|
|
|
233
222
|
}
|
|
234
223
|
};
|
|
235
224
|
//---------------------
|
|
236
|
-
BookingCode.previousTimeChecker = function (fromTime, fromDate, index, bookingDelayInMinutes) {
|
|
225
|
+
BookingCode.previousTimeChecker = function (fromTime, fromDate, index, bookingDelayInMinutes, date) {
|
|
237
226
|
if (bookingDelayInMinutes === void 0) { bookingDelayInMinutes = _utils_1.DEFAULT_BOOKING_DELAY_IN_MINUTES; }
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
};
|
|
249
|
-
var timeFormat = new Intl.DateTimeFormat("en-US", __assign(__assign({}, options), { hour: "2-digit", minute: "2-digit", hour12: false }));
|
|
250
|
-
var currentTimeObj = timeFormat.format(now).replace(/:/g, "");
|
|
251
|
-
if (fromTime < currentTimeObj) {
|
|
252
|
-
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
253
|
-
key: "slot.".concat(index),
|
|
254
|
-
message: ["Booking time should be in future"],
|
|
255
|
-
});
|
|
256
|
-
}
|
|
227
|
+
if (date === void 0) { date = date_util_1.dateUtilService.getIndianDate(); }
|
|
228
|
+
var now = date;
|
|
229
|
+
console.log("previousTimeChecker now", now);
|
|
230
|
+
var bookingDate = date_util_1.dateUtilService.convertStringToDate(fromDate.toString() + fromTime, "yyMMddHHmm");
|
|
231
|
+
var difference = bookingDate.getTime() - now.getTime() + bookingDelayInMinutes * 60 * 1000;
|
|
232
|
+
if (difference < 0) {
|
|
233
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
234
|
+
key: "slot.".concat(index),
|
|
235
|
+
message: ["Booking time should be in future"],
|
|
236
|
+
});
|
|
257
237
|
}
|
|
258
238
|
};
|
|
259
239
|
//---------------------
|
|
@@ -621,6 +601,9 @@ var BookingCode = /** @class */ (function () {
|
|
|
621
601
|
this.pitchNumber === nextBookingCode.pitchNumber &&
|
|
622
602
|
this.turfId === nextBookingCode.turfId);
|
|
623
603
|
};
|
|
604
|
+
BookingCode.getInstanceByComponents = function (turfId, pitchCode, dateCode, fromTimeCode, toTimeCode, priceCsv) {
|
|
605
|
+
return new BookingCode("".concat(turfId.toString().padStart(4, "0")).concat(dateCode.toString().padStart(6, "0")).concat(fromTimeCode).concat(toTimeCode).concat(pitchCode.toString().padStart(2, "0")), priceCsv);
|
|
606
|
+
};
|
|
624
607
|
/**
|
|
625
608
|
* Extracts the numeric part of a bookingCode, excluding a predefined deleted slot separator.
|
|
626
609
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BookingCode } from "./booking-code-model";
|
|
1
2
|
import { IBookingModification } from "../types/booking-modification.type";
|
|
2
3
|
import { ModificationDiscountPolicy } from "../enums/modification-discount-policy.enum";
|
|
3
4
|
import { IChargeModel } from "../interface/model/charge-model.interface";
|
|
@@ -27,6 +28,7 @@ export declare class ChargesModel implements IChargeModel {
|
|
|
27
28
|
private modifyMove;
|
|
28
29
|
clone(): ChargesModel;
|
|
29
30
|
private modifyDelete;
|
|
31
|
+
extension(extensionBookingCode: BookingCode): ChargesModel;
|
|
30
32
|
static getInstance(chargeData: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
31
33
|
getTotalAmount(): number;
|
|
32
34
|
getPaymentStatus(): "Refund" | "Paid" | "Pending";
|
|
@@ -25,6 +25,7 @@ var ChargesModel = /** @class */ (function () {
|
|
|
25
25
|
this.cancelledBookingGrossAmount);
|
|
26
26
|
};
|
|
27
27
|
ChargesModel.prototype.getNetAmount = function () {
|
|
28
|
+
// console.log("getNetAmount", this.getGrossAmount(), this.getDiscountAmount());
|
|
28
29
|
return this.getGrossAmount() - this.getDiscountAmount();
|
|
29
30
|
};
|
|
30
31
|
ChargesModel.prototype.getDiscountAmount = function () {
|
|
@@ -35,6 +36,7 @@ var ChargesModel = /** @class */ (function () {
|
|
|
35
36
|
this.cancelledBookingGrossAmount > 0) {
|
|
36
37
|
this.couponCode = "";
|
|
37
38
|
}
|
|
39
|
+
// console.log("getDiscountAmount", this.couponCode);
|
|
38
40
|
return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount(), false, this.totalBookingHours);
|
|
39
41
|
};
|
|
40
42
|
ChargesModel.prototype.getPayableRefundAmount = function () {
|
|
@@ -150,7 +152,6 @@ var ChargesModel = /** @class */ (function () {
|
|
|
150
152
|
(newBookingCode ? newBookingCode.getTotalTime("hr") : 0);
|
|
151
153
|
var newChargeModel = this.clone();
|
|
152
154
|
newChargeModel.totalBookingHours = newTotalBookingHours;
|
|
153
|
-
newChargeModel.couponCode = "";
|
|
154
155
|
var costDifference = oldBookingCode.getCost() - newBookingCode.getCost();
|
|
155
156
|
// console.log(`costDifference ${costDifference}`);
|
|
156
157
|
newChargeModel.cancelledBookingGrossAmount += costDifference;
|
|
@@ -208,7 +209,6 @@ var ChargesModel = /** @class */ (function () {
|
|
|
208
209
|
var newTotalBookingHours = this.totalBookingHours - bookingCode.getTotalTime("hr");
|
|
209
210
|
var newChargeModel = this.clone();
|
|
210
211
|
newChargeModel.totalBookingHours = newTotalBookingHours;
|
|
211
|
-
newChargeModel.couponCode = "";
|
|
212
212
|
var costDifference = bookingCode.getCost();
|
|
213
213
|
newChargeModel.cancelledBookingGrossAmount += costDifference;
|
|
214
214
|
var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, costDifference);
|
|
@@ -224,6 +224,24 @@ var ChargesModel = /** @class */ (function () {
|
|
|
224
224
|
}
|
|
225
225
|
return newChargeModel;
|
|
226
226
|
};
|
|
227
|
+
ChargesModel.prototype.extension = function (extensionBookingCode) {
|
|
228
|
+
var newTotalBookingHours = this.totalBookingHours +
|
|
229
|
+
(extensionBookingCode ? extensionBookingCode.getTotalTime("hr") : 0);
|
|
230
|
+
var newChargeModel = this.clone();
|
|
231
|
+
newChargeModel.totalBookingHours = newTotalBookingHours;
|
|
232
|
+
newChargeModel.additionalBookingGrossAmount += extensionBookingCode.getCost();
|
|
233
|
+
newChargeModel.netTotal = newChargeModel.getNetAmount();
|
|
234
|
+
newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
|
|
235
|
+
// console.log(newChargeModel.payableAmount);
|
|
236
|
+
if (newChargeModel.amountPayable > 0) {
|
|
237
|
+
newChargeModel.refundPayable = 0;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
|
|
241
|
+
newChargeModel.amountPayable = 0;
|
|
242
|
+
}
|
|
243
|
+
return newChargeModel;
|
|
244
|
+
};
|
|
227
245
|
ChargesModel.getInstance = function (chargeData, discountPolicy) {
|
|
228
246
|
if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
|
|
229
247
|
var chargesModel = new ChargesModel(chargeData.initialBookingGrossAmount, chargeData.amountPaid, chargeData.couponCode, chargeData.totalBookingHours, discountPolicy);
|
|
@@ -3,4 +3,4 @@ export declare const DEFAULT_PASSWORD = "turf@#123";
|
|
|
3
3
|
export declare const DELETED_SLOT_SEPARATOR = "d_";
|
|
4
4
|
export declare const START_OF_DAY_TIME_CODE = "0000";
|
|
5
5
|
export declare const END_OF_DAY_TIME_CODE = "2400";
|
|
6
|
-
export declare const DEFAULT_BOOKING_DELAY_IN_MINUTES =
|
|
6
|
+
export declare const DEFAULT_BOOKING_DELAY_IN_MINUTES = 60;
|
|
@@ -5,7 +5,8 @@ export declare class DateUtilService {
|
|
|
5
5
|
getNDaysCode(n: number): string;
|
|
6
6
|
getDateCode(date: Date): string;
|
|
7
7
|
addNDaysToDate(date: Date, n: number): Date;
|
|
8
|
-
convertStringToDate(dateString: string, format: string): Date;
|
|
8
|
+
convertStringToDate(dateString: string, format: string, offset?: number): Date;
|
|
9
|
+
getIndianDate(date?: Date): Date;
|
|
9
10
|
isInPast(date: Date): boolean;
|
|
10
11
|
getDateFromDatabaseDate: (date: string) => Date;
|
|
11
12
|
noOfDaysBetweenDates: (date1: Date, date2: Date) => number;
|
|
@@ -31,12 +31,17 @@ var DateUtilService = /** @class */ (function () {
|
|
|
31
31
|
DateUtilService.prototype.addNDaysToDate = function (date, n) {
|
|
32
32
|
return (0, date_fns_1.add)(date, { days: n });
|
|
33
33
|
};
|
|
34
|
-
DateUtilService.prototype.convertStringToDate = function (dateString, format) {
|
|
34
|
+
DateUtilService.prototype.convertStringToDate = function (dateString, format, offset) {
|
|
35
|
+
if (offset === void 0) { offset = 330 * 60 * 1000; }
|
|
35
36
|
var parsedDate = (0, date_fns_1.parse)(dateString, format, new Date());
|
|
36
37
|
// IST has a fixed offset of UTC+5:30
|
|
37
|
-
var indianDate = new Date(parsedDate.getTime() +
|
|
38
|
+
var indianDate = new Date(parsedDate.getTime() + offset);
|
|
38
39
|
return indianDate;
|
|
39
40
|
};
|
|
41
|
+
DateUtilService.prototype.getIndianDate = function (date) {
|
|
42
|
+
if (date === void 0) { date = new Date(); }
|
|
43
|
+
return new Date(date.getTime() + 330 * 60 * 1000);
|
|
44
|
+
};
|
|
40
45
|
DateUtilService.prototype.isInPast = function (date) {
|
|
41
46
|
return date < new Date();
|
|
42
47
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// 001005_0P_1,006010_2P_1,011999_5P_1
|
|
3
|
+
// 000001_0P_Monthly,000003_5P_Quarterly,000006_7P_Half-Yearly,000012_10P_Yearly
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
// 1_5#1#1#0P,1_5#3#0.95#5P,1_5#6#0.93#7P,1_5#12#0.9#10P,6_10#1#0.98#2P,6_10#3#0.931#6.9P,6_10#6#0.9114#8.86P,6_10#12#0.882#11.8P,11_99#1#0.95#5P,11_99#3#0.9025#9.75P,11_99#6#0.8835#11.65P,11_99#12#0.855#14.5P
|
|
6
|
+
describe("AppController (e2e)", function () {
|
|
7
|
+
it("Method Testing ", function () {
|
|
8
|
+
// BookingCode.previousTimeChecker("2115",240428, 0, 45);
|
|
9
|
+
// BookingCode.previousTimeChecker("2109",240428, 0, 51);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _enum_1 = require("../../../../@enum");
|
|
4
|
+
var _model_1 = require("../../../../src/@model");
|
|
5
|
+
var booking_entity_test_1 = require("../../../utils/models/booking-entity-test");
|
|
6
|
+
describe("AppController (e2e)", function () {
|
|
7
|
+
var initialBookingCode1 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230813, '1000', '1200', '500,500,500,500');
|
|
8
|
+
var initialBookingCode2 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1100', '500,500');
|
|
9
|
+
var modify1ExtendBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1200', '500,500,500,500');
|
|
10
|
+
var modify2ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1200', '1230', '500');
|
|
11
|
+
var modify3ReduceOldBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1230', '500,500,500,500,500');
|
|
12
|
+
var modify3ReduceNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1100', '500,500');
|
|
13
|
+
var modify4ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1000', '500,500');
|
|
14
|
+
var modify5DeleteNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1100', '500,500,500,500');
|
|
15
|
+
var bookingCodes = [
|
|
16
|
+
initialBookingCode1, initialBookingCode2
|
|
17
|
+
];
|
|
18
|
+
var initialGrossAmount = bookingCodes
|
|
19
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
20
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
21
|
+
var totalBookingHours = booking_entity_test_1.BookingEntityTest.getTotalHours(bookingCodes);
|
|
22
|
+
var chargeModel = new _model_1.ChargesModel(initialGrossAmount, 0, "", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL);
|
|
23
|
+
var currentChargeModel = chargeModel;
|
|
24
|
+
it("create", function () {
|
|
25
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
26
|
+
var expectedAdditionalBookingGrossAmount = 0;
|
|
27
|
+
var expectedCancellationGrossAmount = 0;
|
|
28
|
+
var expectedTotalCancellationCharges = 0;
|
|
29
|
+
var expectedRefundPayable = 0;
|
|
30
|
+
var expectedNetTotal = 2700;
|
|
31
|
+
var expectedAmountPaid = 0;
|
|
32
|
+
var expectedAmountPayable = 2700;
|
|
33
|
+
var expectedTotalRefundedAmount = 0;
|
|
34
|
+
var expectedCouponCode = "100PHU";
|
|
35
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
36
|
+
var initialGrossAmount = bookingCodes
|
|
37
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
38
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
39
|
+
chargeModel = new _model_1.ChargesModel(initialGrossAmount, 0, "100PHU", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE);
|
|
40
|
+
currentChargeModel = chargeModel;
|
|
41
|
+
expect(chargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
42
|
+
expect(chargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
43
|
+
expect(chargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
44
|
+
expect(chargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
45
|
+
expect(chargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
46
|
+
expect(chargeModel.netTotal).toEqual(expectedNetTotal);
|
|
47
|
+
expect(chargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
48
|
+
expect(chargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
49
|
+
expect(chargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
50
|
+
expect(chargeModel.couponCode).toEqual(expectedCouponCode);
|
|
51
|
+
expect(chargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
52
|
+
});
|
|
53
|
+
it("1. modify extend", function () {
|
|
54
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
55
|
+
var expectedAdditionalBookingGrossAmount = 1000;
|
|
56
|
+
var expectedCancellationGrossAmount = 0;
|
|
57
|
+
var expectedTotalCancellationCharges = 0;
|
|
58
|
+
var expectedRefundPayable = 0;
|
|
59
|
+
var expectedNetTotal = 3600;
|
|
60
|
+
var expectedAmountPaid = 0;
|
|
61
|
+
var expectedAmountPayable = 3600;
|
|
62
|
+
var expectedTotalRefundedAmount = 0;
|
|
63
|
+
var expectedCouponCode = "100PHU";
|
|
64
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
65
|
+
if (currentChargeModel)
|
|
66
|
+
currentChargeModel = currentChargeModel.modify({
|
|
67
|
+
oldBookingCode: initialBookingCode2,
|
|
68
|
+
newBookingCode: modify1ExtendBookingCode,
|
|
69
|
+
});
|
|
70
|
+
expect(currentChargeModel).not.toBeNull();
|
|
71
|
+
if (currentChargeModel) {
|
|
72
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
73
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
74
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
75
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
76
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
77
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
78
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
79
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
80
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
81
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
82
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
it("2. extension", function () {
|
|
86
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
87
|
+
var expectedAdditionalBookingGrossAmount = 1000 + 500;
|
|
88
|
+
var expectedCancellationGrossAmount = 0;
|
|
89
|
+
var expectedTotalCancellationCharges = 0;
|
|
90
|
+
var expectedRefundPayable = 0;
|
|
91
|
+
var expectedNetTotal = 3600 + 450;
|
|
92
|
+
var expectedAmountPaid = 0;
|
|
93
|
+
var expectedAmountPayable = 3600 + 450;
|
|
94
|
+
var expectedTotalRefundedAmount = 0;
|
|
95
|
+
var expectedCouponCode = "100PHU";
|
|
96
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
97
|
+
if (currentChargeModel)
|
|
98
|
+
currentChargeModel = currentChargeModel.extension(modify2ExtensionBookingCode);
|
|
99
|
+
expect(currentChargeModel).not.toBeNull();
|
|
100
|
+
if (currentChargeModel) {
|
|
101
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
102
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
103
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
104
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
105
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
106
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
107
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
108
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
109
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
110
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
111
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it("3. modify reduce", function () {
|
|
115
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
116
|
+
var expectedAdditionalBookingGrossAmount = 1500;
|
|
117
|
+
var expectedCancellationGrossAmount = 0 + 1500;
|
|
118
|
+
var expectedTotalCancellationCharges = 0 + 100;
|
|
119
|
+
var expectedRefundPayable = 0;
|
|
120
|
+
var expectedNetTotal = 4050 - 1500 + 150;
|
|
121
|
+
var expectedAmountPaid = 0;
|
|
122
|
+
var expectedAmountPayable = 4050 - 1500 + 150 + 100;
|
|
123
|
+
var expectedTotalRefundedAmount = 0;
|
|
124
|
+
var expectedCouponCode = "100PHU";
|
|
125
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
126
|
+
if (currentChargeModel)
|
|
127
|
+
currentChargeModel = currentChargeModel.modify({
|
|
128
|
+
oldBookingCode: modify3ReduceOldBookingCode,
|
|
129
|
+
newBookingCode: modify3ReduceNewBookingCode,
|
|
130
|
+
cancellationUnit: "100U",
|
|
131
|
+
});
|
|
132
|
+
expect(currentChargeModel).not.toBeNull();
|
|
133
|
+
if (currentChargeModel) {
|
|
134
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
135
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
136
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
137
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
138
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
139
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
140
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
141
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
142
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
143
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
144
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
it("4. extension", function () {
|
|
148
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
149
|
+
var expectedAdditionalBookingGrossAmount = 1500 + 1000;
|
|
150
|
+
var expectedCancellationGrossAmount = 1500;
|
|
151
|
+
var expectedTotalCancellationCharges = 100;
|
|
152
|
+
var expectedRefundPayable = 0;
|
|
153
|
+
var expectedNetTotal = 2700 + 900;
|
|
154
|
+
var expectedAmountPaid = 0;
|
|
155
|
+
var expectedAmountPayable = 2800 + 900;
|
|
156
|
+
var expectedTotalRefundedAmount = 0;
|
|
157
|
+
var expectedCouponCode = "100PHU";
|
|
158
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
159
|
+
if (currentChargeModel)
|
|
160
|
+
currentChargeModel = currentChargeModel.extension(modify4ExtensionBookingCode);
|
|
161
|
+
expect(currentChargeModel).not.toBeNull();
|
|
162
|
+
if (currentChargeModel) {
|
|
163
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
164
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
165
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
166
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
167
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
168
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
169
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
170
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
171
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
172
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
173
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
it("5. delete", function () {
|
|
177
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
178
|
+
var expectedAdditionalBookingGrossAmount = 2500;
|
|
179
|
+
var expectedCancellationGrossAmount = 1500 + 2000;
|
|
180
|
+
var expectedTotalCancellationCharges = 100 + 100;
|
|
181
|
+
var expectedRefundPayable = 0;
|
|
182
|
+
var expectedNetTotal = 3600 - 2000 + 200;
|
|
183
|
+
var expectedAmountPaid = 0;
|
|
184
|
+
var expectedAmountPayable = 3700 - 2000 + 200 + 100;
|
|
185
|
+
var expectedTotalRefundedAmount = 0;
|
|
186
|
+
var expectedCouponCode = "100PHU";
|
|
187
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_RELATIVE;
|
|
188
|
+
if (currentChargeModel) {
|
|
189
|
+
currentChargeModel = currentChargeModel.modify({
|
|
190
|
+
oldBookingCode: modify5DeleteNewBookingCode,
|
|
191
|
+
cancellationUnit: "100U",
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
expect(currentChargeModel).not.toBeNull();
|
|
195
|
+
if (currentChargeModel) {
|
|
196
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
197
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
198
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
199
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
200
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
201
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
202
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
203
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
204
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
205
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
206
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _enum_1 = require("../../../../@enum");
|
|
4
|
+
var _model_1 = require("../../../../src/@model");
|
|
5
|
+
var booking_entity_test_1 = require("../../../utils/models/booking-entity-test");
|
|
6
|
+
describe("AppController (e2e)", function () {
|
|
7
|
+
var initialBookingCode1 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230813, '1000', '1200', '500,500,500,500');
|
|
8
|
+
var initialBookingCode2 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1100', '500,500');
|
|
9
|
+
var modify1ExtendBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1200', '500,500,500,500');
|
|
10
|
+
var modify2ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1200', '1230', '500');
|
|
11
|
+
var modify3ReduceOldBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1230', '500,500,500,500,500');
|
|
12
|
+
var modify3ReduceNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1100', '500,500');
|
|
13
|
+
var modify4ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1000', '500,500');
|
|
14
|
+
var modify5DeleteNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1100', '500,500,500,500');
|
|
15
|
+
var bookingCodes = [
|
|
16
|
+
initialBookingCode1, initialBookingCode2
|
|
17
|
+
];
|
|
18
|
+
var initialGrossAmount = bookingCodes
|
|
19
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
20
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
21
|
+
var totalBookingHours = booking_entity_test_1.BookingEntityTest.getTotalHours(bookingCodes);
|
|
22
|
+
var chargeModel = new _model_1.ChargesModel(initialGrossAmount, 0, "", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL);
|
|
23
|
+
var currentChargeModel = chargeModel;
|
|
24
|
+
it("create", function () {
|
|
25
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
26
|
+
var expectedAdditionalBookingGrossAmount = 0;
|
|
27
|
+
var expectedCancellationGrossAmount = 0;
|
|
28
|
+
var expectedTotalCancellationCharges = 0;
|
|
29
|
+
var expectedRefundPayable = 0;
|
|
30
|
+
var expectedNetTotal = 2700;
|
|
31
|
+
var expectedAmountPaid = 2700;
|
|
32
|
+
var expectedAmountPayable = 0;
|
|
33
|
+
var expectedTotalRefundedAmount = 0;
|
|
34
|
+
var expectedCouponCode = "100PHU";
|
|
35
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
36
|
+
var initialGrossAmount = bookingCodes
|
|
37
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
38
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
39
|
+
chargeModel = new _model_1.ChargesModel(initialGrossAmount, 2700, "100PHU", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL);
|
|
40
|
+
currentChargeModel = chargeModel;
|
|
41
|
+
expect(chargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
42
|
+
expect(chargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
43
|
+
expect(chargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
44
|
+
expect(chargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
45
|
+
expect(chargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
46
|
+
expect(chargeModel.netTotal).toEqual(expectedNetTotal);
|
|
47
|
+
expect(chargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
48
|
+
expect(chargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
49
|
+
expect(chargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
50
|
+
expect(chargeModel.couponCode).toEqual(expectedCouponCode);
|
|
51
|
+
expect(chargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
52
|
+
});
|
|
53
|
+
it("1. modify extend", function () {
|
|
54
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
55
|
+
var expectedAdditionalBookingGrossAmount = 1000;
|
|
56
|
+
var expectedCancellationGrossAmount = 0;
|
|
57
|
+
var expectedTotalCancellationCharges = 0;
|
|
58
|
+
var expectedRefundPayable = 0;
|
|
59
|
+
var expectedNetTotal = 2700 + 900;
|
|
60
|
+
var expectedAmountPaid = 2700;
|
|
61
|
+
var expectedAmountPayable = 0 + 900;
|
|
62
|
+
var expectedTotalRefundedAmount = 0;
|
|
63
|
+
var expectedCouponCode = "100PHU";
|
|
64
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
65
|
+
if (currentChargeModel)
|
|
66
|
+
currentChargeModel = currentChargeModel.modify({
|
|
67
|
+
oldBookingCode: initialBookingCode2,
|
|
68
|
+
newBookingCode: modify1ExtendBookingCode,
|
|
69
|
+
});
|
|
70
|
+
expect(currentChargeModel).not.toBeNull();
|
|
71
|
+
if (currentChargeModel) {
|
|
72
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
73
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
74
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
75
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
76
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
77
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
78
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
79
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
80
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
81
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
82
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
it("2. extension", function () {
|
|
86
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
87
|
+
var expectedAdditionalBookingGrossAmount = 1000 + 500;
|
|
88
|
+
var expectedCancellationGrossAmount = 0;
|
|
89
|
+
var expectedTotalCancellationCharges = 0;
|
|
90
|
+
var expectedRefundPayable = 0;
|
|
91
|
+
var expectedNetTotal = 3600 + 450;
|
|
92
|
+
var expectedAmountPaid = 2700;
|
|
93
|
+
var expectedAmountPayable = 900 + 450;
|
|
94
|
+
var expectedTotalRefundedAmount = 0;
|
|
95
|
+
var expectedCouponCode = "100PHU";
|
|
96
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
97
|
+
if (currentChargeModel)
|
|
98
|
+
currentChargeModel = currentChargeModel.extension(modify2ExtensionBookingCode);
|
|
99
|
+
expect(currentChargeModel).not.toBeNull();
|
|
100
|
+
if (currentChargeModel) {
|
|
101
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
102
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
103
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
104
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
105
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
106
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
107
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
108
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
109
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
110
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
111
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it("3. modify reduce", function () {
|
|
115
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
116
|
+
var expectedAdditionalBookingGrossAmount = 1500;
|
|
117
|
+
var expectedCancellationGrossAmount = 0 + 1500;
|
|
118
|
+
var expectedTotalCancellationCharges = 0 + 100;
|
|
119
|
+
var expectedNetTotal = 4050 - 1500 + 450;
|
|
120
|
+
var expectedAmountPaid = 2700;
|
|
121
|
+
var expectedAmountPayable = 1350 + 450 + 100 - 1500;
|
|
122
|
+
var expectedRefundPayable = 0;
|
|
123
|
+
var expectedTotalRefundedAmount = 0;
|
|
124
|
+
var expectedCouponCode = "";
|
|
125
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
126
|
+
if (currentChargeModel)
|
|
127
|
+
currentChargeModel = currentChargeModel.modify({
|
|
128
|
+
oldBookingCode: modify3ReduceOldBookingCode,
|
|
129
|
+
newBookingCode: modify3ReduceNewBookingCode,
|
|
130
|
+
cancellationUnit: "100U",
|
|
131
|
+
});
|
|
132
|
+
expect(currentChargeModel).not.toBeNull();
|
|
133
|
+
if (currentChargeModel) {
|
|
134
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
135
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
136
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
137
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
138
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
139
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
140
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
141
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
142
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
143
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
144
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
it("4. extension", function () {
|
|
148
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
149
|
+
var expectedAdditionalBookingGrossAmount = 1500 + 1000;
|
|
150
|
+
var expectedCancellationGrossAmount = 1500;
|
|
151
|
+
var expectedTotalCancellationCharges = 100;
|
|
152
|
+
var expectedNetTotal = 3000 + 1000;
|
|
153
|
+
var expectedAmountPaid = 2700;
|
|
154
|
+
var expectedAmountPayable = 400 + 1000;
|
|
155
|
+
var expectedRefundPayable = 0;
|
|
156
|
+
var expectedTotalRefundedAmount = 0;
|
|
157
|
+
var expectedCouponCode = "";
|
|
158
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
159
|
+
if (currentChargeModel)
|
|
160
|
+
currentChargeModel = currentChargeModel.extension(modify4ExtensionBookingCode);
|
|
161
|
+
expect(currentChargeModel).not.toBeNull();
|
|
162
|
+
if (currentChargeModel) {
|
|
163
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
164
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
165
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
166
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
167
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
168
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
169
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
170
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
171
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
172
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
173
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
it("5. delete", function () {
|
|
177
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
178
|
+
var expectedAdditionalBookingGrossAmount = 2500;
|
|
179
|
+
var expectedCancellationGrossAmount = 1500 + 2000;
|
|
180
|
+
var expectedTotalCancellationCharges = 100 + 100;
|
|
181
|
+
var expectedNetTotal = 4000 - 2000;
|
|
182
|
+
var expectedAmountPaid = 2700;
|
|
183
|
+
var expectedAmountPayable = 1400 - 2000 + 100 < 0 ? 0 : 1400 - 2000 + 100;
|
|
184
|
+
var expectedRefundPayable = 1400 - 2000 + 100 < 0 ? Math.abs(1400 - 2000 + 100) : 0;
|
|
185
|
+
var expectedTotalRefundedAmount = 0;
|
|
186
|
+
var expectedCouponCode = "";
|
|
187
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
188
|
+
if (currentChargeModel)
|
|
189
|
+
currentChargeModel = currentChargeModel.modify({
|
|
190
|
+
oldBookingCode: modify5DeleteNewBookingCode,
|
|
191
|
+
cancellationUnit: "100U",
|
|
192
|
+
});
|
|
193
|
+
expect(currentChargeModel).not.toBeNull();
|
|
194
|
+
if (currentChargeModel) {
|
|
195
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
196
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
197
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
198
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
199
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
200
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
201
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
202
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
203
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
204
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
205
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _enum_1 = require("../../../../@enum");
|
|
4
|
+
var _model_1 = require("../../../../src/@model");
|
|
5
|
+
var booking_entity_test_1 = require("../../../utils/models/booking-entity-test");
|
|
6
|
+
describe("AppController (e2e)", function () {
|
|
7
|
+
var initialBookingCode1 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230813, '1000', '1200', '500,500,500,500');
|
|
8
|
+
var initialBookingCode2 = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1100', '500,500');
|
|
9
|
+
var modify1ExtendBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 1, 230814, '1000', '1200', '500,500,500,500');
|
|
10
|
+
var modify2ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1200', '1230', '500');
|
|
11
|
+
var modify3ReduceOldBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1230', '500,500,500,500,500');
|
|
12
|
+
var modify3ReduceNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '1000', '1100', '500,500');
|
|
13
|
+
var modify4ExtensionBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1000', '500,500');
|
|
14
|
+
var modify5DeleteNewBookingCode = _model_1.BookingCode.getInstanceByComponents(1, 2, 230814, '0900', '1100', '500,500,500,500');
|
|
15
|
+
var bookingCodes = [
|
|
16
|
+
initialBookingCode1, initialBookingCode2
|
|
17
|
+
];
|
|
18
|
+
var initialGrossAmount = bookingCodes
|
|
19
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
20
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
21
|
+
var totalBookingHours = booking_entity_test_1.BookingEntityTest.getTotalHours(bookingCodes);
|
|
22
|
+
var chargeModel = new _model_1.ChargesModel(initialGrossAmount, 0, "", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL);
|
|
23
|
+
var currentChargeModel = chargeModel;
|
|
24
|
+
it("create", function () {
|
|
25
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
26
|
+
var expectedAdditionalBookingGrossAmount = 0;
|
|
27
|
+
var expectedCancellationGrossAmount = 0;
|
|
28
|
+
var expectedTotalCancellationCharges = 0;
|
|
29
|
+
var expectedRefundPayable = 0;
|
|
30
|
+
var expectedNetTotal = 2700;
|
|
31
|
+
var expectedAmountPaid = 0;
|
|
32
|
+
var expectedAmountPayable = 2700;
|
|
33
|
+
var expectedTotalRefundedAmount = 0;
|
|
34
|
+
var expectedCouponCode = "100PHU";
|
|
35
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
36
|
+
var initialGrossAmount = bookingCodes
|
|
37
|
+
.map(function (bookingCode) { return bookingCode.getCost(); })
|
|
38
|
+
.reduce(function (a, b) { return a + b; }, 0);
|
|
39
|
+
chargeModel = new _model_1.ChargesModel(initialGrossAmount, 0, "100PHU", totalBookingHours, _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL);
|
|
40
|
+
currentChargeModel = chargeModel;
|
|
41
|
+
expect(chargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
42
|
+
expect(chargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
43
|
+
expect(chargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
44
|
+
expect(chargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
45
|
+
expect(chargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
46
|
+
expect(chargeModel.netTotal).toEqual(expectedNetTotal);
|
|
47
|
+
expect(chargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
48
|
+
expect(chargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
49
|
+
expect(chargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
50
|
+
expect(chargeModel.couponCode).toEqual(expectedCouponCode);
|
|
51
|
+
expect(chargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
52
|
+
});
|
|
53
|
+
it("1. modify extend", function () {
|
|
54
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
55
|
+
var expectedAdditionalBookingGrossAmount = 1000;
|
|
56
|
+
var expectedCancellationGrossAmount = 0;
|
|
57
|
+
var expectedTotalCancellationCharges = 0;
|
|
58
|
+
var expectedRefundPayable = 0;
|
|
59
|
+
var expectedNetTotal = 3600;
|
|
60
|
+
var expectedAmountPaid = 0;
|
|
61
|
+
var expectedAmountPayable = 3600;
|
|
62
|
+
var expectedTotalRefundedAmount = 0;
|
|
63
|
+
var expectedCouponCode = "100PHU";
|
|
64
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
65
|
+
if (currentChargeModel)
|
|
66
|
+
currentChargeModel = currentChargeModel.modify({
|
|
67
|
+
oldBookingCode: initialBookingCode2,
|
|
68
|
+
newBookingCode: modify1ExtendBookingCode,
|
|
69
|
+
});
|
|
70
|
+
expect(currentChargeModel).not.toBeNull();
|
|
71
|
+
if (currentChargeModel) {
|
|
72
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
73
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
74
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
75
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
76
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
77
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
78
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
79
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
80
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
81
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
82
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
it("2. extension", function () {
|
|
86
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
87
|
+
var expectedAdditionalBookingGrossAmount = 1000 + 500;
|
|
88
|
+
var expectedCancellationGrossAmount = 0;
|
|
89
|
+
var expectedTotalCancellationCharges = 0;
|
|
90
|
+
var expectedRefundPayable = 0;
|
|
91
|
+
var expectedNetTotal = 3600 + 450;
|
|
92
|
+
var expectedAmountPaid = 0;
|
|
93
|
+
var expectedAmountPayable = 3600 + 450;
|
|
94
|
+
var expectedTotalRefundedAmount = 0;
|
|
95
|
+
var expectedCouponCode = "100PHU";
|
|
96
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
97
|
+
if (currentChargeModel)
|
|
98
|
+
currentChargeModel = currentChargeModel.extension(modify2ExtensionBookingCode);
|
|
99
|
+
expect(currentChargeModel).not.toBeNull();
|
|
100
|
+
if (currentChargeModel) {
|
|
101
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
102
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
103
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
104
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
105
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
106
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
107
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
108
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
109
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
110
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
111
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it("3. modify reduce", function () {
|
|
115
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
116
|
+
var expectedAdditionalBookingGrossAmount = 1500;
|
|
117
|
+
var expectedCancellationGrossAmount = 0 + 1500;
|
|
118
|
+
var expectedTotalCancellationCharges = 0 + 100;
|
|
119
|
+
var expectedRefundPayable = 0;
|
|
120
|
+
var expectedNetTotal = 3000;
|
|
121
|
+
var expectedAmountPaid = 0;
|
|
122
|
+
var expectedAmountPayable = 3000 + 100;
|
|
123
|
+
var expectedTotalRefundedAmount = 0;
|
|
124
|
+
var expectedCouponCode = "";
|
|
125
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
126
|
+
if (currentChargeModel)
|
|
127
|
+
currentChargeModel = currentChargeModel.modify({
|
|
128
|
+
oldBookingCode: modify3ReduceOldBookingCode,
|
|
129
|
+
newBookingCode: modify3ReduceNewBookingCode,
|
|
130
|
+
cancellationUnit: "100U",
|
|
131
|
+
});
|
|
132
|
+
expect(currentChargeModel).not.toBeNull();
|
|
133
|
+
if (currentChargeModel) {
|
|
134
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
135
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
136
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
137
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
138
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
139
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
140
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
141
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
142
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
143
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
144
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
it("4. extension", function () {
|
|
148
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
149
|
+
var expectedAdditionalBookingGrossAmount = 1500 + 1000;
|
|
150
|
+
var expectedCancellationGrossAmount = 1500;
|
|
151
|
+
var expectedTotalCancellationCharges = 100;
|
|
152
|
+
var expectedRefundPayable = 0;
|
|
153
|
+
var expectedNetTotal = 3000 + 1000;
|
|
154
|
+
var expectedAmountPaid = 0;
|
|
155
|
+
var expectedAmountPayable = 3100 + 1000;
|
|
156
|
+
var expectedTotalRefundedAmount = 0;
|
|
157
|
+
var expectedCouponCode = "";
|
|
158
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
159
|
+
if (currentChargeModel)
|
|
160
|
+
currentChargeModel = currentChargeModel.extension(modify4ExtensionBookingCode);
|
|
161
|
+
expect(currentChargeModel).not.toBeNull();
|
|
162
|
+
if (currentChargeModel) {
|
|
163
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
164
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
165
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
166
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
167
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
168
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
169
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
170
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
171
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
172
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
173
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
it("5. delete", function () {
|
|
177
|
+
var expectedInitialBookingGrossAmount = 3000;
|
|
178
|
+
var expectedAdditionalBookingGrossAmount = 2500;
|
|
179
|
+
var expectedCancellationGrossAmount = 1500 + 2000;
|
|
180
|
+
var expectedTotalCancellationCharges = 100 + 100;
|
|
181
|
+
var expectedRefundPayable = 0;
|
|
182
|
+
var expectedNetTotal = 4000 - 2000;
|
|
183
|
+
var expectedAmountPaid = 0;
|
|
184
|
+
var expectedAmountPayable = 4100 + 100 - 2000;
|
|
185
|
+
var expectedTotalRefundedAmount = 0;
|
|
186
|
+
var expectedCouponCode = "";
|
|
187
|
+
var expectedDiscountPolicy = _enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL;
|
|
188
|
+
if (currentChargeModel) {
|
|
189
|
+
currentChargeModel = currentChargeModel.modify({
|
|
190
|
+
oldBookingCode: modify5DeleteNewBookingCode,
|
|
191
|
+
cancellationUnit: "100U",
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
expect(currentChargeModel).not.toBeNull();
|
|
195
|
+
if (currentChargeModel) {
|
|
196
|
+
expect(currentChargeModel.initialBookingGrossAmount).toEqual(expectedInitialBookingGrossAmount);
|
|
197
|
+
expect(currentChargeModel.additionalBookingGrossAmount).toEqual(expectedAdditionalBookingGrossAmount);
|
|
198
|
+
expect(currentChargeModel.cancelledBookingGrossAmount).toEqual(expectedCancellationGrossAmount);
|
|
199
|
+
expect(currentChargeModel.totalCancellationCharges).toEqual(expectedTotalCancellationCharges);
|
|
200
|
+
expect(currentChargeModel.refundPayable).toEqual(expectedRefundPayable);
|
|
201
|
+
expect(currentChargeModel.netTotal).toEqual(expectedNetTotal);
|
|
202
|
+
expect(currentChargeModel.amountPaid).toEqual(expectedAmountPaid);
|
|
203
|
+
expect(currentChargeModel.amountPayable).toEqual(expectedAmountPayable);
|
|
204
|
+
expect(currentChargeModel.totalRefundedAmount).toEqual(expectedTotalRefundedAmount);
|
|
205
|
+
expect(currentChargeModel.couponCode).toEqual(expectedCouponCode);
|
|
206
|
+
expect(currentChargeModel.discountPolicy).toEqual(expectedDiscountPolicy);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "turf-common",
|
|
3
|
-
"version": "1.4.2-beta.
|
|
3
|
+
"version": "1.4.2-beta.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"version:deploy:patch": "npm version patch && git push && npm run build && npm publish",
|
|
15
15
|
"version:deploy:minor": "npm version minor && git push && npm run build && npm publish",
|
|
16
16
|
"test": "jest",
|
|
17
|
-
"test:pattern": "jest -i
|
|
17
|
+
"test:pattern": "jest -i unit/charges/discount-relative",
|
|
18
18
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" 2>&1| tee eslint.log",
|
|
19
19
|
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
|
20
20
|
},
|