updated tests

This commit is contained in:
Mateus Badan de Pieri 2023-02-02 14:39:33 +00:00
parent 263d588191
commit b2d18d13f5
1 changed files with 29 additions and 11 deletions

View File

@ -2,7 +2,7 @@ jest.mock("../../../integrations/postgres")
import * as setup from "./utilities"
import postgres from "../../../integrations/postgres"
import { mocks } from "@budibase/backend-core/tests"
import { env } from "@budibase/backend-core"
import { env, events } from "@budibase/backend-core"
const structures = setup.structures
env._set("ENCRYPTION_KEY", "budibase")
@ -46,30 +46,48 @@ describe("/api/env/variables", () => {
expect(res.body.variables[0]).toEqual("test")
})
it("should be able to update the environment variable 'test'", async () => {})
it("should be able to update the environment variable 'test'", async () => {
const varName = "test"
await request
.patch(`/api/env/variables/${varName}`)
.send(structures.basicEnvironmentVariable("test", "test1"))
.set(config.defaultHeaders())
.expect(200)
})
it("should be able to delete the environment variable 'test'", async () => {})
it("should be able to create an environment variable", async () => {})
it("should be able to delete the environment variable 'test'", async () => {
const varName = "test"
await request
.delete(`/api/env/variables/${varName}`)
.set(config.defaultHeaders())
.expect(200)
})
it("should create a datasource (using the environment variable) and query", async () => {
const datasourceBase = structures.basicDatasource()
// TODO: we need to use an environment variable in the datasource configuration
const datasource = await request
await request
.post(`/api/env/variables`)
.send(structures.basicEnvironmentVariable("test", "test"))
.set(config.defaultHeaders())
datasourceBase.datasource.config = {
password: "{{ env.test }}",
}
const response = await request
.post(`/api/datasources`)
.send(datasourceBase)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(datasource._id).toBeDefined()
expect(response.body.datasource._id).toBeDefined()
const query = await request
const response2 = await request
.post(`/api/queries`)
.send(structures.basicQuery(datasource._id))
.send(structures.basicQuery(response.body.datasource._id))
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(query._id).toBeDefined()
expect(response2.body._id).toBeDefined()
})
it("should run a query preview and check the mocked results", async () => {