@capillarytech/creatives-library 9.2.3 → 9.2.4-alpha.feature-rcs-multi-account.52

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.
Files changed (38) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +9 -0
  3. package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +44 -3
  4. package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +14 -0
  5. package/v2Components/CommonTestAndPreview/SendTestMessage.js +14 -0
  6. package/v2Components/CommonTestAndPreview/index.js +118 -11
  7. package/v2Components/CommonTestAndPreview/reducer.js +8 -2
  8. package/v2Components/CommonTestAndPreview/selectors.js +6 -0
  9. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +11 -0
  10. package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +92 -0
  11. package/v2Components/CommonTestAndPreview/tests/index.test.js +200 -0
  12. package/v2Components/CommonTestAndPreview/tests/reducer.test.js +4 -0
  13. package/v2Components/CommonTestAndPreview/tests/selectors.test.js +10 -0
  14. package/v2Components/TestAndPreviewSlidebox/index.js +8 -0
  15. package/v2Containers/CommunicationFlow/CommunicationFlow.js +9 -1
  16. package/v2Containers/CommunicationFlow/Tests/CommunicationFlow.test.js +76 -1
  17. package/v2Containers/CommunicationFlow/messages.js +12 -0
  18. package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/ChannelSelectionStep.js +5 -0
  19. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +195 -19
  20. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/SenderDetails.js +37 -4
  21. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/DeliverySettingsSection.test.js +360 -0
  22. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/SenderDetails.test.js +25 -0
  23. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/deliverySettingsConfig.test.js +80 -0
  24. package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/deliverySettingsConfig.js +39 -8
  25. package/v2Containers/CreativesContainer/index.js +24 -0
  26. package/v2Containers/CreativesContainer/tests/index.test.js +82 -0
  27. package/v2Containers/Rcs/accountUtils.js +126 -0
  28. package/v2Containers/Rcs/index.js +30 -4
  29. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +108 -0
  30. package/v2Containers/Rcs/tests/accountUtils.test.js +178 -0
  31. package/v2Containers/Rcs/tests/testAndPreviewAccount.test.js +193 -0
  32. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +27 -0
  33. package/v2Containers/Templates/ChannelTypeIllustration.js +12 -0
  34. package/v2Containers/Templates/index.js +10 -5
  35. package/v2Containers/Templates/messages.js +4 -0
  36. package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +14 -2
  37. package/v2Containers/Templates/tests/index.test.js +112 -0
  38. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
@@ -153,6 +153,7 @@ function renderSection(props = {}) {
153
153
  deliverySettingsData = {},
154
154
  deliverySetting = {},
155
155
  onDeliverySettingChange,
156
+ onRcsAccountPendingChange,
156
157
  orgUnitId,
157
158
  domainPropertiesPriority,
158
159
  } = props;
@@ -163,6 +164,7 @@ function renderSection(props = {}) {
163
164
  deliverySettingsData={deliverySettingsData}
164
165
  deliverySetting={deliverySetting}
165
166
  onDeliverySettingChange={onDeliverySettingChange}
167
+ onRcsAccountPendingChange={onRcsAccountPendingChange}
166
168
  orgUnitId={orgUnitId}
167
169
  domainPropertiesPriority={domainPropertiesPriority}
168
170
  />
@@ -746,4 +748,362 @@ describe('DeliverySettingsSection — marketer flows', () => {
746
748
  });
747
749
  });
748
750
 
