From 37453130642f8ffc07c633c2a06eea47ff408356 Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour <4711238+mutdmour@users.noreply.github.com> Date: Mon, 3 Jun 2024 12:51:40 +0200 Subject: [PATCH] fix(editor): Attempt to make cloud plan tests less flaky (no-changelog) (#9595) --- cypress/e2e/27-cloud.cy.ts | 92 +++++++++++++------------------------- 1 file changed, 32 insertions(+), 60 deletions(-) diff --git a/cypress/e2e/27-cloud.cy.ts b/cypress/e2e/27-cloud.cy.ts index f0a1e7aae6..6fdcfba295 100644 --- a/cypress/e2e/27-cloud.cy.ts +++ b/cypress/e2e/27-cloud.cy.ts @@ -19,25 +19,39 @@ describe('Cloud', { disableAutoLogin: true }, () => { planData.expirationDate = fiveDaysFromNow.toJSON(); }); + beforeEach(() => { + cy.intercept('GET', '/rest/admin/cloud-plan', { + body: planData, + }).as('getPlanData'); + + cy.intercept('GET', '/rest/settings', (req) => { + req.on('response', (res) => { + res.send({ + data: { + ...res.body.data, + deployment: { type: 'cloud' }, + n8nMetadata: { userId: 1 }, + }, + }); + }); + }).as('loadSettings'); + + cy.intercept('GET', new RegExp('/rest/projects*')).as('projects'); + cy.intercept('GET', new RegExp('/rest/roles')).as('roles'); + }); + + function visitWorkflowPage() { + cy.visit(workflowPage.url); + cy.wait('@getPlanData'); + cy.wait('@projects'); + cy.wait('@roles'); + } + describe('BannerStack', () => { it('should render trial banner for opt-in cloud user', () => { - cy.intercept('GET', '/rest/admin/cloud-plan', { - body: planData, - }).as('getPlanData'); - - cy.intercept('GET', '/rest/settings', (req) => { - req.on('response', (res) => { - res.send({ - data: { ...res.body.data, deployment: { type: 'cloud' }, n8nMetadata: { userId: 1 } }, - }); - }); - }).as('loadSettings'); - cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password }); - cy.visit(workflowPage.url); - - cy.wait('@getPlanData'); + visitWorkflowPage(); bannerStack.getters.banner().should('be.visible'); @@ -47,45 +61,19 @@ describe('Cloud', { disableAutoLogin: true }, () => { cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password }); - cy.visit(workflowPage.url); + visitWorkflowPage(); bannerStack.getters.banner().should('be.visible'); mainSidebar.actions.signout(); }); - - it('should not render opt-in-trial banner for non cloud deployment', () => { - cy.intercept('GET', '/rest/settings', (req) => { - req.on('response', (res) => { - res.send({ - data: { ...res.body.data, deployment: { type: 'default' } }, - }); - }); - }).as('loadSettings'); - - cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password }); - - cy.visit(workflowPage.url); - - bannerStack.getters.banner().should('not.be.visible'); - - mainSidebar.actions.signout(); - }); }); describe('Admin Home', () => { it('Should show admin button', () => { - cy.intercept('GET', '/rest/settings', (req) => { - req.on('response', (res) => { - res.send({ - data: { ...res.body.data, deployment: { type: 'cloud' }, n8nMetadata: { userId: 1 } }, - }); - }); - }).as('loadSettings'); - cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password }); - cy.visit(workflowPage.url); + visitWorkflowPage(); mainSidebar.getters.adminPanel().should('be.visible'); }); @@ -93,26 +81,10 @@ describe('Cloud', { disableAutoLogin: true }, () => { describe('Public API', () => { it('Should show upgrade CTA for Public API if user is trialing', () => { - cy.intercept('GET', '/rest/admin/cloud-plan', { - body: planData, - }).as('getPlanData'); - - cy.intercept('GET', '/rest/settings', (req) => { - req.on('response', (res) => { - res.send({ - data: { - ...res.body.data, - deployment: { type: 'cloud' }, - n8nMetadata: { userId: 1 }, - }, - }); - }); - }).as('loadSettings'); - cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password }); visitPublicApiPage(); - cy.wait(['@loadSettings', '@getPlanData']); + cy.wait(['@loadSettings', '@projects', '@roles', '@getPlanData']); getPublicApiUpgradeCTA().should('be.visible'); });