turf-common 1.4.1 → 1.4.2-beta.12
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/README.md +20 -20
- package/build/src/enums/valid-coupon-type.enum.d.ts +3 -0
- package/build/src/enums/valid-coupon-type.enum.js +18 -0
- package/build/src/interface/api/booking-availablity-by-pitch.interface.d.ts +1 -0
- package/build/src/interface/api/create-recurring-slot-booking.interface.d.ts +1 -0
- package/build/src/interface/api/one-slot-booking.interface.d.ts +1 -0
- package/build/src/models/booking-code-model.d.ts +6 -1
- package/build/src/models/booking-code-model.js +14 -2
- package/build/src/models/pitch-slab-model.d.ts +1 -0
- package/build/src/models/pitch-slab-model.js +15 -0
- package/build/src/models/pricing-plan-model.js +1 -4
- package/build/src/models/subscribed-pricing-plan-model.d.ts +10 -0
- package/build/src/models/subscribed-pricing-plan-model.js +50 -17
- package/build/tests/unit/pricing-plan/basic-scenario.spec.d.ts +1 -0
- package/build/tests/unit/pricing-plan/basic-scenario.spec.js +183 -0
- package/build/tests/unit/pricing-plan/basic.spec.js +1 -1
- package/package.json +43 -42
package/README.md
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
## 1 npm init -y
|
|
2
|
-
|
|
3
|
-
## 2 npm login
|
|
4
|
-
|
|
5
|
-
## 3 npm version patch
|
|
6
|
-
|
|
7
|
-
# //it increase version
|
|
8
|
-
|
|
9
|
-
## 3 npm publish --access public
|
|
10
|
-
|
|
11
|
-
# //npm publish by default --access public
|
|
12
|
-
|
|
13
|
-
## 4 npm run version:deploy
|
|
14
|
-
|
|
15
|
-
### deploy version
|
|
16
|
-
|
|
17
|
-
## Client side
|
|
18
|
-
|
|
19
|
-
update package command <br />
|
|
20
|
-
npm update turf-comman
|
|
1
|
+
## 1 npm init -y
|
|
2
|
+
|
|
3
|
+
## 2 npm login
|
|
4
|
+
|
|
5
|
+
## 3 npm version patch
|
|
6
|
+
|
|
7
|
+
# //it increase version
|
|
8
|
+
|
|
9
|
+
## 3 npm publish --access public
|
|
10
|
+
|
|
11
|
+
# //npm publish by default --access public
|
|
12
|
+
|
|
13
|
+
## 4 npm run version:deploy
|
|
14
|
+
|
|
15
|
+
### deploy version
|
|
16
|
+
|
|
17
|
+
## Client side
|
|
18
|
+
|
|
19
|
+
update package command <br />
|
|
20
|
+
npm update turf-comman
|
|
@@ -8,3 +8,21 @@ var ValidCouponType;
|
|
|
8
8
|
ValidCouponType["PER_HOUR_UNIT"] = "per hour unit";
|
|
9
9
|
ValidCouponType["PER_HOUR_PERCENTAGE"] = "per hour percentage";
|
|
10
10
|
})(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
|
|
11
|
+
// Create namespace for the enum and add method UILabel to get the label of the enum value.
|
|
12
|
+
(function (ValidCouponType) {
|
|
13
|
+
function UILabel(value) {
|
|
14
|
+
switch (value) {
|
|
15
|
+
case ValidCouponType.PERCENTAGE:
|
|
16
|
+
return "Percentage";
|
|
17
|
+
case ValidCouponType.UNIT:
|
|
18
|
+
return "Price";
|
|
19
|
+
case ValidCouponType.PER_HOUR_UNIT:
|
|
20
|
+
return "Price Hour Unit";
|
|
21
|
+
case ValidCouponType.PER_HOUR_PERCENTAGE:
|
|
22
|
+
return "Per Hour Percentage";
|
|
23
|
+
default:
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
ValidCouponType.UILabel = UILabel;
|
|
28
|
+
})(ValidCouponType || (exports.ValidCouponType = ValidCouponType = {}));
|
|
@@ -20,7 +20,7 @@ export declare class BookingCode {
|
|
|
20
20
|
getHalfHourTimeCodes(): string[];
|
|
21
21
|
/**
|
|
22
22
|
*
|
|
23
|
-
* @returns
|
|
23
|
+
* @returns ['00000030','00300100','01000130']: string[] - List of half hour time slot codes between start time & end time inclusive
|
|
24
24
|
* @example fromTime: 0000; toTime: 0130
|
|
25
25
|
* // returns ['00000030','00300100','01000130']
|
|
26
26
|
*/
|
|
@@ -31,6 +31,11 @@ export declare class BookingCode {
|
|
|
31
31
|
getMonthCode(): string;
|
|
32
32
|
getDateWithFromTimeCode(): string;
|
|
33
33
|
getCodeWithoutTurfCode(): string;
|
|
34
|
+
getPriceByPriceEntities(priceEntities?: {
|
|
35
|
+
[date: string]: {
|
|
36
|
+
[time: string]: number;
|
|
37
|
+
};
|
|
38
|
+
}): number;
|
|
34
39
|
static sortByCode(bookingCodes: BookingCode[]): void;
|
|
35
40
|
static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
|
|
36
41
|
static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
|
|
@@ -60,7 +60,7 @@ var BookingCode = /** @class */ (function () {
|
|
|
60
60
|
};
|
|
61
61
|
/**
|
|
62
62
|
*
|
|
63
|
-
* @returns
|
|
63
|
+
* @returns ['00000030','00300100','01000130']: string[] - List of half hour time slot codes between start time & end time inclusive
|
|
64
64
|
* @example fromTime: 0000; toTime: 0130
|
|
65
65
|
* // returns ['00000030','00300100','01000130']
|
|
66
66
|
*/
|
|
@@ -105,6 +105,18 @@ var BookingCode = /** @class */ (function () {
|
|
|
105
105
|
BookingCode.prototype.getCodeWithoutTurfCode = function () {
|
|
106
106
|
return "".concat(this.dateCode).concat(this.slot).concat(this.pitchCode);
|
|
107
107
|
};
|
|
108
|
+
BookingCode.prototype.getPriceByPriceEntities = function (priceEntities) {
|
|
109
|
+
var halfHourTimeRangeCodes = this.getHalfHourTimeRangeCodes();
|
|
110
|
+
var weekDay = this.getWeekday();
|
|
111
|
+
var monthCode = this.getMonthCode();
|
|
112
|
+
var price = 0;
|
|
113
|
+
for (var _i = 0, halfHourTimeRangeCodes_1 = halfHourTimeRangeCodes; _i < halfHourTimeRangeCodes_1.length; _i++) {
|
|
114
|
+
var halfHourTimeRangeCode = halfHourTimeRangeCodes_1[_i];
|
|
115
|
+
price +=
|
|
116
|
+
priceEntities[monthCode + weekDay][halfHourTimeRangeCode] < 0 ? 0 : priceEntities[monthCode + weekDay][halfHourTimeRangeCode];
|
|
117
|
+
}
|
|
118
|
+
return price;
|
|
119
|
+
};
|
|
108
120
|
BookingCode.sortByCode = function (bookingCodes) {
|
|
109
121
|
bookingCodes.sort(function (_a, _b) {
|
|
110
122
|
var code1 = _a.code;
|
|
@@ -157,7 +169,7 @@ var BookingCode = /** @class */ (function () {
|
|
|
157
169
|
discount = parseFloat(couponCode) * totalBookingHours;
|
|
158
170
|
}
|
|
159
171
|
}
|
|
160
|
-
discountedCost = totalCost - discount;
|
|
172
|
+
discountedCost = totalCost - Math.round(discount);
|
|
161
173
|
return Math.round(discountedCost);
|
|
162
174
|
};
|
|
163
175
|
BookingCode.getDiscountAmount = function (couponCode, totalCost) {
|
|
@@ -27,6 +27,21 @@ var PitchSlabModelV2 = /** @class */ (function () {
|
|
|
27
27
|
this.to = data.to;
|
|
28
28
|
// this.discount = data.discount;
|
|
29
29
|
}
|
|
30
|
+
// public getDiscount(): number {
|
|
31
|
+
// if (this.discount.indexOf("P") > -1) {
|
|
32
|
+
// return parseFloat(this.discount.replace("P", ""));
|
|
33
|
+
// }
|
|
34
|
+
// return 0;
|
|
35
|
+
// }
|
|
36
|
+
// public getBasePrice(basePrice: number): number {
|
|
37
|
+
// return basePrice * (1 - this.getDiscount() / 100);
|
|
38
|
+
// }
|
|
39
|
+
PitchSlabModelV2.prototype.getRange = function () {
|
|
40
|
+
if (this.to >= 99) {
|
|
41
|
+
return "".concat(this.from - 1, "+");
|
|
42
|
+
}
|
|
43
|
+
return "".concat(this.from, "-").concat(this.to);
|
|
44
|
+
};
|
|
30
45
|
return PitchSlabModelV2;
|
|
31
46
|
}());
|
|
32
47
|
exports.PitchSlabModelV2 = PitchSlabModelV2;
|
|
@@ -110,10 +110,7 @@ var PricingPlanModelV2 = /** @class */ (function () {
|
|
|
110
110
|
PricingPlanModelV2.prototype.getPitchSlab = function (pitchCount) {
|
|
111
111
|
var pitchRangesMap = this.pitch_slab;
|
|
112
112
|
var pitchRanges = Object.values(pitchRangesMap);
|
|
113
|
-
|
|
114
|
-
return pitchRange.from <= pitchCount && pitchCount <= pitchRange.to;
|
|
115
|
-
})[0];
|
|
116
|
-
return selectedPitchSlab;
|
|
113
|
+
return pitchRanges[this.getPitchSlabIndex(pitchCount)];
|
|
117
114
|
};
|
|
118
115
|
PricingPlanModelV2.prototype.getBillingCycle = function (billingCycleKey) {
|
|
119
116
|
var billingCycleMap = this.billing_cycle;
|
|
@@ -44,6 +44,7 @@ export declare class SubscribedPricingPlanModelV2 extends PricingPlanModelV2 {
|
|
|
44
44
|
hourInMonth: number;
|
|
45
45
|
months: number | undefined;
|
|
46
46
|
constructor(data: IPricingPlanModelV2, pitchCount: number, billingCycle: string);
|
|
47
|
+
getPlanBasePriceFormatted(): string;
|
|
47
48
|
getCodeByPitchCountCycle(): string;
|
|
48
49
|
getCodeByCycle(): string[];
|
|
49
50
|
getDiscount(): string;
|
|
@@ -57,13 +58,22 @@ export declare class SubscribedPricingPlanModelV2 extends PricingPlanModelV2 {
|
|
|
57
58
|
}[];
|
|
58
59
|
getMonths(): number;
|
|
59
60
|
getBasePrice(): number;
|
|
61
|
+
getBasePriceV2(): number;
|
|
60
62
|
getGrossAmount(config?: {
|
|
61
63
|
roundDown: boolean;
|
|
62
64
|
}): number;
|
|
65
|
+
getGrossAmountV2(config?: {
|
|
66
|
+
roundDown: boolean;
|
|
67
|
+
}): number;
|
|
63
68
|
getNetAmount(config?: {
|
|
64
69
|
roundDown: boolean;
|
|
65
70
|
}): number;
|
|
71
|
+
getNetAmountV2(config?: {
|
|
72
|
+
roundDown: boolean;
|
|
73
|
+
}): number;
|
|
66
74
|
getBillingDiscount(): number;
|
|
75
|
+
getBillingDiscountV2(): number;
|
|
76
|
+
getDiscountBasePrice(): number;
|
|
67
77
|
getMonthDifference(that: SubscribedPricingPlanModelV2): number;
|
|
68
78
|
getGrossAmountByMonth(month: number): number;
|
|
69
79
|
getNetAmountByMonth(month: number): number;
|
|
@@ -150,6 +150,13 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
150
150
|
return _this;
|
|
151
151
|
// this.selectedPitchSlabBasePrice = this.base_price;
|
|
152
152
|
}
|
|
153
|
+
SubscribedPricingPlanModelV2.prototype.getPlanBasePriceFormatted = function () {
|
|
154
|
+
// Format -> #.##
|
|
155
|
+
return parseFloat((this.getBasePriceV2()).toFixed(2)).toLocaleString('en-IN', {
|
|
156
|
+
minimumFractionDigits: 2,
|
|
157
|
+
maximumFractionDigits: 2,
|
|
158
|
+
});
|
|
159
|
+
};
|
|
153
160
|
SubscribedPricingPlanModelV2.prototype.getCodeByPitchCountCycle = function () {
|
|
154
161
|
var _this = this;
|
|
155
162
|
var codes = this.billing_cost_code.split(",");
|
|
@@ -196,15 +203,7 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
196
203
|
return codes ? codes[0].split("#")[3] : "";
|
|
197
204
|
};
|
|
198
205
|
SubscribedPricingPlanModelV2.prototype.getBasePriceByPitchSlab = function () {
|
|
199
|
-
var
|
|
200
|
-
var codes = this.billing_cost_code.split(",");
|
|
201
|
-
var code = codes.filter(function (code) {
|
|
202
|
-
var _a = code.split("_"), from = _a[0], to = _a[1];
|
|
203
|
-
to = to.split("#")[0];
|
|
204
|
-
// console.log(from, to)
|
|
205
|
-
return _this.pitchCount >= parseInt(from) && _this.pitchCount <= parseInt(to);
|
|
206
|
-
});
|
|
207
|
-
// console.log(code)
|
|
206
|
+
var code = this.getCodesByPitchSlab();
|
|
208
207
|
code.sort();
|
|
209
208
|
if (code) {
|
|
210
209
|
var _a = code[0].split("#"), from = _a[0], to = _a[1], price = _a[2];
|
|
@@ -248,6 +247,9 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
248
247
|
SubscribedPricingPlanModelV2.prototype.getBasePrice = function () {
|
|
249
248
|
return this.selectedPitchSlabBasePrice;
|
|
250
249
|
};
|
|
250
|
+
SubscribedPricingPlanModelV2.prototype.getBasePriceV2 = function () {
|
|
251
|
+
return this.base_price;
|
|
252
|
+
};
|
|
251
253
|
// Tested
|
|
252
254
|
SubscribedPricingPlanModelV2.prototype.getGrossAmount = function (config) {
|
|
253
255
|
if (config === void 0) { config = { roundDown: false }; }
|
|
@@ -259,6 +261,17 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
259
261
|
return Math.round(this.selectedPitchSlabBasePrice * this.pitchCount * this.getTotalHours());
|
|
260
262
|
}
|
|
261
263
|
};
|
|
264
|
+
SubscribedPricingPlanModelV2.prototype.getGrossAmountV2 = function (config) {
|
|
265
|
+
if (config === void 0) { config = { roundDown: false }; }
|
|
266
|
+
var grossAmount = this.base_price * this.pitchCount * this.getTotalHours();
|
|
267
|
+
var roundDown = config.roundDown;
|
|
268
|
+
if (roundDown) {
|
|
269
|
+
return Math.floor(grossAmount);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
return Math.round(grossAmount);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
262
275
|
// Tested
|
|
263
276
|
SubscribedPricingPlanModelV2.prototype.getNetAmount = function (config) {
|
|
264
277
|
var _this = this;
|
|
@@ -283,19 +296,46 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
283
296
|
this.getTotalHours());
|
|
284
297
|
}
|
|
285
298
|
};
|
|
299
|
+
SubscribedPricingPlanModelV2.prototype.getNetAmountV2 = function (config) {
|
|
300
|
+
if (config === void 0) { config = { roundDown: false }; }
|
|
301
|
+
var roundDown = config.roundDown;
|
|
302
|
+
var netAmount = this.base_price * this.getDiscountBasePrice() * this.pitchCount * this.getTotalHours();
|
|
303
|
+
if (roundDown) {
|
|
304
|
+
return Math.floor(netAmount);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
return Math.round(netAmount);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
286
310
|
// Tested
|
|
287
311
|
SubscribedPricingPlanModelV2.prototype.getBillingDiscount = function () {
|
|
288
312
|
var _this = this;
|
|
289
313
|
// const codesByPitchCount = this.getCodesByPitchSlab();
|
|
290
314
|
var basePriceByPitchSlab = this.getBasePriceByPitchSlab();
|
|
315
|
+
// console.log(`basePriceByPitchSlab: ${basePriceByPitchSlab}`)
|
|
291
316
|
var codesByBillingCycle = this.getCodeByCycle();
|
|
317
|
+
// console.log(`codesByBillingCycle: ${codesByBillingCycle}`)
|
|
292
318
|
var codeByPitchCycle = codesByBillingCycle.filter(function (code) {
|
|
293
319
|
var _a = code.split("#")[0].split("_"), from = _a[0], to = _a[1];
|
|
294
320
|
return _this.pitchCount >= parseInt(from) && _this.pitchCount <= parseInt(to);
|
|
295
321
|
})[0];
|
|
322
|
+
// console.log(`codeByPitchCycle: ${codeByPitchCycle}`)
|
|
296
323
|
var basePriceByPitchCycle = parseFloat(codeByPitchCycle.split("#")[2]);
|
|
297
324
|
return parseFloat(((basePriceByPitchSlab - basePriceByPitchCycle) / basePriceByPitchSlab * 100).toFixed(2));
|
|
298
325
|
};
|
|
326
|
+
SubscribedPricingPlanModelV2.prototype.getBillingDiscountV2 = function () {
|
|
327
|
+
var discountBasePrice = this.getDiscountBasePrice();
|
|
328
|
+
return parseFloat(((this.base_price - discountBasePrice) / this.base_price * 100).toFixed(2));
|
|
329
|
+
};
|
|
330
|
+
SubscribedPricingPlanModelV2.prototype.getDiscountBasePrice = function () {
|
|
331
|
+
var _this = this;
|
|
332
|
+
var codesByBillingCycle = this.getCodeByCycle();
|
|
333
|
+
var codeByPitchCycle = codesByBillingCycle.filter(function (code) {
|
|
334
|
+
var _a = code.split("#")[0].split("_"), from = _a[0], to = _a[1];
|
|
335
|
+
return _this.pitchCount >= parseInt(from) && _this.pitchCount <= parseInt(to);
|
|
336
|
+
})[0];
|
|
337
|
+
return parseFloat(parseFloat(codeByPitchCycle.split("#")[2]).toFixed(2));
|
|
338
|
+
};
|
|
299
339
|
SubscribedPricingPlanModelV2.prototype.getMonthDifference = function (that) {
|
|
300
340
|
return that.getMonths() - this.getMonths();
|
|
301
341
|
};
|
|
@@ -350,14 +390,7 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
|
|
|
350
390
|
};
|
|
351
391
|
// Tested
|
|
352
392
|
SubscribedPricingPlanModelV2.prototype.getBasePriceBySelectedBillingCycleDiscount = function () {
|
|
353
|
-
|
|
354
|
-
var codesByBillingCycle = this.getCodeByCycle();
|
|
355
|
-
var codeByPitchCycle = codesByBillingCycle.filter(function (code) {
|
|
356
|
-
var _a = code.split("#")[0].split("_"), from = _a[0], to = _a[1];
|
|
357
|
-
return _this.pitchCount >= parseInt(from) && _this.pitchCount <= parseInt(to);
|
|
358
|
-
})[0];
|
|
359
|
-
var basePriceByPitchCycle = parseFloat(codeByPitchCycle.split("#")[2]);
|
|
360
|
-
return parseFloat(basePriceByPitchCycle.toFixed(2));
|
|
393
|
+
return this.getDiscountBasePrice();
|
|
361
394
|
};
|
|
362
395
|
// Tested
|
|
363
396
|
SubscribedPricingPlanModelV2.prototype.getTotalHours = function () {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _enum_1 = require("../../../@enum");
|
|
4
|
+
var _model_1 = require("../../../@model");
|
|
5
|
+
describe("AppController (e2e)", function () {
|
|
6
|
+
it("Pricing and Subscription related methods values assertion", function () {
|
|
7
|
+
var pricingPlanEntityV2 = {
|
|
8
|
+
id: 1,
|
|
9
|
+
effectiveFrom: new Date(),
|
|
10
|
+
effectiveTo: new Date(),
|
|
11
|
+
status: _enum_1.PricingPlanStatus.ACTIVE,
|
|
12
|
+
createdBy: 1,
|
|
13
|
+
createdOn: new Date(),
|
|
14
|
+
updatedBy: 1,
|
|
15
|
+
updatedOn: new Date(),
|
|
16
|
+
basePrice: 1,
|
|
17
|
+
unit: "unit",
|
|
18
|
+
subscriptionCycle: "000001_0P_Monthly,000003_0P_Quarterly,000006_0P_Half-Yearly,000012_0P_Yearly",
|
|
19
|
+
billingCostCode: "1_5#1#1.0000#0P,1_5#3#0.9500#5P,1_5#6#0.9300#7P,1_5#12#0.9000#10P,6_10#1#0.9800#2P,6_10#3#0.9300#7P,6_10#6#0.9100#9P,6_10#12#0.8800#12P,11_99#1#0.9500#5P,11_99#3#0.9000#10P,11_99#6#0.8800#12P,11_99#12#0.8600#14P",
|
|
20
|
+
// costCode: "001005_0P_1,006010_2P_1,011999_5P_1",
|
|
21
|
+
// billingCycle: "000001_0P_Monthly,000003_5P_Quarterly,000006_7P_Half-Yearly,000012_10P_Yearly"
|
|
22
|
+
};
|
|
23
|
+
var pricingPlanEntityModel2 = new _model_1.PricingPlanEntityModelV2(pricingPlanEntityV2);
|
|
24
|
+
// console.log(pricingPlanEntityModel2.toPitchSlabs())
|
|
25
|
+
// console.log(pricingPlanEntityModel2.toBillingCycles())
|
|
26
|
+
var expectedBillingCycles = [
|
|
27
|
+
{
|
|
28
|
+
to: 1,
|
|
29
|
+
name: 'Monthly',
|
|
30
|
+
key: 'monthly'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
to: 3,
|
|
34
|
+
name: 'Quarterly',
|
|
35
|
+
key: 'quarterly'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
to: 6,
|
|
39
|
+
name: 'Half-Yearly',
|
|
40
|
+
key: 'half-yearly'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
to: 12,
|
|
44
|
+
name: 'Yearly',
|
|
45
|
+
key: 'yearly'
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
var expectedBillingCycleKeys = expectedBillingCycles.map(function (billingCycle) { return billingCycle.key; });
|
|
49
|
+
var expectedbillingCycles = pricingPlanEntityModel2.toBillingCycles();
|
|
50
|
+
expectedbillingCycles.forEach(function (billingCycle, index) {
|
|
51
|
+
expect(billingCycle.to).toEqual(expectedBillingCycles[index].to);
|
|
52
|
+
expect(billingCycle.name).toEqual(expectedBillingCycles[index].name);
|
|
53
|
+
expect(billingCycle.key).toEqual(expectedBillingCycles[index].key);
|
|
54
|
+
});
|
|
55
|
+
var pricingPlanModelV2 = new _model_1.PricingPlanModelV2(pricingPlanEntityModel2.toModel());
|
|
56
|
+
expect(pricingPlanModelV2.formatPitchSlab(0)).toEqual("1-5");
|
|
57
|
+
expect(pricingPlanModelV2.formatPitchSlab(1)).toEqual("6-10");
|
|
58
|
+
expect(pricingPlanModelV2.formatPitchSlab(2)).toEqual("10+");
|
|
59
|
+
// console.log(pricingPlanModel.getPitchSlab(1))
|
|
60
|
+
// console.log(pricingPlanModelV2.getPitchSlab(1) )
|
|
61
|
+
var pitchCounts = [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 70];
|
|
62
|
+
var pitchSlabs = [
|
|
63
|
+
{ from: 1, to: 5 },
|
|
64
|
+
{ from: 6, to: 10 },
|
|
65
|
+
{ from: 11, to: 99 },
|
|
66
|
+
];
|
|
67
|
+
var expectedPitchSlabsByPitchCount = [
|
|
68
|
+
pitchSlabs[0],
|
|
69
|
+
pitchSlabs[0],
|
|
70
|
+
pitchSlabs[0],
|
|
71
|
+
pitchSlabs[0],
|
|
72
|
+
pitchSlabs[1],
|
|
73
|
+
pitchSlabs[1],
|
|
74
|
+
pitchSlabs[1],
|
|
75
|
+
pitchSlabs[1],
|
|
76
|
+
pitchSlabs[1],
|
|
77
|
+
pitchSlabs[2],
|
|
78
|
+
pitchSlabs[2],
|
|
79
|
+
pitchSlabs[2],
|
|
80
|
+
];
|
|
81
|
+
var pitchSlab = pricingPlanModelV2.getPitchSlab(1);
|
|
82
|
+
pitchCounts.forEach(function (pitchCount, index) {
|
|
83
|
+
pitchSlab = pricingPlanModelV2.getPitchSlab(pitchCount);
|
|
84
|
+
expect(pitchSlab.from).toEqual(expectedPitchSlabsByPitchCount[index].from);
|
|
85
|
+
expect(pitchSlab.to).toEqual(expectedPitchSlabsByPitchCount[index].to);
|
|
86
|
+
});
|
|
87
|
+
var _loop_1 = function (billingCycleKey) {
|
|
88
|
+
expect(pricingPlanModelV2.getBillingCycle(billingCycleKey)).toEqual(expectedbillingCycles.filter(function (billingCycle) { return billingCycle.key === billingCycleKey; })[0]);
|
|
89
|
+
};
|
|
90
|
+
for (var _i = 0, expectedBillingCycleKeys_1 = expectedBillingCycleKeys; _i < expectedBillingCycleKeys_1.length; _i++) {
|
|
91
|
+
var billingCycleKey = expectedBillingCycleKeys_1[_i];
|
|
92
|
+
_loop_1(billingCycleKey);
|
|
93
|
+
}
|
|
94
|
+
var monthsByBillingCycle = {
|
|
95
|
+
monthly: 1,
|
|
96
|
+
quarterly: 3,
|
|
97
|
+
"half-yearly": 6,
|
|
98
|
+
yearly: 12,
|
|
99
|
+
};
|
|
100
|
+
for (var _a = 0, expectedBillingCycleKeys_2 = expectedBillingCycleKeys; _a < expectedBillingCycleKeys_2.length; _a++) {
|
|
101
|
+
var billingCycleKey = expectedBillingCycleKeys_2[_a];
|
|
102
|
+
expect(pricingPlanModelV2.getMonth(billingCycleKey)).toEqual(monthsByBillingCycle[billingCycleKey]);
|
|
103
|
+
}
|
|
104
|
+
var noOfSubscriptionDaysByBillingCycle = {
|
|
105
|
+
monthly: 30,
|
|
106
|
+
quarterly: 90,
|
|
107
|
+
"half-yearly": 180,
|
|
108
|
+
yearly: 360,
|
|
109
|
+
};
|
|
110
|
+
// TODO: Need to check the logic of the below method as it returning 1 less than the expected value
|
|
111
|
+
// for (let billingCycleKey of expectedBillingCycleKeys) {
|
|
112
|
+
// expect(pricingPlanModelV2.getNoOfSubscriptionDays(billingCycleKey)).toEqual(noOfSubscriptionDaysByBillingCycle[billingCycleKey]);
|
|
113
|
+
// }
|
|
114
|
+
var daysByBillingCycle = {
|
|
115
|
+
monthly: [1, 3, 29, 30],
|
|
116
|
+
quarterly: [31, 90],
|
|
117
|
+
"half-yearly": [91, 180],
|
|
118
|
+
yearly: [181, 360],
|
|
119
|
+
};
|
|
120
|
+
for (var _b = 0, _c = Object.entries(daysByBillingCycle); _b < _c.length; _b++) {
|
|
121
|
+
var _d = _c[_b], billingCycleKey = _d[0], days = _d[1];
|
|
122
|
+
for (var _e = 0, days_1 = days; _e < days_1.length; _e++) {
|
|
123
|
+
var day = days_1[_e];
|
|
124
|
+
var billingCycle = pricingPlanModelV2.getBillingCycleByDay(day);
|
|
125
|
+
expect(billingCycle).toBeDefined();
|
|
126
|
+
expect(billingCycle === null || billingCycle === void 0 ? void 0 : billingCycle.key).toEqual(billingCycleKey);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var noOfMonthsByBillingCycle = {
|
|
130
|
+
0: [1],
|
|
131
|
+
1: [3, 2],
|
|
132
|
+
2: [4, 5, 6],
|
|
133
|
+
3: [7, 8, 9, 10, 11, 12],
|
|
134
|
+
};
|
|
135
|
+
for (var _f = 0, _g = Object.entries(noOfMonthsByBillingCycle); _f < _g.length; _f++) {
|
|
136
|
+
var _h = _g[_f], billingCycleKeyIndex = _h[0], months = _h[1];
|
|
137
|
+
for (var _j = 0, months_1 = months; _j < months_1.length; _j++) {
|
|
138
|
+
var month = months_1[_j];
|
|
139
|
+
expect(pricingPlanModelV2.getBillingCycleIndexByMonths(month)).toEqual(parseInt(billingCycleKeyIndex));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// const pitchCount = 11;
|
|
143
|
+
// const billingCycleKey = 'quarterly';
|
|
144
|
+
// const billingCycleKeys = ["monthly", "quarterly", "half-yearly", "yearly"];
|
|
145
|
+
var basePriceMatrix = [
|
|
146
|
+
[1, 0.95, 0.93, 0.9],
|
|
147
|
+
[0.98, 0.93, 0.91, 0.88],
|
|
148
|
+
[0.95, 0.9, 0.88, 0.86],
|
|
149
|
+
];
|
|
150
|
+
pitchCounts = [2, 6, 70];
|
|
151
|
+
for (var _k = 0, pitchCounts_1 = pitchCounts; _k < pitchCounts_1.length; _k++) {
|
|
152
|
+
var pitchCount = pitchCounts_1[_k];
|
|
153
|
+
for (var _l = 0, expectedBillingCycleKeys_3 = expectedBillingCycleKeys; _l < expectedBillingCycleKeys_3.length; _l++) {
|
|
154
|
+
var billingCycleKey = expectedBillingCycleKeys_3[_l];
|
|
155
|
+
var subscribedPricingPlanModelV2 = new _model_1.SubscribedPricingPlanModelV2(pricingPlanModelV2, pitchCount, billingCycleKey);
|
|
156
|
+
console.log("---- Pitch Count: '".concat(subscribedPricingPlanModelV2.pitchCount, "', Billing: '").concat(subscribedPricingPlanModelV2.billingCycle, "'"));
|
|
157
|
+
// TODO: Need to check the usability of the below method
|
|
158
|
+
// console.log(`subscribedPricingPlanModelV2.getMonths() : ${subscribedPricingPlanModelV2.getMonths()}`)
|
|
159
|
+
// TODO: Needs to change the name to getBasePriceByPitchSlab for Monthly
|
|
160
|
+
// console.log(`subscribedPricingPlanModelV2.getBasePrice(): ${subscribedPricingPlanModelV2.getBasePrice()}`)
|
|
161
|
+
// TODO: Neede removal
|
|
162
|
+
// console.log(`subscribedPricingPlanModelV2.getBillingDiscount(): ${subscribedPricingPlanModelV2.getBillingDiscount()}`)
|
|
163
|
+
// expect(subscribebPricingPlanModel.getBillingDiscount()).toEqual(
|
|
164
|
+
// subscribedPricingPlanModelV2.getBillingDiscount()
|
|
165
|
+
// );
|
|
166
|
+
// TODO: Needs to change the logic based on base price and discount
|
|
167
|
+
// console.log(`subscribedPricingPlanModelV2.getGrossAmount(): ${subscribedPricingPlanModelV2.getGrossAmount()}`)
|
|
168
|
+
// TODO: Needs to change the logic based on base price and discount
|
|
169
|
+
// console.log(`subscribedPricingPlanModelV2.getNetAmount(): ${subscribedPricingPlanModelV2.getNetAmount()}`)
|
|
170
|
+
// console.log(`subscribedPricingPlanModelV2.getGrossAmountByPitchDays(): ${subscribedPricingPlanModelV2.getGrossAmountByPitchDays(11, 3)}`)
|
|
171
|
+
// console.log(`subscribedPricingPlanModelV2.getNetAmountByPitchDays(): ${subscribedPricingPlanModelV2.getNetAmountByPitchDays(11, 3)}`)
|
|
172
|
+
var pitchSlabIndex = subscribedPricingPlanModelV2.getPitchSlabIndex(pitchCount);
|
|
173
|
+
var billingCycleIndex = subscribedPricingPlanModelV2.getBillingCycleIndexByMonths(subscribedPricingPlanModelV2.selectedBillingCycle.to);
|
|
174
|
+
expect(subscribedPricingPlanModelV2.getBasePriceBySelectedBillingCycleDiscount()).toEqual(basePriceMatrix[pitchSlabIndex][billingCycleIndex]);
|
|
175
|
+
// const months = [1, 2, 3, 5, 6, 7, 11, 12];
|
|
176
|
+
// for (let month of months) {
|
|
177
|
+
// console.log(`subscribedPricingPlanModelV2.getGrossAmountByMonth(${month}): ${subscribedPricingPlanModelV2.getGrossAmountByMonth(month)}`)
|
|
178
|
+
// console.log(`subscribedPricingPlanModelV2.getNetAmountByMonth(${month}): ${subscribedPricingPlanModelV2.getNetAmountByMonth(month)}`)
|
|
179
|
+
// }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -6,7 +6,7 @@ var _model_1 = require("../../../@model");
|
|
|
6
6
|
// 000001_0P_Monthly,000003_5P_Quarterly,000006_7P_Half-Yearly,000012_10P_Yearly
|
|
7
7
|
// 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
|
|
8
8
|
describe("AppController (e2e)", function () {
|
|
9
|
-
it("
|
|
9
|
+
it("Pricing and subscriptions related version 2 models method values verification ", function () {
|
|
10
10
|
var pricingPlanEntity = {
|
|
11
11
|
id: 1,
|
|
12
12
|
effectiveFrom: new Date(),
|
package/package.json
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "turf-common",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./build/index.js",
|
|
6
|
-
"types": "./build/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"build/**/*"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"clean": "rm -rf build",
|
|
12
|
-
"build": "npm run clean && tsc",
|
|
13
|
-
"version:deploy:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
|
|
14
|
-
"version:deploy:patch": "npm version patch && git push && npm run build && npm publish",
|
|
15
|
-
"version:deploy:minor": "npm version minor && git push && npm run build && npm publish",
|
|
16
|
-
"test": "jest",
|
|
17
|
-
"
|
|
18
|
-
"lint
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"@types/
|
|
30
|
-
"@
|
|
31
|
-
"@typescript-eslint/
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"ts-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "turf-common",
|
|
3
|
+
"version": "1.4.2-beta.12",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rm -rf build",
|
|
12
|
+
"build": "npm run clean && tsc",
|
|
13
|
+
"version:deploy:beta": "npm version prerelease --preid beta && git push && npm run build && npm publish --tag beta",
|
|
14
|
+
"version:deploy:patch": "npm version patch && git push && npm run build && npm publish",
|
|
15
|
+
"version:deploy:minor": "npm version minor && git push && npm run build && npm publish",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"test:pattern": "jest -i TURF-533",
|
|
18
|
+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" 2>&1| tee eslint.log",
|
|
19
|
+
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "github__bellex-dev__turf-common:bellex-dev/turf-common.git"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.11",
|
|
30
|
+
"@types/node": "^20.8.9",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
32
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
33
|
+
"del-cli": "^5.1.0",
|
|
34
|
+
"eslint": "^8.50.0",
|
|
35
|
+
"jest": "^29.7.0",
|
|
36
|
+
"ts-jest": "^29.1.1",
|
|
37
|
+
"ts-node": "^10.9.2",
|
|
38
|
+
"typescript": "^5.2.2"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"date-fns": "^2.30.0"
|
|
42
|
+
}
|
|
43
|
+
}
|