751
+ describe('RCS multi-account: sender bound to the template account', () => {
752
+ const rcsDomain = (id, sourceAccountIdentifier, sender) => ({
753
+ domainProperties: {
754
+ id,
755
+ domainName: `RCS ${sourceAccountIdentifier}`,
756
+ connectionProperties: { sourceAccountIdentifier },
757
+ contactInfo: [{
758
+ type: 'gsm_sender_id', value: sender, valid: true, default: true,
759
+ }],
760
+ },
761
+ });
762
+ const multiAccountRcsEntity = { RCS: [rcsDomain(11, 'acc-A', '+rcsA'), rcsDomain(12, 'acc-B', '+rcsB')] };
763
+ const lastRcsSetting = (onChange) => onChange.mock.calls[onChange.mock.calls.length - 1][0].channelSetting.RCS;
764
+
765
+ it('defaults the RCS sender from the picked template account domain', async () => {
766
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
767
+ const onDeliverySettingChange = jest.fn();
768
+
769
+ renderSection({
770
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B', accountId: 13751 } }],
771
+ onDeliverySettingChange,
772
+ });
773
+
774
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
775
+ expect(lastRcsSetting(onDeliverySettingChange)).toMatchObject({ rcsSender: '+rcsB', senderMobNum: '+rcsB' });
776
+ expect(fetchWeCrmAccounts).not.toHaveBeenCalledWith('RCS');
777
+ });
778
+
779
+ it('resolves a reopened template account from its saved WeCRM accountId', async () => {
780
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
781
+ fetchWeCrmAccounts.mockImplementation((source) => Promise.resolve({
782
+ response: source === 'RCS'
783
+ ? [{ id: 13750, sourceAccountIdentifier: 'acc-A' }, { id: 13751, sourceAccountIdentifier: 'acc-B' }]
784
+ : [],
785
+ }));
786
+ const onDeliverySettingChange = jest.fn();
787
+
788
+ renderSection({
789
+ contentItems: [{ channel: 'RCS', templateData: { accountId: 13751 } }],
790
+ onDeliverySettingChange,
791
+ });
792
+
793
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
794
+ expect(fetchWeCrmAccounts).toHaveBeenCalledWith('RCS');
795
+ expect(lastRcsSetting(onDeliverySettingChange)).toMatchObject({ rcsSender: '+rcsB' });
796
+ });
797
+
798
+ it('shows "RCS account is not configured" and sets no RCS sender when the account has no domain', async () => {
799
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
800
+ const onDeliverySettingChange = jest.fn();
801
+
802
+ renderSection({
803
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-C' } }],
804
+ onDeliverySettingChange,
805
+ });
806
+
807
+ expect(await screen.findByText(/RCS account is not configured/)).toBeInTheDocument();
808
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
809
+ expect(screen.queryByText('+rcsB')).not.toBeInTheDocument();
810
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
811
+ });
812
+
813
+ it('re-picks the RCS sender when the template now belongs to another account', async () => {
814
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
815
+ const onDeliverySettingChange = jest.fn();
816
+
817
+ renderSection({
818
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }],
819
+ deliverySetting: { channelSetting: { RCS: { rcsSender: '+rcsA', senderMobNum: '+rcsA', smsFallbackSenderId: 'FB' } } },
820
+ onDeliverySettingChange,
821
+ });
822
+
823
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
824
+ expect(lastRcsSetting(onDeliverySettingChange)).toEqual({ rcsSender: '+rcsB', senderMobNum: '+rcsB', smsFallbackSenderId: 'FB' });
825
+ });
826
+
827
+ it('never shows the previous account\'s saved RCS sender in the summary', async () => {
828
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
829
+
830
+ // Parent never applies the corrected setting: the stale +rcsA must still not be displayed.
831
+ renderSection({
832
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }],
833
+ deliverySetting: { channelSetting: { RCS: { rcsSender: '+rcsA', senderMobNum: '+rcsA' } } },
834
+ onDeliverySettingChange: jest.fn(),
835
+ });
836
+
837
+ expect(await screen.findByText('+rcsB')).toBeInTheDocument();
838
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
839
+ });
840
+
841
+ it('shows no RCS sender in the summary when the new account has no domain', async () => {
842
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
843
+
844
+ renderSection({
845
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-C' } }],
846
+ deliverySetting: { channelSetting: { RCS: { rcsSender: '+rcsA', senderMobNum: '+rcsA' } } },
847
+ onDeliverySettingChange: jest.fn(),
848
+ });
849
+
850
+ expect(await screen.findByText(/RCS account is not configured/)).toBeInTheDocument();
851
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
852
+ });
853
+
854
+ it('keeps a saved RCS sender that belongs to the template account', async () => {
855
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
856
+ const onDeliverySettingChange = jest.fn();
857
+
858
+ renderSection({
859
+ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }],
860
+ deliverySetting: { channelSetting: { RCS: { rcsSender: '+rcsB', senderMobNum: '+rcsB' } } },
861
+ onDeliverySettingChange,
862
+ });
863
+
864
+ expect(await screen.findByText('+rcsB')).toBeInTheDocument();
865
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
866
+ });
867
+
868
+ it('does not sync a first-domain sender when the account lookup fails, and retries on demand', async () => {
869
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
870
+ fetchWeCrmAccounts.mockImplementation((source) => (source === 'RCS'
871
+ ? Promise.reject(new Error('down'))
872
+ : Promise.resolve({ response: [] })));
873
+ const onDeliverySettingChange = jest.fn();
874
+
875
+ renderSection({
876
+ contentItems: [{ channel: 'RCS', templateData: { accountId: 13751 } }],
877
+ onDeliverySettingChange,
878
+ });
879
+
880
+ expect(await screen.findByText('Could not load the RCS account of this template.')).toBeInTheDocument();
881
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
882
+
883
+ fetchWeCrmAccounts.mockImplementation((source) => Promise.resolve({
884
+ response: source === 'RCS' ? [{ id: 13751, sourceAccountIdentifier: 'acc-B' }] : [],
885
+ }));
886
+ await userEvent.click(screen.getByText('Retry'));
887
+
888
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
889
+ expect(lastRcsSetting(onDeliverySettingChange)).toMatchObject({ rcsSender: '+rcsB' });
890
+ expect(screen.queryByText('Could not load the RCS account of this template.')).not.toBeInTheDocument();
891
+ });
892
+
893
+ it('shows no RCS sender in the summary and reports pending while the account lookup fails', async () => {
894
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
895
+ fetchWeCrmAccounts.mockImplementation((source) => (source === 'RCS'
896
+ ? Promise.reject(new Error('down'))
897
+ : Promise.resolve({ response: [] })));
898
+ const onRcsAccountPendingChange = jest.fn();
899
+
900
+ renderSection({
901
+ contentItems: [{ channel: 'RCS', templateData: { accountId: 13751 } }],
902
+ // Sender saved for account A; the template's account (13751) is unresolved.
903
+ deliverySetting: { channelSetting: { RCS: { rcsSender: '+rcsA', senderMobNum: '+rcsA' } } },
904
+ onDeliverySettingChange: jest.fn(),
905
+ onRcsAccountPendingChange,
906
+ });
907
+
908
+ expect(await screen.findByText('Could not load the RCS account of this template.')).toBeInTheDocument();
909
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
910
+ expect(screen.queryByText('+rcsB')).not.toBeInTheDocument();
911
+ expect(onRcsAccountPendingChange).toHaveBeenLastCalledWith(true);
912
+
913
+ fetchWeCrmAccounts.mockImplementation((source) => Promise.resolve({
914
+ response: source === 'RCS' ? [{ id: 13751, sourceAccountIdentifier: 'acc-B' }] : [],
915
+ }));
916
+ await userEvent.click(screen.getByText('Retry'));
917
+ expect(await screen.findByText('+rcsB')).toBeInTheDocument();
918
+ expect(onRcsAccountPendingChange).toHaveBeenLastCalledWith(false);
919
+ });
920
+
921
+ it('waits for the RCS domains when RCS is added after SMS domains loaded (no stale message / sender clear)', async () => {
922
+ const rcsTemplate = { channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } };
923
+ const savedRcs = { RCS: { rcsSender: '+rcsB', senderMobNum: '+rcsB' } };
924
+ const onDeliverySettingChange = jest.fn();
925
+ const renderWith = (contentItems) => (
926
+ <IntlProvider locale="en" messages={{}} defaultLocale="en">
927
+ <DeliverySettingsSection
928
+ contentItems={contentItems}
929
+ deliverySettingsData={{}}
930
+ deliverySetting={{ channelSetting: { SMS: { gsmSenderId: '+1002003001' }, ...savedRcs } }}
931
+ onDeliverySettingChange={onDeliverySettingChange}
932
+ />
933
+ </IntlProvider>
934
+ );
935
+ getDomainProperties.mockResolvedValueOnce({ entity: apiEntity.SMS });
936
+ const { rerender } = render(renderWith([{ channel: 'SMS' }]));
937
+ expect(await screen.findByText('+1002003001')).toBeInTheDocument();
938
+ onDeliverySettingChange.mockClear();
939
+
940
+ let resolveRcsDomains;
941
+ getDomainProperties.mockReturnValueOnce(new Promise((resolve) => { resolveRcsDomains = resolve; }));
942
+ rerender(renderWith([{ channel: 'SMS' }, rcsTemplate]));
943
+ await waitFor(() => expect(getDomainProperties).toHaveBeenCalledTimes(2));
944
+ // SMS-only response still loaded: no "not configured" and the saved RCS sender is not cleared.
945
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
946
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
947
+
948
+ resolveRcsDomains({ entity: { ...apiEntity.SMS, ...multiAccountRcsEntity } });
949
+ expect(await screen.findByText('+rcsB')).toBeInTheDocument();
950
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
951
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
952
+ });
953
+
954
+ it('still defaults the other channels (SMS) while the RCS account lookup fails', async () => {
955
+ getDomainProperties.mockResolvedValue({ entity: { ...apiEntity.SMS, ...multiAccountRcsEntity } });
956
+ fetchWeCrmAccounts.mockImplementation((source) => (source === 'RCS'
957
+ ? Promise.reject(new Error('down'))
958
+ : Promise.resolve({ response: [] })));
959
+ const onDeliverySettingChange = jest.fn();
960
+
961
+ renderSection({
962
+ contentItems: [{ channel: 'SMS' }, { channel: 'RCS', templateData: { accountId: 13751 } }],
963
+ onDeliverySettingChange,
964
+ });
965
+
966
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
967
+ const { channelSetting } = onDeliverySettingChange.mock.calls[onDeliverySettingChange.mock.calls.length - 1][0];
968
+ expect(channelSetting.SMS).toMatchObject({ gsmSenderId: '+1002003001' });
969
+ expect(channelSetting.RCS).toBeUndefined();
970
+ });
971
+
972
+ it('saved accountId, two accounts\' domains, failed lookup, no saved sender: no first-domain RCS sender in the summary or on save', async () => {
973
+ getDomainProperties.mockResolvedValue({ entity: { ...apiEntity.SMS, ...multiAccountRcsEntity } });
974
+ fetchWeCrmAccounts.mockImplementation((source) => (source === 'RCS'
975
+ ? Promise.reject(new Error('down'))
976
+ : Promise.resolve({ response: [] })));
977
+ const onDeliverySettingChange = jest.fn();
978
+
979
+ renderSection({
980
+ contentItems: [{
981
+ channel: 'RCS',
982
+ templateData: { accountId: 13751, smsFallBackContent: { message: 'Fallback SMS body' } },
983
+ }],
984
+ onDeliverySettingChange,
985
+ });
986
+
987
+ expect(await screen.findByText('Could not load the RCS account of this template.')).toBeInTheDocument();
988
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
989
+ expect(screen.queryByText('+rcsB')).not.toBeInTheDocument();
990
+
991
+ // Save from the slidebox (changing the SMS-fallback sender) must not persist the first domain's RCS sender.
992
+ onDeliverySettingChange.mockClear();
993
+ await openSenderDetailsFromSummary();
994
+ const slidebox = document.querySelector('.sender-details');
995
+ // Account unresolved: the slidebox shows no RCS account name (not the first domain's, of account A).
996
+ expect(within(slidebox).queryByText('RCS acc-A')).not.toBeInTheDocument();
997
+ expect(within(slidebox).queryByText('RCS acc-B')).not.toBeInTheDocument();
998
+ const combos = within(slidebox).getAllByRole('combobox');
999
+ await userEvent.click(combos[combos.length - 1]);
1000
+ await waitFor(() => expect(screen.getByRole('listbox')).toBeInTheDocument());
1001
+ await userEvent.click(await findVisibleSelectOption('+1002003002'));
1002
+ const saveBtn = within(slidebox).getByRole('button', { name: /save changes/i });
1003
+ await waitFor(() => expect(saveBtn).not.toBeDisabled());
1004
+ await userEvent.click(saveBtn);
1005
+
1006
+ expect(onDeliverySettingChange).toHaveBeenCalled();
1007
+ const savedRcs = onDeliverySettingChange.mock.calls[0][0].channelSetting.RCS;
1008
+ expect(savedRcs).toMatchObject({ rcsSender: '', senderMobNum: '', smsFallbackSenderId: '+1002003002' });
1009
+ });
1010
+
1011
+ it('opening the slidebox while RCS domains are loading after SMS shows the spinner, not "not configured"', async () => {
1012
+ const renderWith = (contentItems) => (
1013
+ <IntlProvider locale="en" messages={{}} defaultLocale="en">
1014
+ <DeliverySettingsSection
1015
+ contentItems={contentItems}
1016
+ deliverySettingsData={{}}
1017
+ deliverySetting={{ channelSetting: { SMS: { gsmSenderId: '+1002003001' } } }}
1018
+ onDeliverySettingChange={jest.fn()}
1019
+ />
1020
+ </IntlProvider>
1021
+ );
1022
+ getDomainProperties.mockResolvedValueOnce({ entity: apiEntity.SMS });
1023
+ const { rerender } = render(renderWith([{ channel: 'SMS' }]));
1024
+ expect(await screen.findByText('+1002003001')).toBeInTheDocument();
1025
+
1026
+ let resolveRcsDomains;
1027
+ getDomainProperties.mockReturnValueOnce(new Promise((resolve) => { resolveRcsDomains = resolve; }));
1028
+ rerender(renderWith([{ channel: 'SMS' }, { channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }]));
1029
+ await waitFor(() => expect(getDomainProperties).toHaveBeenCalledTimes(2));
1030
+
1031
+ await openSenderDetailsFromSummary();
1032
+ // Previous SMS-only response must not be treated as "no RCS domains" inside the slidebox.
1033
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
1034
+
1035
+ resolveRcsDomains({ entity: { ...apiEntity.SMS, ...multiAccountRcsEntity } });
1036
+ expect(await screen.findByText('RCS acc-B')).toBeInTheDocument();
1037
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
1038
+ });
1039
+
1040
+ it('starts the request for a new channel set while the previous request is still in flight', async () => {
1041
+ const renderWith = (contentItems) => (
1042
+ <IntlProvider locale="en" messages={{}} defaultLocale="en">
1043
+ <DeliverySettingsSection
1044
+ contentItems={contentItems}
1045
+ deliverySettingsData={{}}
1046
+ deliverySetting={{}}
1047
+ onDeliverySettingChange={jest.fn()}
1048
+ />
1049
+ </IntlProvider>
1050
+ );
1051
+ let resolveSmsDomains;
1052
+ getDomainProperties.mockReturnValueOnce(new Promise((resolve) => { resolveSmsDomains = resolve; }));
1053
+ const { rerender } = render(renderWith([{ channel: 'SMS' }]));
1054
+ await waitFor(() => expect(getDomainProperties).toHaveBeenCalledTimes(1));
1055
+
1056
+ // Channel set changes before the SMS request settles: the SMS + RCS request must still be issued.
1057
+ getDomainProperties.mockResolvedValueOnce({ entity: { ...apiEntity.SMS, ...multiAccountRcsEntity } });
1058
+ rerender(renderWith([{ channel: 'SMS' }, { channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }]));
1059
+ await waitFor(() => expect(getDomainProperties).toHaveBeenCalledTimes(2));
1060
+ expect(getDomainProperties).toHaveBeenLastCalledWith(['SMS', 'RCS'], 'test-ou', undefined);
1061
+ expect(await screen.findByText('+rcsB')).toBeInTheDocument();
1062
+
1063
+ // The superseded SMS-only response arriving late is ignored.
1064
+ resolveSmsDomains({ entity: apiEntity.SMS });
1065
+ await waitFor(() => expect(screen.getByText('+rcsB')).toBeInTheDocument());
1066
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
1067
+ });
1068
+
1069
+ it('treats a saved account that is no longer in WeCRM as not configured (no first-domain sender)', async () => {
1070
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
1071
+ fetchWeCrmAccounts.mockImplementation((source) => Promise.resolve({
1072
+ response: source === 'RCS' ? [{ id: 13750, sourceAccountIdentifier: 'acc-A' }] : [],
1073
+ }));
1074
+ const onDeliverySettingChange = jest.fn();
1075
+
1076
+ renderSection({
1077
+ contentItems: [{ channel: 'RCS', templateData: { accountId: 99999 } }],
1078
+ onDeliverySettingChange,
1079
+ });
1080
+
1081
+ expect(await screen.findByText(/RCS account is not configured/)).toBeInTheDocument();
1082
+ expect(screen.queryByText('+rcsA')).not.toBeInTheDocument();
1083
+ expect(onDeliverySettingChange).not.toHaveBeenCalled();
1084
+ });
1085
+
1086
+ it('shows "RCS account is not configured" for a known account once the RCS domain list settles empty', async () => {
1087
+ let resolveDomains;
1088
+ getDomainProperties.mockReturnValue(new Promise((resolve) => { resolveDomains = resolve; }));
1089
+
1090
+ renderSection({ contentItems: [{ channel: 'RCS', templateData: { sourceAccountIdentifier: 'acc-B' } }] });
1091
+
1092
+ expect(await screen.findByText('Sender details')).toBeInTheDocument();
1093
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
1094
+ resolveDomains({ entity: { RCS: [] } });
1095
+ expect(await screen.findByText(/RCS account is not configured/)).toBeInTheDocument();
1096
+ });
1097
+
1098
+ it('uses the first RCS domain when the template account is unknown (old data)', async () => {
1099
+ getDomainProperties.mockResolvedValue({ entity: multiAccountRcsEntity });
1100
+ const onDeliverySettingChange = jest.fn();
1101
+
1102
+ renderSection({ contentItems: [{ channel: 'RCS', templateData: {} }], onDeliverySettingChange });
1103
+
1104
+ await waitFor(() => expect(onDeliverySettingChange).toHaveBeenCalled());
1105
+ expect(lastRcsSetting(onDeliverySettingChange)).toMatchObject({ rcsSender: '+rcsA' });
1106
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
1107
+ });
1108
+ });
749
1109
  });
