Skip to content

Commit 8b09afc

Browse files
Improve subscription deletion logic in afterEach hook to handle non-existent applications
1 parent 1ab17d1 commit 8b09afc

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

tests/cypress/e2e/publisher/000-general/03-create-and-publish-graphql-api-with-all-information.cy.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ let apiId;
1919
describe("Create GraphQl API from file", () => {
2020
const username = 'admin';
2121
const password = 'admin';
22+
const filmSubscriberRole = `FilmSubscriber${Utils.generateRandomNumber()}`;
2223
const filepath = 'api_artifacts/schema_graphql.graphql';
2324
const modifiedFilepath = 'api_artifacts/modified_schema_graphql.graphql';
2425
const apiVersion = '1.0.0';
25-
let apiContext;
26-
let apiName;
27-
let applicationName;
28-
let applicationCreated = false;
29-
let filmSubscriberRole;
26+
const apiContext = `/swapi${Utils.generateRandomNumber()}`;
27+
const apiName = `StarWarsAPIGQL${Utils.generateRandomNumber()}`;
28+
const applicationName = 'Graphql Client App';
3029
const starWarsQueryRequest = `query{
3130
human(id:1000){\n
3231
id\n
@@ -95,7 +94,6 @@ describe("Create GraphQl API from file", () => {
9594

9695
beforeEach(function () {
9796
//add role filmsubscriber
98-
filmSubscriberRole = `FilmSubscriber${Utils.generateRandomNumber()}`;
9997
cy.carbonLogin(username, password);
10098
cy.visit('/carbon/role/add-step1.jsp');
10199
cy.get('input[name="roleName"]').type(filmSubscriberRole);
@@ -119,9 +117,6 @@ describe("Create GraphQl API from file", () => {
119117
})
120118

121119
it("Verify GraphQl API Capabilities", () => {
122-
apiContext = `/swapi${Utils.generateRandomNumber()}`;
123-
apiName = `StarWarsAPIGQL${Utils.generateRandomNumber()}`;
124-
applicationName = `Graphql Client App ${Utils.generateRandomNumber()}`;
125120

126121
//create a graphql API
127122
cy.createGraphqlAPIfromFile(apiName, apiVersion, apiContext, filepath).then(value => {
@@ -183,7 +178,7 @@ describe("Create GraphQl API from file", () => {
183178
.should('not.have.class', 'Mui-disabled').click({ force: true });
184179
cy.contains('Revision Created Successfully');
185180
cy.contains('Revision Deployed Successfully');
186-
// cy.contains('div[role="button"]', 'Successfully Deployed').should('exist');
181+
cy.contains('div[role="button"]', 'Successfully Deployed').should('exist');
187182

188183
//publish
189184
cy.get("#left-menu-overview", { timeout: Cypress.env('largeTimeout') }).click();
@@ -196,9 +191,6 @@ describe("Create GraphQl API from file", () => {
196191

197192
// create an application
198193
cy.createApplication(applicationName, "50PerMin", "Sample Description");
199-
cy.then(() => {
200-
applicationCreated = true;
201-
});
202194

203195
//go to apis
204196
cy.get('[data-testid="itest-link-to-apis"]',
@@ -285,10 +277,8 @@ expect(JSON.stringify(resp.body)).to.include(starWarsSubscriptionResponse);
285277

286278

287279
after(function () {
288-
if (applicationCreated) {
289-
cy.deleteApplication(applicationName);
290-
cy.logoutFromDevportal();
291-
}
280+
cy.deleteApplication(applicationName);
281+
cy.logoutFromDevportal();
292282
cy.loginToPublisher(username, password);
293283
cy.log("app id " + apiId);
294284
// Test is done. Now delete the api

tests/cypress/e2e/publisher/006-subscriptions/01-subscribtion-blocking.cy.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ describe("Subscription blocking", () => {
8080
afterEach(() => {
8181
cy.loginToDevportal(developer, password);
8282
cy.visit(`/devportal/applications?tenant=carbon.super`);
83-
cy.get(`#delete-${appName}-btn`, { timeout: Cypress.env('largeTimeout') });
84-
cy.get(`#delete-${appName}-btn`).click();
85-
cy.get(`#itest-confirm-application-delete`).click();
83+
cy.get('body').then(($body) => {
84+
if ($body.find(`#delete-${appName}-btn`).length > 0) {
85+
cy.get(`#delete-${appName}-btn`, { timeout: Cypress.env('largeTimeout') }).click();
86+
cy.get(`#itest-confirm-application-delete`).click();
87+
}
88+
});
8689
cy.logoutFromDevportal();
87-
cy.loginToPublisher(publisher, password);
88-
Utils.deleteAPI(testApiId);
90+
if (testApiId) {
91+
cy.loginToPublisher(publisher, password);
92+
Utils.deleteAPI(testApiId);
93+
cy.logoutFromPublisher();
94+
}
8995
})
9096
})

0 commit comments

Comments
 (0)