@nuskin/react-loyalty-elements 1.1.0-loyalty-mvp.26 → 1.1.0-loyalty-mvp.28
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/package.json
CHANGED
|
@@ -62,7 +62,7 @@ const SubscriptionReward = (props: RewardProgressBarProps) => {
|
|
|
62
62
|
let monthCompletionValue = 0;
|
|
63
63
|
|
|
64
64
|
if (data) {
|
|
65
|
-
const sortedSubs = data.
|
|
65
|
+
const sortedSubs = data.csmMonthlySubsOrderTotal?.sort(
|
|
66
66
|
(a: { year: number; month: number }, b: { year: number; month: number }) => {
|
|
67
67
|
if (a.year === b.year) {
|
|
68
68
|
return b.month - a.month;
|
|
@@ -70,35 +70,23 @@ const SubscriptionReward = (props: RewardProgressBarProps) => {
|
|
|
70
70
|
return b.year - a.year;
|
|
71
71
|
},
|
|
72
72
|
);
|
|
73
|
-
|
|
74
73
|
const lastThreeMonths = sortedSubs?.slice(0, 3);
|
|
75
|
-
|
|
74
|
+
const monthsForCalculateCSM = lastThreeMonths.reverse();
|
|
75
|
+
const allMonthsAboveMaxAmount = lastThreeMonths.every(
|
|
76
|
+
(sub: { totalAmount: number }) => sub.totalAmount > maxAmount,
|
|
77
|
+
);
|
|
76
78
|
const promoCodes = lastThreeMonths?.map((sub: { promoCode: string }) => sub.promoCode);
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
totalAmount > minAmount &&
|
|
84
|
-
(!promoCodes[i] ||
|
|
85
|
-
promoCodes[i] === undefined ||
|
|
86
|
-
promoCodes[i] === '' ||
|
|
87
|
-
promoCodes[i] === null)
|
|
88
|
-
) {
|
|
89
|
-
monthCompletionValue = monthCompletionValue + 1;
|
|
90
|
-
voucherValue = 50;
|
|
91
|
-
if (totalAmount > maxAmount) {
|
|
92
|
-
voucherValue = 150;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
} else if (
|
|
79
|
+
const isValid = !promoCodes.some((code: string) => code === undefined);
|
|
80
|
+
// Ensure you have at least two promo codes to compare.
|
|
81
|
+
const allSamePromoCode = isValid ? promoCodes?.every((code: string) => code === promoCodes[0]) : false;
|
|
82
|
+
for (let i = 0; i < monthsForCalculateCSM?.length; i++) {
|
|
83
|
+
const totalAmount = monthsForCalculateCSM[i].totalAmount;
|
|
84
|
+
if (
|
|
96
85
|
allSamePromoCode &&
|
|
97
86
|
(promoCodes[i] !== undefined || promoCodes[i] !== '' || promoCodes[i] !== null)
|
|
98
87
|
) {
|
|
99
88
|
monthCompletionValue = 3;
|
|
100
89
|
} else {
|
|
101
|
-
// Check the total amount against the minAmount and maxAmount
|
|
102
90
|
if (
|
|
103
91
|
totalAmount > minAmount &&
|
|
104
92
|
(!promoCodes[i] ||
|
|
@@ -107,11 +95,13 @@ const SubscriptionReward = (props: RewardProgressBarProps) => {
|
|
|
107
95
|
promoCodes[i] === null)
|
|
108
96
|
) {
|
|
109
97
|
monthCompletionValue = monthCompletionValue + 1;
|
|
110
|
-
voucherValue = minVoucher;
|
|
111
|
-
|
|
112
|
-
|
|
98
|
+
voucherValue = allMonthsAboveMaxAmount ? maxVoucher : minVoucher;
|
|
99
|
+
} else {
|
|
100
|
+
if (totalAmount < minAmount) {
|
|
101
|
+
if ((i === 2 && data?.approximateMonthlyTotal?.currentMonthTotal < minAmount) || i !== 2) {
|
|
102
|
+
monthCompletionValue = 0;
|
|
103
|
+
}
|
|
113
104
|
}
|
|
114
|
-
} else if (totalAmount < minAmount) {
|
|
115
105
|
monthCompletionValue = monthCompletionValue;
|
|
116
106
|
}
|
|
117
107
|
}
|
|
@@ -15,7 +15,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
15
15
|
currentMonthTotal: 150.7,
|
|
16
16
|
nextMonthTotal: 120.0,
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
csmMonthlySubsOrderTotal: [
|
|
19
19
|
{
|
|
20
20
|
accountId: 225167,
|
|
21
21
|
userId: 237,
|
|
@@ -110,7 +110,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
110
110
|
jest.spyOn(application, 'isMobile', 'get').mockReturnValue(false);
|
|
111
111
|
|
|
112
112
|
const mockSubscriptionData = {
|
|
113
|
-
|
|
113
|
+
csmMonthlySubsOrderTotal: [{ totalAmount: 200 }, { totalAmount: 300 }, { totalAmount: 291.8 }],
|
|
114
114
|
};
|
|
115
115
|
|
|
116
116
|
render(<SubscriptionReward subscriptionData={mockSubscriptionData} {...props} />);
|
|
@@ -122,7 +122,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
122
122
|
const customProps = {
|
|
123
123
|
...props,
|
|
124
124
|
subscriptionData: {
|
|
125
|
-
|
|
125
|
+
csmMonthlySubsOrderTotal: [
|
|
126
126
|
{ totalAmount: 150, promoCode: undefined },
|
|
127
127
|
{ totalAmount: 200, promoCode: undefined },
|
|
128
128
|
{ totalAmount: 300, promoCode: undefined },
|
|
@@ -138,7 +138,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
138
138
|
const belowMinAmountProps = {
|
|
139
139
|
...props,
|
|
140
140
|
subscriptionData: {
|
|
141
|
-
|
|
141
|
+
csmMonthlySubsOrderTotal: [
|
|
142
142
|
{ totalAmount: 50 }, // Assuming minAmount is greater than 50
|
|
143
143
|
],
|
|
144
144
|
},
|
|
@@ -152,7 +152,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
152
152
|
const aboveMaxAmountProps = {
|
|
153
153
|
...props,
|
|
154
154
|
subscriptionData: {
|
|
155
|
-
|
|
155
|
+
csmMonthlySubsOrderTotal: [
|
|
156
156
|
{ totalAmount: 350 }, // Assuming maxAmount is less than 350
|
|
157
157
|
],
|
|
158
158
|
},
|
|
@@ -173,7 +173,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
173
173
|
const missingPromoCodeProps = {
|
|
174
174
|
...props,
|
|
175
175
|
subscriptionData: {
|
|
176
|
-
|
|
176
|
+
csmMonthlySubsOrderTotal: [
|
|
177
177
|
{ totalAmount: 150, promoCode: undefined },
|
|
178
178
|
{ totalAmount: 200, promoCode: null },
|
|
179
179
|
{ totalAmount: 300, promoCode: '' },
|
|
@@ -189,7 +189,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
189
189
|
const samePromoCodeBelowThresholdProps = {
|
|
190
190
|
...props,
|
|
191
191
|
subscriptionData: {
|
|
192
|
-
|
|
192
|
+
csmMonthlySubsOrderTotal: [
|
|
193
193
|
{ totalAmount: 50, promoCode: 'CODE1' },
|
|
194
194
|
{ totalAmount: 75, promoCode: 'CODE1' },
|
|
195
195
|
{ totalAmount: 80, promoCode: 'CODE1' },
|
|
@@ -205,7 +205,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
205
205
|
const samePromoCodeProps = {
|
|
206
206
|
...props,
|
|
207
207
|
subscriptionData: {
|
|
208
|
-
|
|
208
|
+
csmMonthlySubsOrderTotal: [
|
|
209
209
|
{ totalAmount: 150, promoCode: 'CODE1' },
|
|
210
210
|
{ totalAmount: 200, promoCode: 'CODE1' },
|
|
211
211
|
{ totalAmount: 300, promoCode: 'CODE1' },
|
|
@@ -260,21 +260,12 @@ describe('SubscriptionReward Component', () => {
|
|
|
260
260
|
// Add assertions to check the expected behavior
|
|
261
261
|
});
|
|
262
262
|
|
|
263
|
-
it('handles case where subscriptionData is an empty object', () => {
|
|
264
|
-
const emptyObjectProps = {
|
|
265
|
-
...props,
|
|
266
|
-
subscriptionData: {},
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
render(<SubscriptionReward {...emptyObjectProps} />);
|
|
270
|
-
// Add assertions to check the expected behavior
|
|
271
|
-
});
|
|
272
263
|
|
|
273
264
|
it('calculates month completion values correctly with varying promo codes', () => {
|
|
274
265
|
const customProps = {
|
|
275
266
|
...props,
|
|
276
267
|
subscriptionData: {
|
|
277
|
-
|
|
268
|
+
csmMonthlySubsOrderTotal: [
|
|
278
269
|
{ totalAmount: 150, promoCode: 'CODE1' },
|
|
279
270
|
{ totalAmount: 200, promoCode: 'CODE1' },
|
|
280
271
|
{ totalAmount: 300, promoCode: 'CODE2' },
|
|
@@ -291,7 +282,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
291
282
|
const customProps = {
|
|
292
283
|
...props,
|
|
293
284
|
subscriptionData: {
|
|
294
|
-
|
|
285
|
+
csmMonthlySubsOrderTotal: [
|
|
295
286
|
{ totalAmount: 150, promoCode: undefined },
|
|
296
287
|
{ totalAmount: 200, promoCode: undefined },
|
|
297
288
|
{ totalAmount: 300, promoCode: undefined },
|
|
@@ -307,7 +298,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
307
298
|
const customProps = {
|
|
308
299
|
...props,
|
|
309
300
|
subscriptionData: {
|
|
310
|
-
|
|
301
|
+
csmMonthlySubsOrderTotal: [
|
|
311
302
|
{ totalAmount: 150, promoCode: 'CODE1' },
|
|
312
303
|
{ totalAmount: 200, promoCode: undefined },
|
|
313
304
|
{ totalAmount: 300, promoCode: 'CODE1' },
|
|
@@ -323,7 +314,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
323
314
|
const customProps = {
|
|
324
315
|
...props,
|
|
325
316
|
subscriptionData: {
|
|
326
|
-
|
|
317
|
+
csmMonthlySubsOrderTotal: [
|
|
327
318
|
{ totalAmount: 50, promoCode: 'CODE1' },
|
|
328
319
|
{ totalAmount: 75, promoCode: 'CODE1' },
|
|
329
320
|
{ totalAmount: 80, promoCode: 'CODE1' },
|
|
@@ -339,7 +330,7 @@ describe('SubscriptionReward Component', () => {
|
|
|
339
330
|
const customProps = {
|
|
340
331
|
...props,
|
|
341
332
|
subscriptionData: {
|
|
342
|
-
|
|
333
|
+
csmMonthlySubsOrderTotal: [
|
|
343
334
|
{ totalAmount: 350, promoCode: 'CODE1' },
|
|
344
335
|
{ totalAmount: 400, promoCode: 'CODE1' },
|
|
345
336
|
{ totalAmount: 450, promoCode: 'CODE1' },
|
|
@@ -7,13 +7,6 @@ jest.mock('..', () => ({
|
|
|
7
7
|
}));
|
|
8
8
|
|
|
9
9
|
describe('SubscriptionRewardModal', () => {
|
|
10
|
-
test('calls close function when closed', () => {
|
|
11
|
-
const closeMock = jest.fn();
|
|
12
|
-
render(<SubscriptionRewardModal show={true} close={closeMock} />);
|
|
13
|
-
fireEvent.click(screen.getByRole('button', { name: /close/i }));
|
|
14
|
-
expect(closeMock).toHaveBeenCalled();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
10
|
test('does not render modal when show is false', () => {
|
|
18
11
|
render(<SubscriptionRewardModal show={false} />);
|
|
19
12
|
expect(screen.queryByText(/Start earning vouchers today!/i)).not.toBeInTheDocument();
|