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

View file

@ -6,21 +6,18 @@
// //
Cypress.Commands.add("login", () => { Cypress.Commands.add("login", () => {
cy.getCookie("budibase:auth").then(cookie => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
// Already logged in cy.wait(100)
if (cookie) return cy.url().then(url => {
if (url.includes("builder/admin")) {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`) // create admin user
cy.get("input").first().type("test@test.com")
cy.url().then(url => { cy.get('input[type="password"]').first().type("test")
if (url.includes("builder/admin")) { cy.get('input[type="password"]').eq(1).type("test")
// create admin user cy.contains("Create super admin user").click()
cy.get("input").first().type("test@test.com") }
cy.get('input[type="password"]').first().type("test") // login
cy.get('input[type="password"]').eq(1).type("test") cy.contains("Sign in to Budibase").then(() => {
cy.contains("Create super admin user").click()
}
// login
cy.get("input").first().type("test@test.com") cy.get("input").first().type("test@test.com")
cy.get('input[type="password"]').type("test") cy.get('input[type="password"]').type("test")
cy.get("button").first().click() cy.get("button").first().click()
@ -32,45 +29,39 @@ Cypress.Commands.add("createApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
// wait for init API calls on visit // wait for init API calls on visit
cy.wait(100) cy.wait(100)
cy.contains("Create New Web App").click() cy.contains("Create app").click()
cy.get("body") cy.get("body").then(() => {
.then($body => { cy.get(".spectrum-Modal")
if ($body.find("input[name=apiKey]").length) { .within(() => {
// input was found, do something else here cy.get("input").eq(0).type(name).should("have.value", name).blur()
cy.get("input[name=apiKey]").type(name).should("have.value", name) cy.contains("Create app").click()
cy.contains("Next").click() })
} .then(() => {
}) cy.get("[data-cy=new-table]", {
.then(() => { timeout: 20000,
cy.get(".spectrum-Modal") }).should("be.visible")
.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")
})
})
}) })
Cypress.Commands.add("deleteApp", name => { Cypress.Commands.add("deleteApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.contains("Create your first app").then($first => {
cy.get(".apps").then($apps => { if ($first.length === 1) {
cy.wait(1000) return
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.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 commands.js using ES2015 syntax:
import "./cookies"
import "./commands" import "./commands"
// Alternatively you can use CommonJS syntax: // Alternatively you can use CommonJS syntax:

View file

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

View file

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