From 8931309669d9011ae69940c517e05b92f6f5afe7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 4 Sep 2023 18:53:32 +0200 Subject: [PATCH] Datasource test api --- .../src/tests/utilities/TestConfiguration.ts | 6 ++++- .../src/tests/utilities/api/datasource.ts | 26 +++++++++++++++++++ .../server/src/tests/utilities/api/index.ts | 3 +++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/tests/utilities/api/datasource.ts diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index 5d5d6a18e5..d759431bcc 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -684,7 +684,11 @@ class TestConfiguration { datasource: Datasource }): Promise { config = config || basicDatasource() - const response = await this._req(config, null, controllers.datasource.save) + const response = await this._req( + { ...config }, + null, + controllers.datasource.save + ) this.datasource = response.datasource return this.datasource! } diff --git a/packages/server/src/tests/utilities/api/datasource.ts b/packages/server/src/tests/utilities/api/datasource.ts new file mode 100644 index 0000000000..c07fd3bc61 --- /dev/null +++ b/packages/server/src/tests/utilities/api/datasource.ts @@ -0,0 +1,26 @@ +import { CreateDatasourceRequest, Datasource } from "@budibase/types" +import TestConfiguration from "../TestConfiguration" +import { TestAPI } from "./base" + +export class DatasourceAPI extends TestAPI { + constructor(config: TestConfiguration) { + super(config) + } + + create = async ( + config: Datasource, + { expectStatus } = { expectStatus: 200 } + ): Promise => { + const body: CreateDatasourceRequest = { + datasource: config, + tablesFilter: [], + } + const result = await this.request + .post(`/api/datasources`) + .send(body) + .set(this.config.defaultHeaders()) + .expect("Content-Type", /json/) + .expect(expectStatus) + return result.body.datasource as Datasource + } +} diff --git a/packages/server/src/tests/utilities/api/index.ts b/packages/server/src/tests/utilities/api/index.ts index 40995b62f2..0521f9b19f 100644 --- a/packages/server/src/tests/utilities/api/index.ts +++ b/packages/server/src/tests/utilities/api/index.ts @@ -3,17 +3,20 @@ import { PermissionAPI } from "./permission" import { RowAPI } from "./row" import { TableAPI } from "./table" import { ViewV2API } from "./viewV2" +import { DatasourceAPI } from "./datasource" export default class API { table: TableAPI viewV2: ViewV2API row: RowAPI permission: PermissionAPI + datasource: DatasourceAPI constructor(config: TestConfiguration) { this.table = new TableAPI(config) this.viewV2 = new ViewV2API(config) this.row = new RowAPI(config) this.permission = new PermissionAPI(config) + this.datasource = new DatasourceAPI(config) } }