Skip to content

Commit 2ea4dd2

Browse files
authored
Merge pull request #2817 from FromDoppler/dat-2836-map-beplic-doppler-conversations-api
[] - Integrate with conversations api
2 parents a9c244c + 8282c18 commit 2ea4dd2

18 files changed

Lines changed: 414 additions & 14 deletions

File tree

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ REACT_APP_DOPPLER_ONSITE_URL=https://webappint.fromdoppler.net/popup-hub
3636
REACT_APP_DOPPLER_CAN_BUY_PUSHNOTIFICATION_PLAN=true
3737
REACT_APP_DOPPLER_BEPLIC_API_URL=http://localhost:10695/
3838
REACT_APP_DOPPLER_POPUP_HUB_API_URL=http://localhost:10695/
39+
REACT_APP_DOPPLER_CONVERSATIONS_API_URL=http://localhost:10695/
3940
REACT_APP_USERPILOT_TOKEN=
4041
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_FREE_USER=true
4142
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_CONTACTS_MONTHLY_USER=true

.env.int

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ REACT_APP_DOPPLER_ONSITE_URL=https://webappint.fromdoppler.net/popup-hub
3838
REACT_APP_DOPPLER_CAN_BUY_PUSHNOTIFICATION_PLAN=true
3939
REACT_APP_DOPPLER_BEPLIC_API_URL=https://apisint.fromdoppler.net/doppler-beplic
4040
REACT_APP_DOPPLER_POPUP_HUB_API_URL=https://apisint.fromdoppler.net/doppler-popup-hub-msa
41+
REACT_APP_DOPPLER_CONVERSATIONS_API_URL=https://apisint.fromdoppler.net/conversations-middleware
4142
REACT_APP_USERPILOT_TOKEN=STG-NX-d04cfcac
4243
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_FREE_USER=true
4344
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_CONTACTS_MONTHLY_USER=true

.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ REACT_APP_DOPPLER_ONSITE_URL=https://app.fromdoppler.com/popup-hub
3838
REACT_APP_DOPPLER_CAN_BUY_PUSHNOTIFICATION_PLAN=false
3939
REACT_APP_DOPPLER_BEPLIC_API_URL=https://apis.fromdoppler.com/doppler-beplic
4040
REACT_APP_DOPPLER_POPUP_HUB_API_URL=https://apis.fromdoppler.com/doppler-popup-hub-msa
41+
REACT_APP_DOPPLER_CONVERSATIONS_API_URL=https://apis.fromdoppler.com/conversations-middleware
4142
REACT_APP_USERPILOT_TOKEN=NX-d04cfcac
4243
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_FREE_USER=true
4344
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_CONTACTS_MONTHLY_USER=true

.env.qa

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ REACT_APP_DOPPLER_ONSITE_URL=https://webappqa.fromdoppler.net/popup-hub
3838
REACT_APP_DOPPLER_CAN_BUY_PUSHNOTIFICATION_PLAN=true
3939
REACT_APP_DOPPLER_BEPLIC_API_URL=https://apisqa.fromdoppler.net/doppler-beplic
4040
REACT_APP_DOPPLER_POPUP_HUB_API_URL=https://apisqa.fromdoppler.net/doppler-popup-hub-msa
41+
REACT_APP_DOPPLER_CONVERSATIONS_API_URL=https://apisqa.fromdoppler.net/conversations-middleware
4142
REACT_APP_USERPILOT_TOKEN=STG-NX-d04cfcac
4243
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_FREE_USER=true
4344
REACT_APP_DOPPLER_SUPPORT_CANCELLATION_CONTACTS_MONTHLY_USER=true

src/components/BuyProcess/ConversationPlanSelection/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const ConversationPlanSelection = InjectAppServices(
3939
handleSliderValue,
4040
] = useAddOnPlans(AddOnType.Conversations, dopplerAccountPlansApiClient, appSessionRef);
4141

