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