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

View File

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