@capillarytech/creatives-library 8.0.294 → 8.0.295
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 +1 -1
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +1 -51
- package/v2Components/CommonTestAndPreview/actions.js +0 -20
- package/v2Components/CommonTestAndPreview/constants.js +0 -10
- package/v2Components/CommonTestAndPreview/index.js +15 -150
- package/v2Components/CommonTestAndPreview/reducer.js +0 -47
- package/v2Components/CommonTestAndPreview/sagas.js +0 -61
- package/v2Components/CommonTestAndPreview/selectors.js +0 -51
- package/v2Components/CommonTestAndPreview/tests/SendTestMessage.test.js +0 -135
- package/v2Components/CommonTestAndPreview/tests/actions.test.js +0 -50
- package/v2Components/CommonTestAndPreview/tests/constants.test.js +0 -18
- package/v2Components/CommonTestAndPreview/tests/index.test.js +1 -342
- package/v2Components/CommonTestAndPreview/tests/reducer.test.js +0 -118
- package/v2Components/CommonTestAndPreview/tests/sagas.test.js +0 -145
- package/v2Components/CommonTestAndPreview/tests/selectors.test.js +0 -146
- package/v2Components/FormBuilder/index.js +1 -1
- package/v2Components/HtmlEditor/HTMLEditor.js +1 -0
- package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +1 -0
- package/v2Components/HtmlEditor/hooks/__tests__/useValidation.test.js +132 -3
- package/v2Components/HtmlEditor/hooks/useValidation.js +12 -9
- package/v2Components/HtmlEditor/utils/htmlValidator.js +4 -2
- package/v2Components/TestAndPreviewSlidebox/index.js +0 -14
- package/v2Containers/EmailWrapper/components/EmailHTMLEditor.js +2 -2
- package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +110 -18
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +12 -697
- package/v2Containers/SmsTrai/Edit/index.js +1 -5
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +0 -201
- package/v2Containers/Whatsapp/index.js +1 -1
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +4225 -26242
- package/v2Components/CommonTestAndPreview/DeliverySettings/DeliverySettings.scss +0 -33
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +0 -425
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.scss +0 -35
- package/v2Components/CommonTestAndPreview/DeliverySettings/constants.js +0 -92
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +0 -251
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +0 -111
- package/v2Components/CommonTestAndPreview/DeliverySettings/utils/parseSenderDetailsResponse.js +0 -88
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +0 -889
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +0 -222
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/utils/parseSenderDetailsResponse.test.js +0 -235
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for DeliverySettings component (sender ID / delivery settings summary + slidebox)
|
|
3
|
-
* @jest-environment jsdom
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import { render, screen, fireEvent } from '@testing-library/react';
|
|
8
|
-
import { IntlProvider } from 'react-intl';
|
|
9
|
-
import DeliverySettings from '../../DeliverySettings';
|
|
10
|
-
import { CHANNELS } from '../../constants';
|
|
11
|
-
|
|
12
|
-
jest.mock('../../DeliverySettings/DeliverySettings.scss', () => ({}));
|
|
13
|
-
|
|
14
|
-
jest.mock('@capillarytech/cap-ui-library', () => ({
|
|
15
|
-
CapRow: ({ children, className, ...rest }) => <div className={className} data-testid="cap-row" {...rest}>{children}</div>,
|
|
16
|
-
CapHeading: ({ children }) => <div data-testid="cap-heading">{children}</div>,
|
|
17
|
-
CapIcon: ({ onClick, className, 'data-testid': testId }) => <button type="button" onClick={onClick} className={className} data-testid={testId || 'cap-icon'} aria-label="edit" />,
|
|
18
|
-
CapLabel: ({ children, type }) => <span data-type={type}>{children}</span>,
|
|
19
|
-
CapSlideBox: ({ show, content, handleClose }) => (show ? (
|
|
20
|
-
<div data-testid="cap-slidebox">
|
|
21
|
-
<button type="button" onClick={handleClose} data-testid="slidebox-close">Close</button>
|
|
22
|
-
{content}
|
|
23
|
-
</div>
|
|
24
|
-
) : null),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
const mockModifyDeliverySettings = jest.fn();
|
|
28
|
-
jest.mock('../../DeliverySettings/ModifyDeliverySettings', () => function MockModifyDeliverySettings(props) {
|
|
29
|
-
mockModifyDeliverySettings(props);
|
|
30
|
-
return (
|
|
31
|
-
<div data-testid="modify-delivery-settings">
|
|
32
|
-
<button type="button" onClick={() => props.onSaveDeliverySettings({ domainId: 1 })} data-testid="modify-done">Done</button>
|
|
33
|
-
<button type="button" onClick={props.onClose} data-testid="modify-close">Cancel</button>
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const defaultFormatMessage = (msg) => msg?.defaultMessage || msg?.id || '';
|
|
39
|
-
|
|
40
|
-
describe('DeliverySettings', () => {
|
|
41
|
-
const defaultProps = {
|
|
42
|
-
channel: CHANNELS.SMS,
|
|
43
|
-
deliverySettings: {},
|
|
44
|
-
senderDetailsOptions: [],
|
|
45
|
-
wecrmAccounts: [],
|
|
46
|
-
onSaveDeliverySettings: jest.fn(),
|
|
47
|
-
isLoadingSenderDetails: false,
|
|
48
|
-
formatMessage: defaultFormatMessage,
|
|
49
|
-
smsTraiDltEnabled: false,
|
|
50
|
-
registeredSenderIds: [],
|
|
51
|
-
whatsappAccountFromForm: undefined,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
beforeEach(() => {
|
|
55
|
-
jest.clearAllMocks();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('channel visibility', () => {
|
|
59
|
-
it('should return null when channel is not in CHANNELS_WITH_DELIVERY_SETTINGS', () => {
|
|
60
|
-
const { container } = render(
|
|
61
|
-
<DeliverySettings {...defaultProps} channel="INAPP" />
|
|
62
|
-
);
|
|
63
|
-
expect(container.firstChild).toBeNull();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should render when channel is SMS', () => {
|
|
67
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
|
|
68
|
-
expect(screen.getByTestId('cap-heading')).toBeTruthy();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should render when channel is EMAIL', () => {
|
|
72
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.EMAIL} />);
|
|
73
|
-
expect(screen.getByTestId('cap-heading')).toBeTruthy();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should render when channel is WHATSAPP', () => {
|
|
77
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.WHATSAPP} />);
|
|
78
|
-
expect(screen.getByTestId('cap-heading')).toBeTruthy();
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe('summary display', () => {
|
|
83
|
-
it('should show not configured when no delivery values for SMS', () => {
|
|
84
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
|
|
85
|
-
expect(screen.getByText('Not configured')).toBeTruthy();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should show summary values for SMS when deliverySettings and senderDetailsOptions match', () => {
|
|
89
|
-
const senderDetailsOptions = [{ domainId: 1, domainName: 'SMS Domain' }];
|
|
90
|
-
const deliverySettings = { domainId: 1, gsmSenderId: 'SENDER1' };
|
|
91
|
-
render(
|
|
92
|
-
<DeliverySettings
|
|
93
|
-
{...defaultProps}
|
|
94
|
-
channel={CHANNELS.SMS}
|
|
95
|
-
deliverySettings={deliverySettings}
|
|
96
|
-
senderDetailsOptions={senderDetailsOptions}
|
|
97
|
-
/>
|
|
98
|
-
);
|
|
99
|
-
expect(screen.getAllByText(/SMS Domain/).length).toBeGreaterThan(0);
|
|
100
|
-
expect(screen.getAllByText(/SENDER1/).length).toBeGreaterThan(0);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('should show not configured for EMAIL when empty', () => {
|
|
104
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.EMAIL} />);
|
|
105
|
-
expect(screen.getByText('Not configured')).toBeTruthy();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should show summary for EMAIL when has domain and sender', () => {
|
|
109
|
-
const senderDetailsOptions = [{ domainId: 2, domainName: 'Email Domain' }];
|
|
110
|
-
const deliverySettings = {
|
|
111
|
-
domainId: 2,
|
|
112
|
-
senderEmail: 'noreply@test.com',
|
|
113
|
-
senderLabel: 'Test',
|
|
114
|
-
senderReplyTo: 'reply@test.com',
|
|
115
|
-
};
|
|
116
|
-
render(
|
|
117
|
-
<DeliverySettings
|
|
118
|
-
{...defaultProps}
|
|
119
|
-
channel={CHANNELS.EMAIL}
|
|
120
|
-
deliverySettings={deliverySettings}
|
|
121
|
-
senderDetailsOptions={senderDetailsOptions}
|
|
122
|
-
/>
|
|
123
|
-
);
|
|
124
|
-
expect(screen.getAllByText(/Email Domain/).length).toBeGreaterThan(0);
|
|
125
|
-
expect(screen.getAllByText(/noreply@test\.com/).length).toBeGreaterThan(0);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should show summary for WHATSAPP when has account and sender', () => {
|
|
129
|
-
const wecrmAccounts = [{ name: 'WABA One', sourceAccountIdentifier: 'waba-1' }];
|
|
130
|
-
const deliverySettings = {
|
|
131
|
-
sourceAccountIdentifier: 'waba-1',
|
|
132
|
-
senderMobNum: '+1234567890',
|
|
133
|
-
};
|
|
134
|
-
render(
|
|
135
|
-
<DeliverySettings
|
|
136
|
-
{...defaultProps}
|
|
137
|
-
channel={CHANNELS.WHATSAPP}
|
|
138
|
-
deliverySettings={deliverySettings}
|
|
139
|
-
wecrmAccounts={wecrmAccounts}
|
|
140
|
-
/>
|
|
141
|
-
);
|
|
142
|
-
expect(screen.getAllByText(/WABA One/).length).toBeGreaterThan(0);
|
|
143
|
-
expect(screen.getAllByText(/\+1234567890/).length).toBeGreaterThan(0);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('edit and slidebox', () => {
|
|
148
|
-
it('should open slidebox when edit icon is clicked', () => {
|
|
149
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
|
|
150
|
-
expect(screen.queryByTestId('cap-slidebox')).toBeNull();
|
|
151
|
-
fireEvent.click(screen.getByTestId('delivery-settings-edit'));
|
|
152
|
-
expect(screen.getByTestId('cap-slidebox')).toBeTruthy();
|
|
153
|
-
expect(screen.getByTestId('modify-delivery-settings')).toBeTruthy();
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should pass correct props to ModifyDeliverySettings', () => {
|
|
157
|
-
render(<DeliverySettings {...defaultProps} channel={CHANNELS.SMS} />);
|
|
158
|
-
fireEvent.click(screen.getByTestId('delivery-settings-edit'));
|
|
159
|
-
expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
|
|
160
|
-
expect.objectContaining({
|
|
161
|
-
channel: CHANNELS.SMS,
|
|
162
|
-
deliverySettings: {},
|
|
163
|
-
senderDetailsOptions: [],
|
|
164
|
-
wecrmAccounts: [],
|
|
165
|
-
isLoading: false,
|
|
166
|
-
smsTraiDltEnabled: false,
|
|
167
|
-
registeredSenderIds: [],
|
|
168
|
-
whatsappAccountFromForm: undefined,
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should call onSaveDeliverySettings and close slidebox when Done is clicked', () => {
|
|
174
|
-
const onSave = jest.fn();
|
|
175
|
-
render(
|
|
176
|
-
<DeliverySettings
|
|
177
|
-
{...defaultProps}
|
|
178
|
-
channel={CHANNELS.SMS}
|
|
179
|
-
onSaveDeliverySettings={onSave}
|
|
180
|
-
/>
|
|
181
|
-
);
|
|
182
|
-
fireEvent.click(screen.getByTestId('delivery-settings-edit'));
|
|
183
|
-
fireEvent.click(screen.getByTestId('modify-done'));
|
|
184
|
-
expect(onSave).toHaveBeenCalledWith({ domainId: 1 });
|
|
185
|
-
expect(screen.queryByTestId('cap-slidebox')).toBeNull();
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should pass whatsappAccountFromForm to ModifyDeliverySettings', () => {
|
|
189
|
-
render(
|
|
190
|
-
<DeliverySettings
|
|
191
|
-
{...defaultProps}
|
|
192
|
-
channel={CHANNELS.WHATSAPP}
|
|
193
|
-
whatsappAccountFromForm={{ accountName: 'My WABA' }}
|
|
194
|
-
/>
|
|
195
|
-
);
|
|
196
|
-
fireEvent.click(screen.getByTestId('delivery-settings-edit'));
|
|
197
|
-
expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
|
|
198
|
-
expect.objectContaining({
|
|
199
|
-
whatsappAccountFromForm: { accountName: 'My WABA' },
|
|
200
|
-
})
|
|
201
|
-
);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('should pass SMS TRAI props to ModifyDeliverySettings', () => {
|
|
205
|
-
render(
|
|
206
|
-
<DeliverySettings
|
|
207
|
-
{...defaultProps}
|
|
208
|
-
channel={CHANNELS.SMS}
|
|
209
|
-
smsTraiDltEnabled
|
|
210
|
-
registeredSenderIds={['HPCLTD']}
|
|
211
|
-
/>
|
|
212
|
-
);
|
|
213
|
-
fireEvent.click(screen.getByTestId('delivery-settings-edit'));
|
|
214
|
-
expect(mockModifyDeliverySettings).toHaveBeenCalledWith(
|
|
215
|
-
expect.objectContaining({
|
|
216
|
-
smsTraiDltEnabled: true,
|
|
217
|
-
registeredSenderIds: ['HPCLTD'],
|
|
218
|
-
})
|
|
219
|
-
);
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for parseSenderDetailsResponse
|
|
3
|
-
* Covers sender ID / delivery settings response parsing for SMS, EMAIL, WHATSAPP
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { parseSenderDetailsResponse } from '../../../DeliverySettings/utils/parseSenderDetailsResponse';
|
|
7
|
-
|
|
8
|
-
describe('parseSenderDetailsResponse', () => {
|
|
9
|
-
describe('when entity is missing or null', () => {
|
|
10
|
-
it('should return empty domains when response is null', () => {
|
|
11
|
-
expect(parseSenderDetailsResponse('SMS', null)).toEqual({ domains: [] });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should return empty domains when response is undefined', () => {
|
|
15
|
-
expect(parseSenderDetailsResponse('SMS', undefined)).toEqual({ domains: [] });
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return empty domains when entity is missing', () => {
|
|
19
|
-
expect(parseSenderDetailsResponse('SMS', {})).toEqual({ domains: [] });
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('when entity is object with channel key', () => {
|
|
24
|
-
it('should parse SMS channel entity array', () => {
|
|
25
|
-
const response = {
|
|
26
|
-
entity: {
|
|
27
|
-
SMS: [
|
|
28
|
-
{
|
|
29
|
-
id: 10,
|
|
30
|
-
priority: 1,
|
|
31
|
-
domainProperties: {
|
|
32
|
-
domainName: 'SMS Domain 1',
|
|
33
|
-
id: 100,
|
|
34
|
-
contactInfo: [
|
|
35
|
-
{ type: 'gsm_sender_id', valid: true, value: 'GSM1', default: true },
|
|
36
|
-
{ type: 'cdma_sender_id', valid: true, value: 'CDMA1' },
|
|
37
|
-
],
|
|
38
|
-
connectionProperties: {},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
45
|
-
expect(result.domains).toHaveLength(1);
|
|
46
|
-
expect(result.domains[0]).toMatchObject({
|
|
47
|
-
dgmId: 10,
|
|
48
|
-
domainName: 'SMS Domain 1',
|
|
49
|
-
domainId: 100,
|
|
50
|
-
priority: 1,
|
|
51
|
-
});
|
|
52
|
-
expect(result.domains[0].gsmSenders).toHaveLength(1);
|
|
53
|
-
expect(result.domains[0].gsmSenders[0].value).toBe('GSM1');
|
|
54
|
-
expect(result.domains[0].cdmaSenders).toHaveLength(1);
|
|
55
|
-
expect(result.domains[0].cdmaSenders[0].value).toBe('CDMA1');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should parse EMAIL channel entity array', () => {
|
|
59
|
-
const response = {
|
|
60
|
-
entity: {
|
|
61
|
-
EMAIL: [
|
|
62
|
-
{
|
|
63
|
-
id: 20,
|
|
64
|
-
priority: 0,
|
|
65
|
-
domainProperties: {
|
|
66
|
-
domainName: 'Email Domain',
|
|
67
|
-
id: 200,
|
|
68
|
-
contactInfo: [
|
|
69
|
-
{ type: 'sender_id', valid: true, value: 'noreply@example.com' },
|
|
70
|
-
{ type: 'reply_to_id', valid: true, value: 'reply@example.com' },
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
const result = parseSenderDetailsResponse('EMAIL', response);
|
|
78
|
-
expect(result.domains).toHaveLength(1);
|
|
79
|
-
expect(result.domains[0]).toMatchObject({
|
|
80
|
-
dgmId: 20,
|
|
81
|
-
domainName: 'Email Domain',
|
|
82
|
-
domainId: 200,
|
|
83
|
-
priority: 0,
|
|
84
|
-
});
|
|
85
|
-
expect(result.domains[0].emailSenders).toHaveLength(1);
|
|
86
|
-
expect(result.domains[0].emailSenders[0].value).toBe('noreply@example.com');
|
|
87
|
-
expect(result.domains[0].emailRepliers).toHaveLength(1);
|
|
88
|
-
expect(result.domains[0].emailRepliers[0].value).toBe('reply@example.com');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should parse WHATSAPP channel with sourceAccountIdentifier', () => {
|
|
92
|
-
const response = {
|
|
93
|
-
entity: {
|
|
94
|
-
WHATSAPP: [
|
|
95
|
-
{
|
|
96
|
-
id: 30,
|
|
97
|
-
priority: 0,
|
|
98
|
-
domainProperties: {
|
|
99
|
-
domainName: 'WABA Domain',
|
|
100
|
-
id: 300,
|
|
101
|
-
contactInfo: [],
|
|
102
|
-
connectionProperties: {
|
|
103
|
-
sourceAccountIdentifier: 'waba-123',
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
const result = parseSenderDetailsResponse('WHATSAPP', response);
|
|
111
|
-
expect(result.domains).toHaveLength(1);
|
|
112
|
-
expect(result.domains[0].sourceAccountIdentifier).toBe('waba-123');
|
|
113
|
-
expect(result.domains[0].gsmSenders).toEqual([]);
|
|
114
|
-
expect(result.domains[0].cdmaSenders).toEqual([]);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe('when entity is direct array', () => {
|
|
119
|
-
it('should use entity as channelSenderDetails when entity is array', () => {
|
|
120
|
-
const response = {
|
|
121
|
-
entity: [
|
|
122
|
-
{
|
|
123
|
-
id: 1,
|
|
124
|
-
priority: 0,
|
|
125
|
-
domainProperties: { domainName: 'Direct Domain', id: 1 },
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
};
|
|
129
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
130
|
-
expect(result.domains).toHaveLength(1);
|
|
131
|
-
expect(result.domains[0].domainName).toBe('Direct Domain');
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('filtering and sorting', () => {
|
|
136
|
-
it('should filter contactInfo by type and valid', () => {
|
|
137
|
-
const response = {
|
|
138
|
-
entity: {
|
|
139
|
-
SMS: [
|
|
140
|
-
{
|
|
141
|
-
id: 1,
|
|
142
|
-
priority: 0,
|
|
143
|
-
domainProperties: {
|
|
144
|
-
domainName: 'D1',
|
|
145
|
-
id: 1,
|
|
146
|
-
contactInfo: [
|
|
147
|
-
{ type: 'gsm_sender_id', valid: true, value: 'A' },
|
|
148
|
-
{ type: 'gsm_sender_id', valid: false, value: 'B' },
|
|
149
|
-
{ type: 'other', valid: true, value: 'C' },
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
157
|
-
expect(result.domains[0].gsmSenders).toHaveLength(1);
|
|
158
|
-
expect(result.domains[0].gsmSenders[0].value).toBe('A');
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should sort domains by priority', () => {
|
|
162
|
-
const response = {
|
|
163
|
-
entity: {
|
|
164
|
-
SMS: [
|
|
165
|
-
{ id: 1, priority: 2, domainProperties: { domainName: 'Second', id: 1 } },
|
|
166
|
-
{ id: 2, priority: 0, domainProperties: { domainName: 'First', id: 2 } },
|
|
167
|
-
],
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
171
|
-
expect(result.domains[0].domainName).toBe('First');
|
|
172
|
-
expect(result.domains[1].domainName).toBe('Second');
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('should dedupe by domainName keeping first occurrence', () => {
|
|
176
|
-
const response = {
|
|
177
|
-
entity: {
|
|
178
|
-
SMS: [
|
|
179
|
-
{ id: 1, priority: 0, domainProperties: { domainName: 'Same', id: 1 } },
|
|
180
|
-
{ id: 2, priority: 1, domainProperties: { domainName: 'Same', id: 2 } },
|
|
181
|
-
],
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
185
|
-
expect(result.domains).toHaveLength(1);
|
|
186
|
-
expect(result.domains[0].domainId).toBe(1);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('edge cases', () => {
|
|
191
|
-
it('should return empty domains when channel key has no array', () => {
|
|
192
|
-
const response = { entity: { SMS: null } };
|
|
193
|
-
expect(parseSenderDetailsResponse('SMS', response)).toEqual({ domains: [] });
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('should return empty domains when channel key is missing and entity is not array', () => {
|
|
197
|
-
const response = { entity: { EMAIL: [] } };
|
|
198
|
-
expect(parseSenderDetailsResponse('SMS', response)).toEqual({ domains: [] });
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should handle missing domainProperties with defaults', () => {
|
|
202
|
-
const response = {
|
|
203
|
-
entity: {
|
|
204
|
-
SMS: [{ id: 1, priority: 0 }],
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
const result = parseSenderDetailsResponse('SMS', response);
|
|
208
|
-
expect(result.domains).toHaveLength(1);
|
|
209
|
-
expect(result.domains[0].domainId).toBe(-1);
|
|
210
|
-
expect(result.domains[0].domainName).toBeUndefined();
|
|
211
|
-
expect(result.domains[0].gsmSenders).toEqual([]);
|
|
212
|
-
expect(result.domains[0].cdmaSenders).toEqual([]);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should use wabaId when sourceAccountIdentifier missing for WHATSAPP', () => {
|
|
216
|
-
const response = {
|
|
217
|
-
entity: {
|
|
218
|
-
WHATSAPP: [
|
|
219
|
-
{
|
|
220
|
-
id: 1,
|
|
221
|
-
priority: 0,
|
|
222
|
-
domainProperties: {
|
|
223
|
-
domainName: 'W',
|
|
224
|
-
id: 1,
|
|
225
|
-
connectionProperties: { wabaId: 'waba-456' },
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
],
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
const result = parseSenderDetailsResponse('WHATSAPP', response);
|
|
232
|
-
expect(result.domains[0].sourceAccountIdentifier).toBe('waba-456');
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|