Skip to content

Commit e9a9f6c

Browse files
Refactored namespace deletion to use direct API call
1 parent 5d3a8ed commit e9a9f6c

File tree

1 file changed

+42
-10
lines changed

1 file changed

+42
-10
lines changed

cypress/e2e/ui/Automation/Embedded-Automate/Explorer/namespace.cy.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,33 @@ function createNamespaceAndOpenEditForm() {
193193
cy.toolbar(toolbarConfiguration, toolbarEditNamespace);
194194
}
195195

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+
196223
describe('Automate operations on Namespaces: Automation -> Embedded Automate -> Explorer -> {Any-created-domain} -> Namespace form', () => {
197224
beforeEach(() => {
198225
cy.login();
@@ -209,7 +236,9 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
209236
'addNamespaceApi'
210237
);
211238
cy.contains(buttonSelector(submitButtonType), addButton).click();
212-
cy.wait('@addNamespaceApi');
239+
cy.wait('@addNamespaceApi').then((interception) => {
240+
extractDomainIdAndTokenFromResponse(interception);
241+
});
213242
cy.expect_flash(flashTypeSuccess, flashMessageAddSuccess);
214243
// Selecting the created domain from the accordion list items
215244
selectAccordionTree(domainName);
@@ -335,15 +364,18 @@ describe('Automate operations on Namespaces: Automation -> Embedded Automate ->
335364
});
336365

337366
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+
});
347379
});
348380
});
349381
});

0 commit comments

Comments
 (0)