@@ -13,6 +13,7 @@ import { userSettingsSelector } from 'uiSrc/slices/user/user-settings'
13
13
import { addInfiniteNotification } from 'uiSrc/slices/app/notifications'
14
14
import { INFINITE_MESSAGES } from 'uiSrc/components/notifications/components'
15
15
import { Pages } from 'uiSrc/constants'
16
+ import { ADD_NEW , ADD_NEW_CA_CERT } from 'uiSrc/pages/home/constants'
16
17
import { UrlHandlingActions } from 'uiSrc/slices/interfaces/urlHandling'
17
18
import GlobalUrlHandler from './GlobalUrlHandler'
18
19
@@ -131,7 +132,9 @@ describe('GlobalUrlHandler', () => {
131
132
password : 'password' ,
132
133
port : 6379 ,
133
134
tls : false ,
134
- username : undefined
135
+ username : undefined ,
136
+ caCert : undefined ,
137
+ clientCert : undefined ,
135
138
}
136
139
} ) ,
137
140
]
@@ -141,7 +144,147 @@ describe('GlobalUrlHandler', () => {
141
144
expect ( pushMock ) . toBeCalledWith ( Pages . home )
142
145
} )
143
146
144
- it ( 'should call proper actions only after consents popup is accepted and open form to add db' , async ( ) => {
147
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with caCert' , async ( ) => {
148
+ const pushMock = jest . fn ( )
149
+ reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
150
+ ( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
151
+ config : { } ,
152
+ isShowConsents : false
153
+ } )
154
+
155
+ const url = `${ fromUrl } &requiredCaCert=true` ;
156
+
157
+ ( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
158
+ fromUrl : url
159
+ } )
160
+
161
+ await act ( ( ) => {
162
+ render ( < GlobalUrlHandler /> )
163
+ } )
164
+
165
+ const actionUrl = new URL ( url )
166
+ const fromParams = new URLSearchParams ( actionUrl . search )
167
+ // @ts -ignore
168
+ const urlProperties = Object . fromEntries ( fromParams ) || { }
169
+ urlProperties . cloudId = urlProperties . cloudBdbId
170
+ delete urlProperties . cloudBdbId
171
+
172
+ const expectedActions = [
173
+ setUrlProperties ( urlProperties ) ,
174
+ setFromUrl ( null ) ,
175
+ setUrlDbConnection ( {
176
+ action : UrlHandlingActions . Connect ,
177
+ dbConnection : {
178
+ host : 'localhost' ,
179
+ name : 'My Name' ,
180
+ password : 'password' ,
181
+ port : 6379 ,
182
+ tls : true ,
183
+ caCert : { id : ADD_NEW_CA_CERT } ,
184
+ username : 'default' ,
185
+ }
186
+ } )
187
+ ]
188
+
189
+ expect ( store . getActions ( ) . slice ( 0 , expectedActions . length ) ) . toEqual ( expectedActions )
190
+ expect ( pushMock ) . toBeCalledWith ( Pages . home )
191
+ } )
192
+
193
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with client cert' , async ( ) => {
194
+ const pushMock = jest . fn ( )
195
+ reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
196
+ ( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
197
+ config : { } ,
198
+ isShowConsents : false
199
+ } )
200
+
201
+ const url = `${ fromUrl } &requiredClientCert=true` ;
202
+
203
+ ( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
204
+ fromUrl : url
205
+ } )
206
+
207
+ await act ( ( ) => {
208
+ render ( < GlobalUrlHandler /> )
209
+ } )
210
+
211
+ const actionUrl = new URL ( url )
212
+ const fromParams = new URLSearchParams ( actionUrl . search )
213
+ // @ts -ignore
214
+ const urlProperties = Object . fromEntries ( fromParams ) || { }
215
+ urlProperties . cloudId = urlProperties . cloudBdbId
216
+ delete urlProperties . cloudBdbId
217
+
218
+ const expectedActions = [
219
+ setUrlProperties ( urlProperties ) ,
220
+ setFromUrl ( null ) ,
221
+ setUrlDbConnection ( {
222
+ action : UrlHandlingActions . Connect ,
223
+ dbConnection : {
224
+ host : 'localhost' ,
225
+ name : 'My Name' ,
226
+ password : 'password' ,
227
+ port : 6379 ,
228
+ tls : true ,
229
+ caCert : undefined ,
230
+ clientCert : { id : ADD_NEW } ,
231
+ username : 'default' ,
232
+ }
233
+ } )
234
+ ]
235
+
236
+ expect ( store . getActions ( ) . slice ( 0 , expectedActions . length ) ) . toEqual ( expectedActions )
237
+ expect ( pushMock ) . toBeCalledWith ( Pages . home )
238
+ } )
239
+
240
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with tls certs' , async ( ) => {
241
+ const pushMock = jest . fn ( )
242
+ reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
243
+ ( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
244
+ config : { } ,
245
+ isShowConsents : false
246
+ } )
247
+
248
+ const url = `${ fromUrl } &requiredCaCert=true&requiredClientCert=true` ;
249
+
250
+ ( appRedirectionSelector as jest . Mock ) . mockReturnValueOnce ( {
251
+ fromUrl : url
252
+ } )
253
+
254
+ await act ( ( ) => {
255
+ render ( < GlobalUrlHandler /> )
256
+ } )
257
+
258
+ const actionUrl = new URL ( url )
259
+ const fromParams = new URLSearchParams ( actionUrl . search )
260
+ // @ts -ignore
261
+ const urlProperties = Object . fromEntries ( fromParams ) || { }
262
+ urlProperties . cloudId = urlProperties . cloudBdbId
263
+ delete urlProperties . cloudBdbId
264
+
265
+ const expectedActions = [
266
+ setUrlProperties ( urlProperties ) ,
267
+ setFromUrl ( null ) ,
268
+ setUrlDbConnection ( {
269
+ action : UrlHandlingActions . Connect ,
270
+ dbConnection : {
271
+ host : 'localhost' ,
272
+ name : 'My Name' ,
273
+ password : 'password' ,
274
+ port : 6379 ,
275
+ tls : true ,
276
+ caCert : { id : ADD_NEW_CA_CERT } ,
277
+ clientCert : { id : ADD_NEW } ,
278
+ username : 'default' ,
279
+ }
280
+ } )
281
+ ]
282
+
283
+ expect ( store . getActions ( ) . slice ( 0 , expectedActions . length ) ) . toEqual ( expectedActions )
284
+ expect ( pushMock ) . toBeCalledWith ( Pages . home )
285
+ } )
286
+
287
+ it ( 'should call proper actions only after consents popup is accepted and open form to add db with tls' , async ( ) => {
145
288
const pushMock = jest . fn ( )
146
289
reactRouterDom . useHistory = jest . fn ( ) . mockReturnValueOnce ( { push : pushMock } ) ;
147
290
( userSettingsSelector as jest . Mock ) . mockReturnValueOnce ( {
@@ -177,6 +320,8 @@ describe('GlobalUrlHandler', () => {
177
320
password : 'password' ,
178
321
port : 6379 ,
179
322
tls : true ,
323
+ caCert : undefined ,
324
+ clientCert : undefined ,
180
325
username : 'default' ,
181
326
}
182
327
} )
0 commit comments