@@ -724,3 +724,28 @@ describe('SenderDetails', () => {
724
724
  await waitFor(() => expect(within(root).getByText('+1002003001')).toBeInTheDocument());
725
725
  });
726
726
  });
727
+
728
+ describe('SenderDetails — RCS multi-account', () => {
729
+ const rcsDomain = (sourceAccountIdentifier, sender) => ({
730
+ domainProperties: {
731
+ domainName: `RCS ${sourceAccountIdentifier}`,
732
+ connectionProperties: { sourceAccountIdentifier },
733
+ contactInfo: [{
734
+ type: 'gsm_sender_id', value: sender, valid: true, default: true,
735
+ }],
736
+ },
737
+ });
738
+ const entity = { RCS: [rcsDomain('acc-A', '+rcsA'), rcsDomain('acc-B', '+rcsB')] };
739
+
740
+ it('shows the RCS account of the template domain', async () => {
741
+ renderSenderDetails({ channels: ['RCS'], preloadedDomainProperties: entity, rcsSourceAccountId: 'acc-B' });
742
+ expect(await screen.findByText('RCS acc-B')).toBeInTheDocument();
743
+ expect(screen.queryByText(/RCS account is not configured/)).not.toBeInTheDocument();
744
+ });
745
+
746
+ it('shows "RCS account is not configured" when the template account has no domain', async () => {
747
+ renderSenderDetails({ channels: ['RCS'], preloadedDomainProperties: entity, rcsSourceAccountId: 'acc-C' });
748
+ expect(await screen.findByText(/RCS account is not configured/)).toBeInTheDocument();
749
+ expect(screen.queryByText('RCS acc-A')).not.toBeInTheDocument();
750
+ });
751
+ });
@@ -29,6 +29,8 @@ import {
29
29
  hasRcsSmsFallbackContent,
30
30
  getRcsSmsFallbackDefaultDomain,
31
31
  getRcsSmsFallbackBodyText,
32
+ isRcsAccountNotConfiguredForEntity,
33
+ getRcsSenderValuesForAccount,
32
34
  } from '../deliverySettingsConfig';
