11import { getConnectionCookie } from '../cookies' ;
2+ import { getCurrentConnectionInfo } from '../getCurrentConnectionInfo' ;
23import {
34 ClientTypeList ,
45 TrackingEventList ,
@@ -14,16 +15,24 @@ jest.mock('../cookies', () => ({
1415 getConnectionCookie : jest . fn ( ) ,
1516} ) ) ;
1617
17- const addShare = jest . fn ( async ( ) => ( { addShare : null } ) ) ;
18- const getConnectionByIndex = jest . fn ( async ( ) => ( { connection : null } ) ) ;
19- const createDesignerProject = jest . fn ( async ( ) => ( {
20- createDesignerProject : 'id' ,
18+ jest . mock ( '../getCurrentConnectionInfo' , ( ) => ( {
19+ getCurrentConnectionInfo : jest . fn ( ) ,
2120} ) ) ;
21+
22+ const addShare = jest . fn ( async ( ) => ( { addShare : null } ) ) ;
2223const archiveDesignerProject = jest . fn ( async ( ) => ( {
2324 archiveDesignerProject : 'id' ,
2425} ) ) ;
25- const restoreDesignerProject = jest . fn ( async ( ) => ( {
26- restoreDesignerProject : 'id' ,
26+ const createDesignerProject = jest . fn ( async ( ) => ( {
27+ createDesignerProject : 'id' ,
28+ } ) ) ;
29+ const getConnectionByIndex = jest . fn ( async ( ) => ( {
30+ connection : {
31+ endpoint : 'endpoint' ,
32+ id : 'id' ,
33+ name : 'name' ,
34+ index : 0 ,
35+ } ,
2736} ) ) ;
2837const getDesignerProject = jest . fn ( async ( ) => {
2938 return {
@@ -43,6 +52,7 @@ const getVoiceboxConversation = jest.fn(async () => ({
4352 getVoiceboxConversation : null ,
4453} ) ) ;
4554const listConnections = jest . fn ( async ( ) => ( { listConnections : [ null ] } ) ) ;
55+ const listOrganizations = jest . fn ( async ( ) => ( { listOrganizations : [ null ] } ) ) ;
4656const listVoiceboxConversations = jest . fn ( async ( ) => ( {
4757 listVoiceboxConversations : null ,
4858 voiceboxConversationCount : null ,
@@ -51,6 +61,9 @@ const profile = jest.fn(async () => ({ profile: null }));
5161const renameDesignerProject = jest . fn ( async ( ) => ( {
5262 renameDesignerProject : 'id' ,
5363} ) ) ;
64+ const restoreDesignerProject = jest . fn ( async ( ) => ( {
65+ restoreDesignerProject : 'id' ,
66+ } ) ) ;
5467const trackEvent = jest . fn ( async ( ) => ( { trackEvent : null } ) ) ;
5568const updateDesignerProject = jest . fn ( async ( ) => ( {
5669 updateDesignerProject : 'id' ,
@@ -60,13 +73,14 @@ describe('getPortalSdk', () => {
6073 beforeEach ( ( ) => {
6174 jest . spyOn ( portalSdkImport , 'getSdk' ) . mockReturnValue ( {
6275 addShare,
63- getConnectionByIndex,
64- createDesignerProject,
6576 archiveDesignerProject,
77+ createDesignerProject,
78+ getConnectionByIndex,
6679 getDesignerProject,
6780 getDesignerProjects,
6881 getVoiceboxConversation,
6982 listConnections,
83+ listOrganizations,
7084 listVoiceboxConversations,
7185 profile,
7286 renameDesignerProject,
@@ -102,34 +116,122 @@ describe('getPortalSdk', () => {
102116
103117 it ( 'calls portal-sdk functions and gets return values' , async ( ) => {
104118 const sdk = getPortalSdk ( ) ;
105- const input = {
106- endpoint : 'endpoint' ,
107- expires : 100 ,
108- service : 'service' ,
109- target_path : 'target_path' ,
119+
120+ const addShareInput = {
121+ input : {
122+ endpoint : 'endpoint' ,
123+ expires : 100 ,
124+ service : 'service' ,
125+ target_path : 'target_path' ,
126+ } ,
110127 } ;
111- await sdk ?. addShare ( input ) ;
112- expect ( addShare ) . toHaveBeenCalledWith ( { input } ) ;
113- const eventInput = {
114- event : TrackingEventList . DESIGNER_CREATE_DATA_SOURCE ,
115- client_type : ClientTypeList . HUBSPOT ,
128+ await sdk ?. addShare ( addShareInput . input ) ;
129+ expect ( addShare ) . toHaveBeenCalledWith ( addShareInput ) ;
130+
131+ const createDesignerProjectInput = {
132+ name : 'name' ,
133+ content : 'content' ,
134+ connection_id : 'connectionId' ,
116135 } ;
117- await sdk ?. trackEvent ( eventInput ) ;
118- expect ( trackEvent ) . toHaveBeenCalled ( ) ;
136+ await sdk ?. createDesignerProject (
137+ createDesignerProjectInput . name ,
138+ createDesignerProjectInput . content ,
139+ createDesignerProjectInput . connection_id
140+ ) ;
141+ expect ( createDesignerProject ) . toHaveBeenCalledWith (
142+ createDesignerProjectInput
143+ ) ;
144+
145+ const archiveDesignerProjectInput = { project_id : 'projectId' } ;
146+ await sdk ?. archiveDesignerProject ( archiveDesignerProjectInput . project_id ) ;
147+ expect ( archiveDesignerProject ) . toHaveBeenCalledWith (
148+ archiveDesignerProjectInput
149+ ) ;
150+
151+ const getDesignerProjectInput = { project_id : 'projectId' } ;
152+ await sdk ?. getDesignerProject ( getDesignerProjectInput . project_id ) ;
153+ expect ( getDesignerProject ) . toHaveBeenCalledWith ( getDesignerProjectInput ) ;
154+
155+ await sdk ?. getDesignerProjects ( ) ;
156+ expect ( getDesignerProjects ) . toHaveBeenCalled ( ) ;
157+
158+ const getVoiceboxConversationInput = { conversation_id : 'conversationId' } ;
159+ await sdk ?. getVoiceboxConversation (
160+ getVoiceboxConversationInput . conversation_id
161+ ) ;
162+ expect ( getVoiceboxConversation ) . toHaveBeenCalledWith (
163+ getVoiceboxConversationInput
164+ ) ;
165+ await sdk ?. listOrganizations ( ) ;
166+ expect ( listOrganizations ) . toHaveBeenCalled ( ) ;
167+
168+ await sdk ?. listVoiceboxConversations ( ) ;
169+ expect ( listVoiceboxConversations ) . toHaveBeenCalled ( ) ;
119170
120171 await sdk ?. profile ( ) ;
121172 expect ( profile ) . toHaveBeenCalled ( ) ;
122173
123- await sdk ?. listConnections ( ) ;
124- expect ( listConnections ) . toHaveBeenCalled ( ) ;
174+ const renameDesignerProjectInput = {
175+ project_id : 'projectId' ,
176+ name : 'name' ,
177+ } ;
178+ await sdk ?. renameDesignerProject (
179+ renameDesignerProjectInput . project_id ,
180+ renameDesignerProjectInput . name
181+ ) ;
182+ expect ( renameDesignerProject ) . toHaveBeenCalledWith (
183+ renameDesignerProjectInput
184+ ) ;
185+
186+ const restoreDesignerProjectInput = { project_id : 'projectId' } ;
187+ await sdk ?. restoreDesignerProject ( restoreDesignerProjectInput . project_id ) ;
188+ expect ( restoreDesignerProject ) . toHaveBeenCalledWith (
189+ restoreDesignerProjectInput
190+ ) ;
125191
126- await sdk ?. getConnectionByIndex ( 0 ) ;
127- expect ( getConnectionByIndex ) . toHaveBeenCalledWith ( { index : 0 } ) ;
192+ await sdk ?. trackEvent ( {
193+ event : TrackingEventList . DESIGNER_CREATE_DATA_SOURCE ,
194+ client_type : ClientTypeList . HUBSPOT ,
195+ } ) ;
196+ expect ( trackEvent ) . toHaveBeenCalled ( ) ;
197+
198+ const updateDesignerProjectInput = {
199+ project_id : 'projectId' ,
200+ content : 'content' ,
201+ name : 'name' ,
202+ connection_id : 'connectionId' ,
203+ } ;
204+ await sdk ?. updateDesignerProject (
205+ updateDesignerProjectInput . project_id ,
206+ updateDesignerProjectInput . content ,
207+ updateDesignerProjectInput . name ,
208+ updateDesignerProjectInput . connection_id
209+ ) ;
210+ expect ( updateDesignerProject ) . toHaveBeenCalledWith (
211+ updateDesignerProjectInput
212+ ) ;
213+ } ) ;
214+
215+ it ( 'calls the connection portal-sdk function only when there is an org domain' , async ( ) => {
216+ const sdk = getPortalSdk ( ) ;
217+
218+ ( getCurrentConnectionInfo as jest . Mock ) . mockReturnValue ( null ) ;
219+
220+ expect ( await sdk ?. getConnectionByIndex ( 0 ) ) . toBeNull ( ) ;
221+ expect ( getConnectionByIndex ) . not . toHaveBeenCalled ( ) ;
222+
223+ expect ( await sdk ?. listConnections ( ) ) . toBeNull ( ) ;
224+ expect ( listConnections ) . not . toHaveBeenCalled ( ) ;
225+
226+ ( getCurrentConnectionInfo as jest . Mock ) . mockReturnValue ( {
227+ connectionIndex : 1 ,
228+ organizationDomain : 'orgDomain' ,
229+ } ) ;
128230
129- listConnections . mockResolvedValueOnce ( { listConnections : null as any } ) ;
130- const emptyConnectionsSdk = getPortalSdk ( ) ;
231+ expect ( await sdk ?. getConnectionByIndex ( 0 ) ) . not . toBeNull ( ) ;
232+ expect ( getConnectionByIndex ) . toHaveBeenCalled ( ) ;
131233
132- await emptyConnectionsSdk ?. listConnections ( ) ;
234+ expect ( await sdk ?. listConnections ( ) ) . not . toBeNull ( ) ;
133235 expect ( listConnections ) . toHaveBeenCalled ( ) ;
134236 } ) ;
135237} ) ;
0 commit comments