Smart typing

This commit is contained in:
Adria Navarro 2024-01-29 23:19:07 +01:00
parent ff75fbf99e
commit 7394a7cd64
2 changed files with 21 additions and 25 deletions

View File

@ -45,17 +45,6 @@ describe("/queries", () => {
await setupTest() await setupTest()
}) })
async function createInvalidIntegration() {
const datasource = await config.createDatasource({
datasource: {
...basicDatasource().datasource,
source: "INVALID_INTEGRATION" as SourceName,
},
})
const query = await config.createQuery()
return { datasource, query }
}
const createQuery = async (query: Query) => { const createQuery = async (query: Query) => {
return request return request
.post(`/api/queries`) .post(`/api/queries`)
@ -278,14 +267,15 @@ describe("/queries", () => {
}) })
it("should fail with invalid integration type", async () => { it("should fail with invalid integration type", async () => {
let error const response = await config.api.datasource.create(
try { {
await createInvalidIntegration() ...basicDatasource().datasource,
} catch (err) { source: "INVALID_INTEGRATION" as SourceName,
error = err },
} { expectStatus: 500, rawResponse: true }
expect(error).toBeDefined() )
expect(error.message).toBe("No datasource implementation found.")
expect(response.body.message).toBe("No datasource implementation found.")
}) })
}) })

View File

@ -2,20 +2,23 @@ import {
CreateDatasourceRequest, CreateDatasourceRequest,
Datasource, Datasource,
VerifyDatasourceRequest, VerifyDatasourceRequest,
VerifyDatasourceResponse,
} from "@budibase/types" } from "@budibase/types"
import TestConfiguration from "../TestConfiguration" import TestConfiguration from "../TestConfiguration"
import { TestAPI } from "./base" import { TestAPI } from "./base"
import supertest from "supertest"
export class DatasourceAPI extends TestAPI { export class DatasourceAPI extends TestAPI {
constructor(config: TestConfiguration) { constructor(config: TestConfiguration) {
super(config) super(config)
} }
create = async ( create = async <B extends boolean>(
config: Datasource, config: Datasource,
{ expectStatus } = { expectStatus: 200 } {
): Promise<Datasource> => { expectStatus,
rawResponse,
}: { expectStatus?: number; rawResponse?: B } = {}
): Promise<B extends false ? Datasource : supertest.Response> => {
const body: CreateDatasourceRequest = { const body: CreateDatasourceRequest = {
datasource: config, datasource: config,
tablesFilter: [], tablesFilter: [],
@ -25,8 +28,11 @@ export class DatasourceAPI extends TestAPI {
.send(body) .send(body)
.set(this.config.defaultHeaders()) .set(this.config.defaultHeaders())
.expect("Content-Type", /json/) .expect("Content-Type", /json/)
.expect(expectStatus) .expect(expectStatus || 200)
return result.body.datasource as Datasource if (rawResponse) {
return result as any
}
return result.body.datasource
} }
update = async ( update = async (