Migrate mysql.spec.ts to new datasource providers.
This commit is contained in:
parent
5530d7f4b6
commit
2304aeaa71
|
@ -1,4 +1,4 @@
|
|||
import { databaseTestProviders } from "../../../integrations/tests/utils"
|
||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||
|
||||
import tk from "timekeeper"
|
||||
import { outputProcessing } from "../../../utilities/rowProcessor"
|
||||
|
@ -34,10 +34,10 @@ jest.unmock("pg")
|
|||
|
||||
describe.each([
|
||||
["internal", undefined],
|
||||
["postgres", databaseTestProviders.postgres],
|
||||
["mysql", databaseTestProviders.mysql],
|
||||
["mssql", databaseTestProviders.mssql],
|
||||
["mariadb", databaseTestProviders.mariadb],
|
||||
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
])("/rows (%s)", (__, dsProvider) => {
|
||||
const isInternal = dsProvider === undefined
|
||||
const config = setup.getConfig()
|
||||
|
@ -49,23 +49,23 @@ describe.each([
|
|||
await config.init()
|
||||
if (dsProvider) {
|
||||
datasource = await config.createDatasource({
|
||||
datasource: await dsProvider.datasource(),
|
||||
datasource: await dsProvider,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
if (dsProvider) {
|
||||
await dsProvider.stop()
|
||||
}
|
||||
setup.afterAll()
|
||||
})
|
||||
|
||||
function saveTableRequest(
|
||||
...overrides: Partial<SaveTableRequest>[]
|
||||
// We omit the name field here because it's generated in the function with a
|
||||
// high likelihood to be unique. Tests should not have any reason to control
|
||||
// the table name they're writing to.
|
||||
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
|
||||
): SaveTableRequest {
|
||||
const req: SaveTableRequest = {
|
||||
name: uuid.v4().substring(0, 16),
|
||||
name: uuid.v4().substring(0, 10),
|
||||
type: "table",
|
||||
sourceType: datasource
|
||||
? TableSourceType.EXTERNAL
|
||||
|
@ -87,7 +87,10 @@ describe.each([
|
|||
}
|
||||
|
||||
function defaultTable(
|
||||
...overrides: Partial<SaveTableRequest>[]
|
||||
// We omit the name field here because it's generated in the function with a
|
||||
// high likelihood to be unique. Tests should not have any reason to control
|
||||
// the table name they're writing to.
|
||||
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
|
||||
): SaveTableRequest {
|
||||
return saveTableRequest(
|
||||
{
|
||||
|
@ -194,7 +197,6 @@ describe.each([
|
|||
|
||||
const newTable = await config.api.table.save(
|
||||
saveTableRequest({
|
||||
name: "TestTableAuto",
|
||||
schema: {
|
||||
"Row ID": {
|
||||
name: "Row ID",
|
||||
|
@ -383,11 +385,9 @@ describe.each([
|
|||
|
||||
isInternal &&
|
||||
it("doesn't allow creating in user table", async () => {
|
||||
const userTableId = InternalTable.USER_METADATA
|
||||
const response = await config.api.row.save(
|
||||
userTableId,
|
||||
InternalTable.USER_METADATA,
|
||||
{
|
||||
tableId: userTableId,
|
||||
firstName: "Joe",
|
||||
lastName: "Joe",
|
||||
email: "joe@joe.com",
|
||||
|
@ -462,7 +462,6 @@ describe.each([
|
|||
table = await config.api.table.save(defaultTable())
|
||||
otherTable = await config.api.table.save(
|
||||
defaultTable({
|
||||
name: "a",
|
||||
schema: {
|
||||
relationship: {
|
||||
name: "relationship",
|
||||
|
@ -898,8 +897,8 @@ describe.each([
|
|||
let o2mTable: Table
|
||||
let m2mTable: Table
|
||||
beforeAll(async () => {
|
||||
o2mTable = await config.api.table.save(defaultTable({ name: "o2m" }))
|
||||
m2mTable = await config.api.table.save(defaultTable({ name: "m2m" }))
|
||||
o2mTable = await config.api.table.save(defaultTable())
|
||||
m2mTable = await config.api.table.save(defaultTable())
|
||||
})
|
||||
|
||||
describe.each([
|
||||
|
@ -1256,7 +1255,6 @@ describe.each([
|
|||
otherTable = await config.api.table.save(defaultTable())
|
||||
table = await config.api.table.save(
|
||||
saveTableRequest({
|
||||
name: "b",
|
||||
schema: {
|
||||
links: {
|
||||
name: "links",
|
||||
|
@ -1354,7 +1352,6 @@ describe.each([
|
|||
|
||||
const table = await config.api.table.save(
|
||||
saveTableRequest({
|
||||
name: "table",
|
||||
schema: {
|
||||
text: {
|
||||
name: "text",
|
||||
|
|
|
@ -3,7 +3,6 @@ import {
|
|||
generateMakeRequest,
|
||||
MakeRequestResponse,
|
||||
} from "../api/routes/public/tests/utils"
|
||||
import { v4 as uuidv4 } from "uuid"
|
||||
import * as setup from "../api/routes/tests/utilities"
|
||||
import {
|
||||
Datasource,
|
||||
|
@ -12,9 +11,10 @@ import {
|
|||
TableRequest,
|
||||
TableSourceType,
|
||||
} from "@budibase/types"
|
||||
import { databaseTestProviders } from "../integrations/tests/utils"
|
||||
import { DatabaseName, getDatasource } from "../integrations/tests/utils"
|
||||
import mysql from "mysql2/promise"
|
||||
import { builderSocket } from "../websockets"
|
||||
import { generator } from "@budibase/backend-core/tests"
|
||||
// @ts-ignore
|
||||
fetch.mockSearch()
|
||||
|
||||
|
@ -47,17 +47,13 @@ describe("mysql integrations", () => {
|
|||
makeRequest = generateMakeRequest(apiKey, true)
|
||||
|
||||
mysqlDatasource = await config.api.datasource.create(
|
||||
await databaseTestProviders.mysql.datasource()
|
||||
await getDatasource(DatabaseName.MYSQL)
|
||||
)
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await databaseTestProviders.mysql.stop()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
primaryMySqlTable = await config.createTable({
|
||||
name: uuidv4(),
|
||||
name: generator.guid().replaceAll("-", "_").substring(0, 10),
|
||||
type: "table",
|
||||
primary: ["id"],
|
||||
schema: {
|
||||
|
@ -117,7 +113,7 @@ describe("mysql integrations", () => {
|
|||
it("should be able to verify the connection", async () => {
|
||||
await config.api.datasource.verify(
|
||||
{
|
||||
datasource: await databaseTestProviders.mysql.datasource(),
|
||||
datasource: await getDatasource(DatabaseName.MYSQL),
|
||||
},
|
||||
{
|
||||
body: {
|
||||
|
@ -128,7 +124,7 @@ describe("mysql integrations", () => {
|
|||
})
|
||||
|
||||
it("should state an invalid datasource cannot connect", async () => {
|
||||
const dbConfig = await databaseTestProviders.mysql.datasource()
|
||||
const dbConfig = await getDatasource(DatabaseName.MYSQL)
|
||||
await config.api.datasource.verify(
|
||||
{
|
||||
datasource: {
|
||||
|
@ -168,7 +164,7 @@ describe("mysql integrations", () => {
|
|||
const database2 = "test-2"
|
||||
|
||||
beforeAll(async () => {
|
||||
const dsConfig = await databaseTestProviders.mysql.datasource()
|
||||
const dsConfig = await getDatasource(DatabaseName.MYSQL)
|
||||
const dbConfig = dsConfig.config!
|
||||
|
||||
client = await mysql.createConnection(dbConfig)
|
||||
|
@ -237,11 +233,11 @@ describe("mysql integrations", () => {
|
|||
beforeEach(async () => {
|
||||
client = await mysql.createConnection(
|
||||
(
|
||||
await databaseTestProviders.mysql.datasource()
|
||||
await getDatasource(DatabaseName.MYSQL)
|
||||
).config!
|
||||
)
|
||||
mysqlDatasource = await config.api.datasource.create(
|
||||
await databaseTestProviders.mysql.datasource()
|
||||
await getDatasource(DatabaseName.MYSQL)
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -253,7 +249,7 @@ describe("mysql integrations", () => {
|
|||
const addColumnToTable: TableRequest = {
|
||||
type: "table",
|
||||
sourceType: TableSourceType.EXTERNAL,
|
||||
name: "table",
|
||||
name: generator.guid().replaceAll("-", "_").substring(0, 10),
|
||||
sourceId: mysqlDatasource._id!,
|
||||
primary: ["id"],
|
||||
schema: {
|
||||
|
@ -301,14 +297,16 @@ describe("mysql integrations", () => {
|
|||
},
|
||||
},
|
||||
created: true,
|
||||
_id: `${mysqlDatasource._id}__table`,
|
||||
_id: `${mysqlDatasource._id}__${addColumnToTable.name}`,
|
||||
}
|
||||
delete expectedTable._add
|
||||
|
||||
expect(emitDatasourceUpdateMock).toHaveBeenCalledTimes(1)
|
||||
const emittedDatasource: Datasource =
|
||||
emitDatasourceUpdateMock.mock.calls[0][1]
|
||||
expect(emittedDatasource.entities!["table"]).toEqual(expectedTable)
|
||||
expect(emittedDatasource.entities![expectedTable.name]).toEqual(
|
||||
expectedTable
|
||||
)
|
||||
})
|
||||
|
||||
it("will rename a column", async () => {
|
||||
|
|
Loading…
Reference in New Issue