@@ -193,6 +193,33 @@ function createNamespaceAndOpenEditForm() {
193
193
cy . toolbar ( toolbarConfiguration , toolbarEditNamespace ) ;
194
194
}
195
195
196
+ function extractDomainIdAndTokenFromResponse ( interception ) {
197
+ const rawTreeObject = interception ?. response ?. body ?. reloadTrees ?. ae_tree ;
198
+ if ( rawTreeObject ) {
199
+ const rawTreeParsed = JSON . parse ( rawTreeObject ) ;
200
+ rawTreeParsed . every ( ( treeObject ) => {
201
+ // Exit iteration once id is extracted from nodes array
202
+ return treeObject ?. nodes ?. every ( ( nodeObject ) => {
203
+ if ( nodeObject ?. text === domainName ) {
204
+ const domainId = nodeObject ?. key ?. split ( '-' ) ?. [ 1 ] ;
205
+ const csrfToken = interception ?. request ?. headers ?. [ 'x-csrf-token' ] ;
206
+ const idAndToken = {
207
+ domainId,
208
+ csrfToken,
209
+ } ;
210
+ // Creating an aliased state to store id and token
211
+ cy . wrap ( idAndToken ) . as ( 'idAndToken' ) ;
212
+
213
+ // Stop iterating once the domain id is found
214
+ return false ;
215
+ }
216
+ // Continue iterating
217
+ return true ;
218
+ } ) ;
219
+ } ) ;
220
+ }
221
+ }
222
+
196
223
describe ( 'Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form' , ( ) => {
197
224
beforeEach ( ( ) => {
198
225
cy . login ( ) ;
@@ -209,7 +236,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
209
236
'addNamespaceApi'
210
237
) ;
211
238
cy . contains ( buttonSelector ( submitButtonType ) , addButton ) . click ( ) ;
212
- cy . wait ( '@addNamespaceApi' ) ;
239
+ cy . wait ( '@addNamespaceApi' ) . then ( ( interception ) => {
240
+ extractDomainIdAndTokenFromResponse ( interception ) ;
241
+ } ) ;
213
242
cy . expect_flash ( flashTypeSuccess , flashMessageAddSuccess ) ;
214
243
// Selecting the created domain from the accordion list items
215
244
selectAccordionTree ( domainName ) ;
@@ -335,15 +364,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
335
364
} ) ;
336
365
337
366
afterEach ( ( ) => {
338
- // Selecting the created domain(Test_Domain) from the accordion list items
339
- selectAccordionTree ( dataStoreAccordionItem ) ;
340
- cy . accordionItem ( domainName ) ;
341
- cy . wait ( '@getCreatedDomainInfo' ) ;
342
- // Removing the domain
343
- cy . expect_browser_confirm_with_text ( {
344
- confirmTriggerFn : ( ) =>
345
- cy . toolbar ( toolbarConfiguration , toolbarRemoveDomain ) ,
346
- containsText : browserConfirmRemoveMessage ,
367
+ // retrieve the id and token from the aliased state
368
+ // to invoke api for deleting the created domain
369
+ cy . get ( '@idAndToken' ) . then ( ( data ) => {
370
+ cy . request ( {
371
+ method : 'POST' ,
372
+ url : `/miq_ae_class/x_button/${ data . domainId } ?pressed=miq_ae_domain_delete` ,
373
+ headers : {
374
+ 'X-CSRF-Token' : data ?. csrfToken ,
375
+ } ,
376
+ } ) . then ( ( response ) => {
377
+ expect ( response . status ) . to . eq ( 200 ) ;
378
+ } ) ;
347
379
} ) ;
348
380
} ) ;
349
381
} ) ;
0 commit comments