Improve automation tests

This commit is contained in:
adrinr 2023-02-03 17:49:21 +00:00
parent 4a8db61b6b
commit 4cab97b8ab
3 changed files with 25 additions and 11 deletions

View File

@ -14,18 +14,22 @@ jest.mock("../../../utilities/redis", () => ({
import { clearAllApps, checkBuilderEndpoint } from "./utilities/TestFunctions" import { clearAllApps, checkBuilderEndpoint } from "./utilities/TestFunctions"
import * as setup from "./utilities" import * as setup from "./utilities"
import { AppStatus } from "../../../db/utils" import { AppStatus } from "../../../db/utils"
import { events } from "@budibase/backend-core" import { events, utils } from "@budibase/backend-core"
import env from "../../../environment" import env from "../../../environment"
jest.setTimeout(15000)
describe("/applications", () => { describe("/applications", () => {
let request = setup.getRequest() let request = setup.getRequest()
let config = setup.getConfig() let config = setup.getConfig()
afterAll(setup.afterAll) afterAll(setup.afterAll)
beforeEach(async () => { beforeAll(async () => {
await clearAllApps()
await config.init() await config.init()
})
beforeEach(async () => {
jest.clearAllMocks() jest.clearAllMocks()
}) })
@ -33,7 +37,7 @@ describe("/applications", () => {
it("creates empty app", async () => { it("creates empty app", async () => {
const res = await request const res = await request
.post("/api/applications") .post("/api/applications")
.field("name", "My App") .field("name", utils.newid())
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.expect("Content-Type", /json/) .expect("Content-Type", /json/)
.expect(200) .expect(200)
@ -44,7 +48,7 @@ describe("/applications", () => {
it("creates app from template", async () => { it("creates app from template", async () => {
const res = await request const res = await request
.post("/api/applications") .post("/api/applications")
.field("name", "My App") .field("name", utils.newid())
.field("useTemplate", "true") .field("useTemplate", "true")
.field("templateKey", "test") .field("templateKey", "test")
.field("templateString", "{}") // override the file download .field("templateString", "{}") // override the file download
@ -59,7 +63,7 @@ describe("/applications", () => {
it("creates app from file", async () => { it("creates app from file", async () => {
const res = await request const res = await request
.post("/api/applications") .post("/api/applications")
.field("name", "My App") .field("name", utils.newid())
.field("useTemplate", "true") .field("useTemplate", "true")
.set(config.defaultHeaders()) .set(config.defaultHeaders())
.attach("templateFile", "src/api/routes/tests/data/export.txt") .attach("templateFile", "src/api/routes/tests/data/export.txt")
@ -106,6 +110,11 @@ describe("/applications", () => {
}) })
describe("fetch", () => { describe("fetch", () => {
beforeEach(async () => {
// Clean all apps but the onde from config
await clearAllApps(config.getTenantId(), [config.getAppId()!])
})
it("lists all applications", async () => { it("lists all applications", async () => {
await config.createApp("app1") await config.createApp("app1")
await config.createApp("app2") await config.createApp("app2")
@ -266,6 +275,11 @@ describe("/applications", () => {
}) })
describe("unpublish", () => { describe("unpublish", () => {
beforeEach(async () => {
// We want to republish as the unpublish will delete the prod app
await config.publish()
})
it("should unpublish app with dev app ID", async () => { it("should unpublish app with dev app ID", async () => {
const appId = config.getAppId() const appId = config.getAppId()
await request await request

View File

@ -32,7 +32,10 @@ export const getAllTableRows = async (config: any) => {
return req.body return req.body
} }
export const clearAllApps = async (tenantId = TENANT_ID) => { export const clearAllApps = async (
tenantId = TENANT_ID,
exceptions: Array<string> = []
) => {
await tenancy.doInTenant(tenantId, async () => { await tenancy.doInTenant(tenantId, async () => {
const req: any = { query: { status: AppStatus.DEV }, user: { tenantId } } const req: any = { query: { status: AppStatus.DEV }, user: { tenantId } }
await appController.fetch(req) await appController.fetch(req)
@ -40,7 +43,7 @@ export const clearAllApps = async (tenantId = TENANT_ID) => {
if (!apps || apps.length <= 0) { if (!apps || apps.length <= 0) {
return return
} }
for (let app of apps) { for (let app of apps.filter((x: any) => !exceptions.includes(x.appId))) {
const { appId } = app const { appId } = app
const req = new Request(null, { appId }) const req = new Request(null, { appId })
await runRequest(appId, appController.destroy, req) await runRequest(appId, appController.destroy, req)

View File

@ -363,9 +363,6 @@ class TestConfiguration {
if (this.appId) { if (this.appId) {
headers[constants.Header.APP_ID] = this.appId headers[constants.Header.APP_ID] = this.appId
} }
if (this.tenantId) {
headers[constants.Header.TENANT_ID] = this.tenantId
}
return headers return headers
} }