Remove makeRequest from mysql.spec.ts
This commit is contained in:
parent
c2320e4f5b
commit
84118f9e8c
|
@ -1,8 +1,4 @@
|
||||||
import fetch from "node-fetch"
|
import fetch from "node-fetch"
|
||||||
import {
|
|
||||||
generateMakeRequest,
|
|
||||||
MakeRequestResponse,
|
|
||||||
} from "../api/routes/public/tests/utils"
|
|
||||||
import * as setup from "../api/routes/tests/utilities"
|
import * as setup from "../api/routes/tests/utilities"
|
||||||
import { Datasource, FieldType } from "@budibase/types"
|
import { Datasource, FieldType } from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
|
@ -12,6 +8,7 @@ import {
|
||||||
} from "../integrations/tests/utils"
|
} from "../integrations/tests/utils"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
import { tableForDatasource } from "../../src/tests/utilities/structures"
|
import { tableForDatasource } from "../../src/tests/utilities/structures"
|
||||||
|
import { Knex } from "knex"
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fetch.mockSearch()
|
fetch.mockSearch()
|
||||||
|
|
||||||
|
@ -40,15 +37,12 @@ jest.mock("../websockets", () => ({
|
||||||
}))
|
}))
|
||||||
|
|
||||||
describe("mysql integrations", () => {
|
describe("mysql integrations", () => {
|
||||||
let makeRequest: MakeRequestResponse,
|
let rawDatasource: Datasource
|
||||||
rawDatasource: Datasource,
|
let datasource: Datasource
|
||||||
datasource: Datasource
|
let client: Knex
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
const apiKey = await config.generateApiKey()
|
|
||||||
|
|
||||||
makeRequest = generateMakeRequest(apiKey, true)
|
|
||||||
|
|
||||||
rawDatasource = await getDatasource(DatabaseName.MYSQL)
|
rawDatasource = await getDatasource(DatabaseName.MYSQL)
|
||||||
datasource = await config.api.datasource.create(rawDatasource)
|
datasource = await config.api.datasource.create(rawDatasource)
|
||||||
|
@ -59,11 +53,8 @@ describe("mysql integrations", () => {
|
||||||
it("validate table schema", async () => {
|
it("validate table schema", async () => {
|
||||||
// Creating a table so that `entities` is populated.
|
// Creating a table so that `entities` is populated.
|
||||||
await config.api.table.save(tableForDatasource(datasource))
|
await config.api.table.save(tableForDatasource(datasource))
|
||||||
|
const res = await config.api.datasource.get(datasource._id!)
|
||||||
const res = await makeRequest("get", `/api/datasources/${datasource._id}`)
|
expect(res).toEqual({
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
expect(res.body).toEqual({
|
|
||||||
config: {
|
config: {
|
||||||
database: expect.any(String),
|
database: expect.any(String),
|
||||||
host: datasource.config!.host,
|
host: datasource.config!.host,
|
||||||
|
@ -114,14 +105,9 @@ describe("mysql integrations", () => {
|
||||||
rawDatasource,
|
rawDatasource,
|
||||||
`CREATE TABLE \`${database}\`.table1 (id1 SERIAL PRIMARY KEY);`
|
`CREATE TABLE \`${database}\`.table1 (id1 SERIAL PRIMARY KEY);`
|
||||||
)
|
)
|
||||||
const response = await makeRequest("post", "/api/datasources/info", {
|
const res = await config.api.datasource.info(datasource)
|
||||||
datasource: datasource,
|
expect(res.tableNames).toBeDefined()
|
||||||
})
|
expect(res.tableNames).toEqual(expect.arrayContaining(["table1"]))
|
||||||
expect(response.status).toBe(200)
|
|
||||||
expect(response.body.tableNames).toBeDefined()
|
|
||||||
expect(response.body.tableNames).toEqual(
|
|
||||||
expect.arrayContaining(["table1"])
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("does not mix columns from different tables", async () => {
|
it("does not mix columns from different tables", async () => {
|
||||||
|
@ -134,19 +120,13 @@ describe("mysql integrations", () => {
|
||||||
rawDatasource,
|
rawDatasource,
|
||||||
`CREATE TABLE \`${database2}\`.${repeated_table_name} (id2 SERIAL PRIMARY KEY, val2 TEXT);`
|
`CREATE TABLE \`${database2}\`.${repeated_table_name} (id2 SERIAL PRIMARY KEY, val2 TEXT);`
|
||||||
)
|
)
|
||||||
const response = await makeRequest(
|
|
||||||
"post",
|
const res = await config.api.datasource.fetchSchema({
|
||||||
`/api/datasources/${datasource._id}/schema`,
|
datasourceId: datasource._id!,
|
||||||
{
|
tablesFilter: [repeated_table_name],
|
||||||
tablesFilter: [repeated_table_name],
|
})
|
||||||
}
|
expect(res.datasource.entities![repeated_table_name].schema).toBeDefined()
|
||||||
)
|
const schema = res.datasource.entities![repeated_table_name].schema
|
||||||
expect(response.status).toBe(200)
|
|
||||||
expect(
|
|
||||||
response.body.datasource.entities[repeated_table_name].schema
|
|
||||||
).toBeDefined()
|
|
||||||
const schema =
|
|
||||||
response.body.datasource.entities[repeated_table_name].schema
|
|
||||||
expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
|
expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -175,12 +155,11 @@ describe("mysql integrations", () => {
|
||||||
|
|
||||||
await rawQuery(rawDatasource, createTableQuery)
|
await rawQuery(rawDatasource, createTableQuery)
|
||||||
|
|
||||||
const response = await makeRequest(
|
const res = await config.api.datasource.fetchSchema({
|
||||||
"post",
|
datasourceId: datasource._id!,
|
||||||
`/api/datasources/${datasource._id}/schema`
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const table = response.body.datasource.entities[tableName]
|
const table = res.datasource.entities![tableName]
|
||||||
|
|
||||||
expect(table).toBeDefined()
|
expect(table).toBeDefined()
|
||||||
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
|
||||||
|
|
|
@ -14,7 +14,7 @@ const config = setup.getConfig()!
|
||||||
describe("postgres integrations", () => {
|
describe("postgres integrations", () => {
|
||||||
let rawDatasource: Datasource
|
let rawDatasource: Datasource
|
||||||
let datasource: Datasource
|
let datasource: Datasource
|
||||||
let client: Knex<any, unknown[]>
|
let client: Knex
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
|
|
Loading…
Reference in New Issue