33
35
 
34
36
  /** Typical campaigns `domainProperties` entity: channel keys → list of gateway rows */
@@ -340,6 +342,84 @@ describe('deliverySettingsConfig — user-facing flows', () => {
340
342
  });
341
343
  });
342
344
 
345
+ describe('RCS: multi-account binding by sourceAccountIdentifier', () => {
346
+ const rcsRow = (domainName, sender, connectionProperties) => ({
347
+ domainProperties: {
348
+ domainName,
349
+ ...(connectionProperties && { connectionProperties }),
350
+ contactInfo: [{
351
+ type: 'gsm_sender_id', value: sender, valid: true, default: true,
352
+ }],
353
+ },
354
+ });
355
+ const multiAccountEntity = {
356
+ RCS: [
357
+ rcsRow('Brand A', '+rcsA', { sourceAccountIdentifier: 'acc-A' }),
358
+ rcsRow('Brand B', '+rcsB', { sourceAccountIdentifier: 'acc-B' }),
359
+ ],
360
+ };
361
+
362
+ it('binds account name and sender number to the template account domain', () => {
363
+ expect(getRcsAccountName(multiAccountEntity, 'acc-B')).toBe('Brand B');
364
+ const summary = parseEntityForDisplay(multiAccountEntity, { rcsSourceAccountId: 'acc-B' });
365
+ expect(summary.rcsAccountName).toBe('Brand B');
366
+ expect(summary.rcsSenderNumber).toBe('+rcsB');
367
+ expect(summary.senderNumber).toBe('+rcsB');
368
+ });
369
+
370
+ it('gives no account name or sender when the account has no domain (account not configured)', () => {
371
+ expect(getRcsAccountName(multiAccountEntity, 'acc-C')).toBe('');
372
+ const summary = parseEntityForDisplay(multiAccountEntity, { rcsSourceAccountId: 'acc-C' });
373
+ expect(summary.rcsSenderNumber).toBe('');
374
+ expect(summary.rcsAccountName).toBe('');
375
+ expect(isRcsAccountNotConfiguredForEntity(multiAccountEntity, 'acc-C')).toBe(true);
376
+ expect(isRcsAccountNotConfiguredForEntity(multiAccountEntity, 'acc-B')).toBe(false);
377
+ expect(isRcsAccountNotConfiguredForEntity(multiAccountEntity, '')).toBe(false);
378
+ });
379
+
380
+ it('uses the only RCS domain when it carries no account id (legacy single-domain org)', () => {
381
+ const legacyEntity = { RCS: [rcsRow('Legacy', '+rcsL')] };
382
+ expect(getRcsAccountName(legacyEntity, 'acc-A')).toBe('Legacy');
383
+ expect(parseEntityForDisplay(legacyEntity, { rcsSourceAccountId: 'acc-A' }).rcsSenderNumber).toBe('+rcsL');
384
+ expect(isRcsAccountNotConfiguredForEntity(legacyEntity, 'acc-A')).toBe(false);
385
+ });
386
+
387
+ it('lists only the senders of the account domain', () => {
388
+ expect(getRcsSenderValuesForAccount(multiAccountEntity, 'acc-B')).toEqual(['+rcsB']);
389
+ expect(getRcsSenderValuesForAccount(multiAccountEntity, 'acc-C')).toEqual([]);
390
+ });
391
+
392
+ it('lists the senders of every domain of the account', () => {
393
+ const entity = {
394
+ RCS: [
395
+ rcsRow('Brand A', '+rcsA', { sourceAccountIdentifier: 'acc-A' }),
396
+ rcsRow('Brand B 1', '+rcsB1', { sourceAccountIdentifier: 'acc-B' }),
397
+ rcsRow('Brand B 2', '+rcsB2', { sourceAccountIdentifier: 'acc-B' }),
398
+ ],
399
+ };
400
+ expect(getRcsSenderValuesForAccount(entity, 'acc-B')).toEqual(['+rcsB1', '+rcsB2']);
401
+ });
402
+
403
+ it('reports a known account as not configured for a settled empty RCS list, but not while not loaded', () => {
404
+ expect(isRcsAccountNotConfiguredForEntity({ RCS: [] }, 'acc-B')).toBe(true);
405
+ expect(isRcsAccountNotConfiguredForEntity({}, 'acc-B')).toBe(true);
406
+ expect(isRcsAccountNotConfiguredForEntity(null, 'acc-B')).toBe(false);
407
+ expect(isRcsAccountNotConfiguredForEntity({ RCS: [] }, '')).toBe(false);
408
+ });
409
+
410
+ it('falls back to the first RCS domain when no account is passed (single-account behaviour)', () => {
411
+ expect(getRcsAccountName(multiAccountEntity)).toBe('Brand A');
412
+ expect(parseEntityForDisplay(multiAccountEntity).rcsSenderNumber).toBe('+rcsA');
413
+ });
414
+
415
+ it('does not let the RCS account change the WhatsApp sender number', () => {
416
+ const combined = { ...domainPropertiesFromApi, RCS: multiAccountEntity.RCS };
417
+ const summary = parseEntityForDisplay(combined, { rcsSourceAccountId: 'acc-B' });
418
+ expect(summary.senderNumber).toBe('+wa1');
419
+ expect(summary.rcsSenderNumber).toBe('+rcsB');
420
+ });
421
+ });
422
+
343
423
  describe('Viber: gateway id 0 + alternate API sender types', () => {
344
424
  it('uses viber_sender_id when GSM is not present (API variance)', () => {
345
425
  const entity = domainPropertiesFromApi;
@@ -26,6 +26,7 @@
26
26
  import {
27
27
  SMS, EMAIL, WHATSAPP, VIBER, RCS,
28
28
  } from '../../../CreativesContainer/constants';
29
+ import { pickRcsDomainForAccount, isRcsAccountNotConfigured, getRcsDomainsForAccount } from '../../../Rcs/accountUtils';
29
30
 
30
31
  // --- Generic helpers for API response structure ---
31
32
  const toArray = (val) => {
@@ -348,15 +349,44 @@ const getWhatsappSenderNumberOptions = (entity, context = {}) => {
348
349
  return options?.map((option) => ({ label: option.value || option.label, value: option.value || option.label }));
349
350
  };
350
351
 
351
- const getRcsSenderNumberValue = (entity) => {
352
- const channelData = getChannelData(entity, 'RCS');
352
+ // --- RCS account-bound domain (multi-account) ---
353
+ // The RCS template's account (sourceAccountIdentifier) is matched against the domain's connectionProperties,
354
+ // like WhatsApp. Account unknown -> first RCS domain (pre-multi-account behaviour). Account known but no
355
+ // domain of its own -> no domain (account not configured), never another account's domain.
356
+
357
+ /** Find the RCS domain of a sourceAccountIdentifier (see pickRcsDomainForAccount) */
358
+ const getRcsDomainBySourceAccount = (entity, sourceAccountId) => pickRcsDomainForAccount(
359
+ toArray(entity?.RCS),
360
+ sourceAccountId,
361
+ getDomainSourceAccountId,
362
+ );
363
+
364
+ /**
365
+ * True when the RCS template's account is known but none of the RCS domains belongs to it (an empty RCS domain
366
+ * list included). `entity` is the settled domainProperties response: false while it is not loaded (pending /
367
+ * failed), so DeliverySettingsSection — which owns this message — stays silent until the request settles.
368
+ */
369
+ export const isRcsAccountNotConfiguredForEntity = (entity, sourceAccountId) => {
370
+ if (!entity) return false;
371
+ return isRcsAccountNotConfigured(toArray(entity?.RCS), sourceAccountId, getDomainSourceAccountId);
372
+ };
373
+
374
+ /** Sender values of every RCS domain of the template account ([] when the account has no domain). */
375
+ export const getRcsSenderValuesForAccount = (entity, sourceAccountId) => getRcsDomainsForAccount(
376
+ toArray(entity?.RCS),
377
+ sourceAccountId,
378
+ getDomainSourceAccountId,
379
+ ).flatMap((domain) => getOptionsFromContactInfo(domain, 'gsm_sender_id', ['cdma_sender_id'])?.map((option) => option.value) || []);
380
+
381
+ const getRcsSenderNumberValue = (entity, context = {}) => {
382
+ const channelData = getRcsDomainBySourceAccount(entity, context?.rcsSourceAccountId);
353
383
  if (!channelData) return '';
354
384
  return getValueFromContactInfo(channelData, 'gsm_sender_id', ['cdma_sender_id']);
355
385
  };
356
386
 
357
- /** Get RCS account name from first domain (like campaigns-v2: rcsSender display) */
358
- export const getRcsAccountName = (entity) => {
359
- const rcsData = getChannelData(entity, 'RCS');
387
+ /** Get RCS account name from the account's domain (like campaigns-v2: rcsSender display) */
388
+ export const getRcsAccountName = (entity, sourceAccountId = '') => {
389
+ const rcsData = getRcsDomainBySourceAccount(entity, sourceAccountId);
360
390
  if (!rcsData) return '';
361
391
  return rcsData.domainProperties?.domainName || rcsData.domainName || rcsData.label || '';
362
392
  };
@@ -623,6 +653,7 @@ export const getFieldsForChannels = (channels = []) => {
623
653
  export const parseEntityForDisplay = (entity, context = {}) => {
624
654
  if (!entity) return null;
625
655
  const whatsappSourceAccountId = context?.whatsappSourceAccountId || '';
656
+ const rcsSourceAccountId = context?.rcsSourceAccountId || '';
626
657
  return {
627
658
  senderDetails: entity,
628
659
  smsSenderId: getSmsSenderIdValue(entity),
@@ -637,12 +668,12 @@ export const parseEntityForDisplay = (entity, context = {}) => {
637
668
  lineSenderId: getSenderIdFromContactInfo(entity, 'LINE'),
638
669
  whatsappSenderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }),
639
670
  whatsappAccountName: getWhatsappAccountName(entity, whatsappSourceAccountId),
640
- rcsSenderNumber: getRcsSenderNumberValue(entity),
641
- rcsAccountName: getRcsAccountName(entity),
671
+ rcsSenderNumber: getRcsSenderNumberValue(entity, { rcsSourceAccountId }),
672
+ rcsAccountName: getRcsAccountName(entity, rcsSourceAccountId),
642
673
  // RCS SMS-fallback: sourced from the SMS domain data (same as the SMS channel's own fields).
643
674
  rcsSmsFallbackDomain: getSmsDomainValue(entity),
644
675
  rcsSmsFallbackSenderId: getSmsSenderIdValue(entity),
645
- senderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }) || getRcsSenderNumberValue(entity),
676
+ senderNumber: getWhatsappSenderNumberValue(entity, { whatsappSourceAccountId }) || getRcsSenderNumberValue(entity, { rcsSourceAccountId }),
646
677
  };
647
678
  };
648
679
 
@@ -92,6 +92,7 @@ import { IMAGE, VIDEO } from '../Facebook/Advertisement/constant';
92
92
  import { RCS_STATUSES, contentType as RCS_CONTENT_TYPE, EMBEDDED } from '../Rcs/constants';
93
93
  import { pickRcsCardVarMappedEntries } from '../Rcs/rcsLibraryHydrationUtils';
94
94
  import { mapRcsCardContentForConsumerWithResolvedTags } from '../Rcs/utils';
95
+ import { isRcsAccountForAccountId } from '../Rcs/accountUtils';
95
96
  import { RCS_SMS_FALLBACK_VAR_MAPPED_PROP } from '../../v2Components/CommonTestAndPreview/constants';
96
97
  import { CREATIVE } from '../Facebook/constants';
97
98
  import { LOYALTY } from '../App/constants';
@@ -1480,11 +1481,34 @@ export class Creatives extends React.Component {
1480
1481
  cardVarMappedFromFirstRcsCard
1481
1482
  && Object.keys(cardVarMappedFromFirstRcsCard).length > 0
1482
1483
  && isFullModeForRcsConsumerPayload === true;
1484
+ // Multi-account (same contract as WhatsApp): tell the consumer which RCS account the template
1485
+ // belongs to. Use the selected account only when it is the one the template was saved with;
1486
+ // otherwise use the consumer-passed account only when it is verified to be this template's
1487
+ // accountId, else omit both fields — a stale selection or stale metadata never re-tags a template.
1488
+ const { Templates: templatesForRcsAccount, templateData: rcsTemplateDataProps } = this.props;
1489
+ const selectedRcsAccount = templatesForRcsAccount?.selectedRcsAccount;
1490
+ const isSelectedRcsAccountForTemplate = !isEmpty(selectedRcsAccount)
1491
+ && (!accountId || isRcsAccountForAccountId(selectedRcsAccount, accountId));
1492
+ const consumerRcsAccount = {
1493
+ id: rcsTemplateDataProps?.accountDetails?.id ?? rcsTemplateDataProps?.accountId,
1494
+ sourceAccountIdentifier: rcsTemplateDataProps?.sourceAccountIdentifier
1495
+ || rcsTemplateDataProps?.accountDetails?.sourceAccountIdentifier,
1496
+ name: rcsTemplateDataProps?.accountName || rcsTemplateDataProps?.accountDetails?.name,
1497
+ };
1498
+ const isConsumerRcsAccountForTemplate = !isSelectedRcsAccountForTemplate
1499
+ && isRcsAccountForAccountId(consumerRcsAccount, accountId);
1500
+ let rcsAccountForPayload = null;
1501
+ if (isSelectedRcsAccountForTemplate) rcsAccountForPayload = selectedRcsAccount;
1502
+ else if (isConsumerRcsAccountForTemplate) rcsAccountForPayload = consumerRcsAccount;
1503
+ const rcsSourceAccountIdentifier = rcsAccountForPayload?.sourceAccountIdentifier || '';
1504
+ const rcsAccountName = rcsAccountForPayload?.name || '';
1483
1505
  templateData = {
1484
1506
  channel,
1485
1507
  creativeName: name,
1486
1508
  rcsContent,
1487
1509
  accountId,
1510
+ ...(rcsSourceAccountIdentifier && { sourceAccountIdentifier: rcsSourceAccountIdentifier }),
1511
+ ...(rcsAccountName && { accountName: rcsAccountName }),
1488
1512
  ...(vfTemplateId && { templateId: vfTemplateId }),
1489
1513
  ...(includeRootRcsCardVarMappedOnConsumerPayload
1490
1514
  ? { rcsCardVarMapped: cardVarMappedFromFirstRcsCard }