From b2d18d13f53b3d63048b1b82dceb28c970bb5c77 Mon Sep 17 00:00:00 2001 From: Mateus Badan de Pieri Date: Thu, 2 Feb 2023 14:39:33 +0000 Subject: [PATCH] updated tests --- .../routes/tests/environmentVariables.spec.ts | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/server/src/api/routes/tests/environmentVariables.spec.ts b/packages/server/src/api/routes/tests/environmentVariables.spec.ts index 86ff8367da..b2467407ae 100644 --- a/packages/server/src/api/routes/tests/environmentVariables.spec.ts +++ b/packages/server/src/api/routes/tests/environmentVariables.spec.ts @@ -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 () => {