chore(cypress): add wraps, adjust variables, remove comments

pull/5936/head
k3yi0 2022-06-13 08:31:35 +02:00
parent 83b941d960
commit 5ce7bcb207
3 changed files with 47 additions and 27 deletions

View File

@ -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)

View File

@ -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

View File

@ -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.
*/