1
0
Fork 0
mirror of synced 2024-06-18 18:35:37 +12:00

Fixing app cypress test cases.

This commit is contained in:
mike12345567 2021-05-25 13:25:42 +01:00
parent 39545358f2
commit be7736afb7
6 changed files with 44 additions and 62 deletions

View file

@ -1,6 +1,5 @@
const { newid } = require("../hashing")
const Replication = require("./Replication")
const { getCouch } = require("./index")
const UNICODE_MAX = "\ufff0"
const SEPARATOR = "_"
@ -164,8 +163,7 @@ exports.getDeployedAppID = appId => {
* different users/companies apps as there is no security around it - all apps are returned.
* @return {Promise<object[]>} returns the app information document stored in each app database.
*/
exports.getAllApps = async ({ dev, all } = {}) => {
const CouchDB = getCouch()
exports.getAllApps = async ({ CouchDB, dev, all } = {}) => {
let allDbs = await CouchDB.allDbs()
const appDbNames = allDbs.filter(dbName =>
dbName.startsWith(exports.APP_PREFIX)

View file

@ -6,21 +6,18 @@
//
Cypress.Commands.add("login", () => {
cy.getCookie("budibase:auth").then(cookie => {
// Already logged in
if (cookie) return
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.url().then(url => {
if (url.includes("builder/admin")) {
// create admin user
cy.get("input").first().type("test@test.com")
cy.get('input[type="password"]').first().type("test")
cy.get('input[type="password"]').eq(1).type("test")
cy.contains("Create super admin user").click()
}
// login
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.wait(100)
cy.url().then(url => {
if (url.includes("builder/admin")) {
// create admin user
cy.get("input").first().type("test@test.com")
cy.get('input[type="password"]').first().type("test")
cy.get('input[type="password"]').eq(1).type("test")
cy.contains("Create super admin user").click()
}
// login
cy.contains("Sign in to Budibase").then(() => {
cy.get("input").first().type("test@test.com")
cy.get('input[type="password"]').type("test")
cy.get("button").first().click()
@ -32,45 +29,39 @@ Cypress.Commands.add("createApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
// wait for init API calls on visit
cy.wait(100)
cy.contains("Create New Web App").click()
cy.get("body")
.then($body => {
if ($body.find("input[name=apiKey]").length) {
// input was found, do something else here
cy.get("input[name=apiKey]").type(name).should("have.value", name)
cy.contains("Next").click()
}
})
.then(() => {
cy.get(".spectrum-Modal")
.within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.contains("Next").click()
cy.get("input").eq(1).type("test@test.com").blur()
cy.get("input").eq(2).type("test").blur()
cy.contains("Submit").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
timeout: 20000,
}).should("be.visible")
})
})
cy.contains("Create app").click()
cy.get("body").then(() => {
cy.get(".spectrum-Modal")
.within(() => {
cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.contains("Create app").click()
})
.then(() => {
cy.get("[data-cy=new-table]", {
timeout: 20000,
}).should("be.visible")
})
})
})
Cypress.Commands.add("deleteApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.get(".apps").then($apps => {
cy.wait(1000)
if ($apps.find(`[data-cy="app-${name}"]`).length) {
cy.get(`[data-cy="app-${name}"]`).contains("Open").click()
cy.get("[data-cy=settings-icon]").click()
cy.get(".spectrum-Dialog").within(() => {
cy.contains("Danger Zone").click()
cy.get("input").type("DELETE").blur()
cy.contains("Delete Entire App").click()
})
cy.contains("Create your first app").then($first => {
if ($first.length === 1) {
return
}
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.get(".app").then($app => {
cy.wait(1000)
if ($app.find(`[data-cy="app-${name}"]`).length) {
cy.get(`[data-cy="app-${name}"]`).contains("Open").click()
cy.get("[data-cy=settings-icon]").click()
cy.get(".spectrum-Dialog").within(() => {
cy.contains("Danger Zone").click()
cy.get("input").type("DELETE").blur()
cy.contains("Delete Entire App").click()
})
}
})
})
})

View file

@ -1,3 +0,0 @@
Cypress.Cookies.defaults({
preserve: "budibase:auth",
})

View file

@ -14,7 +14,6 @@
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "./cookies"
import "./commands"
// Alternatively you can use CommonJS syntax:

View file

@ -116,7 +116,7 @@ async function createInstance(template) {
exports.fetch = async function (ctx) {
const dev = ctx.query && ctx.query.status === AppStatus.DEV
const all = ctx.query && ctx.query.status === AppStatus.ALL
const apps = await getAllApps({ dev, all })
const apps = await getAllApps({ CouchDB, dev, all })
// get the locks for all the dev apps
if (dev || all) {
@ -192,9 +192,6 @@ exports.create = async function (ctx) {
instance: instance,
updatedAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
deployment: {
type: "cloud",
},
}
const instanceDb = new CouchDB(appId)
await instanceDb.put(newApplication)

View file

@ -8,7 +8,7 @@ const CouchDB = require("../../../db")
exports.fetch = async ctx => {
// always use the dev apps as they'll be most up to date (true)
const apps = await getAllApps({ dev: true })
const apps = await getAllApps({ CouchDB, dev: true })
const promises = []
for (let app of apps) {
// use dev app IDs