42-
4342
const conversationsPromotions = useMemo(
4443
() =>
4544
appSessionRef.current.userData.user.addOnPromotions !== undefined

src/components/BuyProcess/ShoppingCart/Promocode/PromocodeMessages/index.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe('PromocodeMessages component', () => {
1919
promotion={promotion}
2020
allowPromocode={allowPromocode}
2121
hasPromocodeAppliedItem={true}
22-
/>,
22+
/>
23+
,
2324
</IntlProvider>,
2425
);
2526

src/components/BuyProcess/ShoppingCart/Promocode/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ export const Promocode = InjectAppServices(
220220
dispatchPromocode(validateData);
221221
}
222222
} else {
223-
224223
if (selectedPlanType === selectedMarketingPlan?.type) {
225224
const validateData = await dopplerAccountPlansApiClient.validatePromocode(
226225
selectedMarketingPlan?.id,
@@ -265,8 +264,7 @@ export const Promocode = InjectAppServices(
265264
// In this case the user selects a payment frequency or an email marketing plan
266265
const currentPromocode = promocodeInputRef.current?.values[fieldNames.promocode];
267266
const shouldValidatePromocode =
268-
(selectedPaymentFrequency === undefined ||
269-
selectedPaymentFrequency?.numberMonths === 1) &&
267+
(selectedPaymentFrequency === undefined || selectedPaymentFrequency?.numberMonths === 1) &&
270268
currentPromocode;
271269

272270
if (!alreadyInitializedRef.current) {
@@ -480,4 +478,4 @@ export const getPromocode = (query, isArgentina) => {
480478
return !promocodeFromUrl && isArgentina
481479
? process.env.REACT_APP_PROMOCODE_ARGENTINA
482480
: promocodeFromUrl;
483-
};
481+
};

src/components/BuyProcess/ShoppingCart/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,4 @@ ShoppingCart.propTypes = {
472472
isEqualPlan: PropTypes.bool,
473473
canBuy: PropTypes.bool,
474474
selectedPaymentMethod: PropTypes.object,
475-
};
475+
};

src/components/MyPlan/SubscriptionDetails/AddOnPlan/ConversationPlan/index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import { formattedNumber } from '..';
66
import { HeaderStyled } from '../index.style';
77
import { AddOnExpiredMessage } from '../AddOnExpiredMessage';
88
import { getPromotionInformationMessage } from '../utils';
9+
import { ConversationsEnvSource } from '../../../../../doppler-types';
910

1011
export const ConversationPlan = InjectAppServices(
1112
({
1213
buyUrl,
1314
conversationPlan,
1415
isFreeAccount,
1516
addOnPromotions,
16-
dependencies: { dopplerBeplicApiClient, dopplerAccountPlansApiClient, appSessionRef },
17+
dependencies: {
18+
dopplerBeplicApiClient,
19+
dopplerConversationsApiClient,
20+
dopplerAccountPlansApiClient,
21+
appSessionRef,
22+
},
1723
}) => {
1824
const intl = useIntl();
1925
const _ = (id, values) => intl.formatMessage({ id: id }, values);
@@ -25,6 +31,8 @@ export const ConversationPlan = InjectAppServices(
2531
useEffect(() => {
2632
const fetchAddOnData = async () => {
2733
if (plan.active) {
34+
const user = appSessionRef.current.userData.user;
35+
2836
const currentDate = new Date();
2937
const currentYear = currentDate.getFullYear();
3038
const currentMonth = currentDate.getMonth() + 1;
@@ -38,10 +46,22 @@ export const ConversationPlan = InjectAppServices(
3846
'-' +
3947
currentDay.toString().padStart(2, '0');
4048

41-
var getConversationsResponse = await dopplerBeplicApiClient.getConversations(
42-
dateFrom,
43-
dateTo,
44-
);
49+
var getConversationsResponse = null;
50+
51+
if (
52+
user.conversationsEnvSource === '' ||
53+
user.conversationsEnvSource === ConversationsEnvSource.Beplic
54+
) {
55+
getConversationsResponse = await dopplerBeplicApiClient.getConversations(
56+
dateFrom,
57+
dateTo,
58+
);
59+
} else {
60+
getConversationsResponse = await dopplerConversationsApiClient.getConversations(
61+
dateFrom,
62+
dateTo,
63+
);
64+
}
4565

4666
if (getConversationsResponse.success) {
4767
setAvailableQuantity(plan.quantity - getConversationsResponse.value);
@@ -63,11 +83,13 @@ export const ConversationPlan = InjectAppServices(
6383
fetchAddOnData();
6484
}, [
6585
dopplerBeplicApiClient,
86+
dopplerConversationsApiClient,
6687
dopplerAccountPlansApiClient,
6788
plan.active,
6889
plan.quantity,
6990
isFreeAccount,
7091
addOnPromotions,
92+
appSessionRef,
7193
]);
7294

7395
if (loading) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import { BrowserRouter } from 'react-router-dom';
2+
import { ConversationPlan } from '.';
3+
import { AppServicesProvider } from '../../../../../services/pure-di';
4+
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react';
5+
import '@testing-library/jest-dom/extend-expect';
6+
import { IntlProvider } from 'react-intl';
7+
8+
describe('ConversationPlan component', () => {
9+
it('should render component', async () => {
10+
// Assert
11+
var conversationPlan = {
12+
active: true,
13+
additionalConversation: 0,
14+
};
15+
16+
const dependencies = {
17+
dopplerBeplicApiClient: {
18+
getConversations: () => ({ success: true }),
19+
},
20+
dopplerConversationsApiClient: {
21+
getConversations: () => ({ success: true }),
22+
},
23+
appSessionRef: {
24+
current: {
25+
userData: {
26+
user: {
27+
conversationsEnvSource: 'DOPPLER',
28+
addOnPromotions: [],
29+
plan: {
30+
isFreeAccount: false,
31+
planType: 'subscribers',
32+
maxSubscribers: 500,
33+
itemDescription: 'subscribers',
34+
remainingCredits: 500,
35+
planSubscription: 1,
36+
},
37+
chat: {
38+
active: false,
39+
plan: {
40+
conversationsQty: 200,
41+
fee: 0,
42+
},
43+
},
44+
},
45+
},
46+
},
47+
},
48+
};
49+
50+
// Act
51+
render(
52+
<AppServicesProvider forcedServices={dependencies}>
53+
<AppServicesProvider forcedServices={dependencies}>
54+
<BrowserRouter>
55+
<IntlProvider>
56+
<ConversationPlan addOnPromotions={[]} conversationPlan={conversationPlan} />
57+
</IntlProvider>
58+
</BrowserRouter>
59+
</AppServicesProvider>
60+
,
61+
</AppServicesProvider>,
62+
);
63+
64+
// Assert
65+
const loader = screen.getByTestId('wrapper-loading');
66+
await waitForElementToBeRemoved(loader);
67+
});
68+
69+
it('should show the information about conversation plan', async () => {
70+
// Assert
71+
var conversationPlan = {
72+
active: true,
73+
additionalConversation: 0,
74+
};
75+
76+
const dependencies = {
77+
dopplerBeplicApiClient: {
78+
getConversations: () => ({ success: true }),
79+
},
80+
dopplerConversationsApiClient: {
81+
getConversations: () => ({ success: true }),
82+
},
83+
appSessionRef: {
84+
current: {
85+
userData: {
86+
user: {
87+
conversationsEnvSource: 'DOPPLER',
88+
addOnPromotions: [],
89+
plan: {
90+
isFreeAccount: false,
91+
planType: 'subscribers',
92+
maxSubscribers: 500,
93+
itemDescription: 'subscribers',
94+
remainingCredits: 500,
95+
planSubscription: 1,
96+
},
97+
chat: {
98+
active: false,
99+
plan: {
100+
conversationsQty: 200,
101+
fee: 0,
102+
trialExpired: false
103+
},
104+
},
105+
},
106+
},
107+
},
108+
},
109+
};
110+
111+
// Act
112+
render(
113+
<AppServicesProvider forcedServices={dependencies}>
114+
<AppServicesProvider forcedServices={dependencies}>
115+
<BrowserRouter>
116+
<IntlProvider>
117+
<ConversationPlan addOnPromotions={[]} conversationPlan={conversationPlan} />
118+
</IntlProvider>
119+
</BrowserRouter>
120+
</AppServicesProvider>
121+
,
122+
</AppServicesProvider>,
123+
);
124+
125+
// Assert
126+
const loader = screen.getByTestId('wrapper-loading');
127+
await waitForElementToBeRemoved(loader);
128+
129+
expect(screen.getByText('my_plan.subscription_details.addon.conversation_plan.title')).toBeInTheDocument();
130+
expect(screen.getByText('my_plan.subscription_details.change_plan_button')).toBeInTheDocument();
131+
});
132+
});

0 commit comments

Comments
 (0)