turf-common 1.4.1 → 1.4.2-beta.1

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 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
@@ -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
- var selectedPitchSlab = pitchRanges.filter(function (pitchRange) {
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;
@@ -57,6 +57,7 @@ export declare class SubscribedPricingPlanModelV2 extends PricingPlanModelV2 {
57
57
  }[];
58
58
  getMonths(): number;
59
59
  getBasePrice(): number;
60
+ getBasePriceV2(): number;
60
61
  getGrossAmount(config?: {
61
62
  roundDown: boolean;
62
63
  }): number;
@@ -196,15 +196,7 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
196
196
  return codes ? codes[0].split("#")[3] : "";
197
197
  };
198
198
  SubscribedPricingPlanModelV2.prototype.getBasePriceByPitchSlab = function () {
199
- var _this = this;
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)
199
+ var code = this.getCodesByPitchSlab();
208
200
  code.sort();
209
201
  if (code) {
210
202
  var _a = code[0].split("#"), from = _a[0], to = _a[1], price = _a[2];
@@ -248,6 +240,9 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
248
240
  SubscribedPricingPlanModelV2.prototype.getBasePrice = function () {
249
241
  return this.selectedPitchSlabBasePrice;
250
242
  };
243
+ SubscribedPricingPlanModelV2.prototype.getBasePriceV2 = function () {
244
+ return this.base_price;
245
+ };
251
246
  // Tested
252
247
  SubscribedPricingPlanModelV2.prototype.getGrossAmount = function (config) {
253
248
  if (config === void 0) { config = { roundDown: false }; }
@@ -288,11 +283,14 @@ var SubscribedPricingPlanModelV2 = /** @class */ (function (_super) {
288
283
  var _this = this;
289
284
  // const codesByPitchCount = this.getCodesByPitchSlab();
290
285
  var basePriceByPitchSlab = this.getBasePriceByPitchSlab();
286
+ // console.log(`basePriceByPitchSlab: ${basePriceByPitchSlab}`)
291
287
  var codesByBillingCycle = this.getCodeByCycle();
288
+ // console.log(`codesByBillingCycle: ${codesByBillingCycle}`)
292
289
  var codeByPitchCycle = codesByBillingCycle.filter(function (code) {
293
290
  var _a = code.split("#")[0].split("_"), from = _a[0], to = _a[1];
294
291
  return _this.pitchCount >= parseInt(from) && _this.pitchCount <= parseInt(to);
295
292
  })[0];
293
+ // console.log(`codeByPitchCycle: ${codeByPitchCycle}`)
296
294
  var basePriceByPitchCycle = parseFloat(codeByPitchCycle.split("#")[2]);
297
295
  return parseFloat(((basePriceByPitchSlab - basePriceByPitchCycle) / basePriceByPitchSlab * 100).toFixed(2));
298
296
  };
@@ -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("exceute all methods of pricingPlanEntityModel", function () {
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.1",
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
- "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" 2>&1| tee eslint.log",
18
- "lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "github__bellex-dev__turf-common:bellex-dev/turf-common.git"
23
- },
24
- "keywords": [],
25
- "author": "",
26
- "license": "ISC",
27
- "devDependencies": {
28
- "@types/jest": "^29.5.11",
29
- "@types/node": "^20.8.9",
30
- "@typescript-eslint/eslint-plugin": "^6.7.2",
31
- "@typescript-eslint/parser": "^6.7.2",
32
- "del-cli": "^5.1.0",
33
- "eslint": "^8.50.0",
34
- "jest": "^29.7.0",
35
- "ts-jest": "^29.1.1",
36
- "ts-node": "^10.9.2",
37
- "typescript": "^5.2.2"
38
- },
39
- "dependencies": {
40
- "date-fns": "^2.30.0"
41
- }
42
- }
1
+ {
2
+ "name": "turf-common",
3
+ "version": "1.4.2-beta.1",
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
+ }