From 5ce7bcb20720b736e760d2e6fa494fa14b3e7fc7 Mon Sep 17 00:00:00 2001 From: k3yi0 Date: Mon, 13 Jun 2022 08:31:35 +0200 Subject: [PATCH] chore(cypress): add wraps, adjust variables, remove comments --- ui/cypress/integration/admin.test.ts | 4 +- ui/cypress/integration/queryBuilder.test.ts | 2 - ui/cypress/support/commands.ts | 68 ++++++++++++++------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/ui/cypress/integration/admin.test.ts b/ui/cypress/integration/admin.test.ts index 28d117373..1a6a61784 100644 --- a/ui/cypress/integration/admin.test.ts +++ b/ui/cypress/integration/admin.test.ts @@ -5,8 +5,8 @@ describe('Use Admin tab', () => { beforeEach(() => { cy.flush() cy.createInfluxDBConnection() - cy.get('@connections').then(source => { - sourceId = source[0].id + cy.get('@connections').then(sources => { + sourceId = sources[0].id cy.request('GET', `/chronograf/v1/sources/${sourceId}/users`).then( ({body: responseBody}) => { console.log(responseBody.users) diff --git a/ui/cypress/integration/queryBuilder.test.ts b/ui/cypress/integration/queryBuilder.test.ts index 487371e12..4c0ce313b 100644 --- a/ui/cypress/integration/queryBuilder.test.ts +++ b/ui/cypress/integration/queryBuilder.test.ts @@ -5,9 +5,7 @@ describe('query builder', () => { cy.flush() cy.createInfluxDBConnection() cy.createDashboard() - cy.visit('/') cy.get('@connections').then((sources: any) => { - console.log(sources) cy.fixture('influxDB.json').then((influxDBData: any) => { influxDB = influxDBData diff --git a/ui/cypress/support/commands.ts b/ui/cypress/support/commands.ts index fd3410d0e..1eedf8d84 100644 --- a/ui/cypress/support/commands.ts +++ b/ui/cypress/support/commands.ts @@ -1,4 +1,3 @@ -import cypress from 'cypress' import {addMatchImageSnapshotCommand} from 'cypress-image-snapshot/command' const apiUrl = '/chronograf/v1' @@ -245,21 +244,25 @@ export const createChronografUser = ( organization?: string, role?: string ) => { - return cy.request({ - method: 'POST', - url: `${apiUrl}/users`, - body: { - name: userName + '@oauth2.mock', - provider: provider, - roles: [ - { - name: role ?? 'reader', - organization: organization ?? 'default', - }, - ], - scheme: scheme, - }, - }) + return cy + .request({ + method: 'POST', + url: `${apiUrl}/users`, + body: { + name: userName + '@oauth2.mock', + provider: provider, + roles: [ + { + name: role ?? 'reader', + organization: organization ?? 'default', + }, + ], + scheme: scheme, + }, + }) + .then(() => { + wrapChronografUsers() + }) } /** @@ -268,13 +271,18 @@ export const createChronografUser = ( */ export const deleteChronografUser = (name: string) => { const userName = name + '@oauth2.mock' - return cy.request('GET', `${apiUrl}/users`).then(({body: responseBody}) => { - responseBody.users.forEach((user: any) => { - if (userName == user.name) { - cy.request('DELETE', user.links.self) - } + return cy + .request('GET', `${apiUrl}/users`) + .then(({body: responseBody}) => { + responseBody.users.forEach((user: any) => { + if (userName == user.name) { + cy.request('DELETE', user.links.self) + } + }) + }) + .then(() => { + wrapChronografUsers() }) - }) } /** @@ -291,6 +299,9 @@ export const deleteChronografUsers = () => { cy.request('DELETE', user.links.self) }) }) + .then(() => { + wrapChronografUsers() + }) } /** @@ -318,7 +329,9 @@ export const createOrg = (orgName: string, defaultRole: string) => { * @param id - Organization ID. */ export const deleteOrg = (id: string) => { - return cy.request('DELETE', `${apiUrl}/organizations/${id}`) + return cy.request('DELETE', `${apiUrl}/organizations/${id}`).then(() => { + wrapOrgs() + }) } /** @@ -332,6 +345,9 @@ export const deleteOrgs = () => { cy.request('DELETE', organization.links.self) }) }) + .then(() => { + wrapOrgs() + }) } /** * Create an InfluxDB user. @@ -521,6 +537,12 @@ function wrapInfluxDBRoles(sourceId: string) { }) } +function wrapChronografUsers() { + return cy.request('GET', `${apiUrl}/users`).then(({body: response}) => { + cy.wrap(response.users).as('chronografUsers') + }) +} + /** * Set application to a default state. */