Convert rowAction.spec.ts to datasourceDescribe
This commit is contained in:
parent
26aaac1d06
commit
6801ade481
|
@ -19,8 +19,7 @@ import {
|
|||
} from "@budibase/types"
|
||||
import {
|
||||
DatabaseName,
|
||||
getDatasource,
|
||||
knexClient,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { tableForDatasource } from "../../../tests/utilities/structures"
|
||||
import nock from "nock"
|
||||
|
@ -69,7 +68,7 @@ describe("/datasources", () => {
|
|||
{
|
||||
status: 500,
|
||||
body: {
|
||||
message: "No datasource implementation found.",
|
||||
message: 'No datasource implementation found called: "invalid"',
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -163,21 +162,23 @@ describe("/datasources", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe.each([
|
||||
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
|
||||
])("%s", (_, dsProvider) => {
|
||||
datasourceDescribe(
|
||||
{ name: "%s", exclude: [DatabaseName.MONGODB, DatabaseName.SQS] },
|
||||
({ config, dsProvider }) => {
|
||||
let datasource: Datasource
|
||||
let rawDatasource: Datasource
|
||||
let client: Knex
|
||||
|
||||
beforeEach(async () => {
|
||||
rawDatasource = await dsProvider
|
||||
datasource = await config.api.datasource.create(rawDatasource)
|
||||
client = await knexClient(rawDatasource)
|
||||
const ds = await dsProvider()
|
||||
rawDatasource = ds.rawDatasource!
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
|
||||
jest.clearAllMocks()
|
||||
nock.cleanAll()
|
||||
})
|
||||
|
||||
describe("get", () => {
|
||||
|
@ -491,5 +492,5 @@ describe("/datasources", () => {
|
|||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
|
|
@ -46,7 +46,7 @@ datasourceDescribe(
|
|||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
rawDatasource = ds.rawDatasource!
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
|
|
|
@ -64,7 +64,7 @@ datasourceDescribe(
|
|||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
})
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ datasourceDescribe(
|
|||
let table: Table
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
client = ds.client
|
||||
})
|
||||
|
|
|
@ -9,15 +9,20 @@ import {
|
|||
import { automations } from "@budibase/pro"
|
||||
import {
|
||||
CreateRowActionRequest,
|
||||
Datasource,
|
||||
DocumentType,
|
||||
PermissionLevel,
|
||||
RowActionResponse,
|
||||
Table,
|
||||
TableRowActions,
|
||||
} from "@budibase/types"
|
||||
import * as setup from "./utilities"
|
||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||
import { Expectations } from "../../../tests/utilities/api/base"
|
||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||
import {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
} from "../../../integrations/tests/utils"
|
||||
import { generateRowActionsID } from "../../../db/utils"
|
||||
|
||||
const expectAutomationId = () =>
|
||||
|
@ -969,70 +974,66 @@ describe("/rowsActions", () => {
|
|||
status: 200,
|
||||
})
|
||||
})
|
||||
|
||||
it.each([
|
||||
[
|
||||
"internal",
|
||||
async () => {
|
||||
await config.newTenant()
|
||||
await config.api.application.addSampleData(config.getAppId())
|
||||
const tables = await config.api.table.fetch()
|
||||
const table = tables.find(
|
||||
t => t.sourceId === DEFAULT_BB_DATASOURCE_ID
|
||||
)!
|
||||
return table
|
||||
},
|
||||
],
|
||||
[
|
||||
"external",
|
||||
async () => {
|
||||
await config.newTenant()
|
||||
const ds = await config.createDatasource({
|
||||
datasource: await getDatasource(DatabaseName.POSTGRES),
|
||||
})
|
||||
const table = await config.api.table.save(
|
||||
setup.structures.tableForDatasource(ds)
|
||||
)
|
||||
return table
|
||||
},
|
||||
],
|
||||
])(
|
||||
"should delete all the row actions (and automations) for its tables when a datasource is deleted",
|
||||
async (_, getTable) => {
|
||||
async function getRowActionsFromDb(tableId: string) {
|
||||
return await context.doInAppContext(config.getAppId(), async () => {
|
||||
const db = context.getAppDB()
|
||||
const tableDoc = await db.tryGet<TableRowActions>(
|
||||
generateRowActionsID(tableId)
|
||||
)
|
||||
return tableDoc
|
||||
})
|
||||
}
|
||||
|
||||
const table = await getTable()
|
||||
const tableId = table._id!
|
||||
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
|
||||
const { actions } = (await getRowActionsFromDb(tableId))!
|
||||
expect(Object.entries(actions)).toHaveLength(2)
|
||||
|
||||
const { automations } = await config.api.automation.fetch()
|
||||
expect(automations).toHaveLength(2)
|
||||
|
||||
const datasource = await config.api.datasource.get(table.sourceId)
|
||||
await config.api.datasource.delete(datasource)
|
||||
|
||||
const automationsResp = await config.api.automation.fetch()
|
||||
expect(automationsResp.automations).toHaveLength(0)
|
||||
|
||||
expect(await getRowActionsFromDb(tableId)).toBeUndefined()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "row actions (%s)", only: [DatabaseName.SQS, DatabaseName.POSTGRES] },
|
||||
({ config, dsProvider, isInternal }) => {
|
||||
let datasource: Datasource | undefined
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
|
||||
async function getTable(): Promise<Table> {
|
||||
if (isInternal) {
|
||||
await config.api.application.addSampleData(config.getAppId())
|
||||
const tables = await config.api.table.fetch()
|
||||
return tables.find(t => t.sourceId === DEFAULT_BB_DATASOURCE_ID)!
|
||||
} else {
|
||||
const table = await config.api.table.save(
|
||||
setup.structures.tableForDatasource(datasource!)
|
||||
)
|
||||
return table
|
||||
}
|
||||
}
|
||||
|
||||
it("should delete all the row actions (and automations) for its tables when a datasource is deleted", async () => {
|
||||
async function getRowActionsFromDb(tableId: string) {
|
||||
return await context.doInAppContext(config.getAppId(), async () => {
|
||||
const db = context.getAppDB()
|
||||
const tableDoc = await db.tryGet<TableRowActions>(
|
||||
generateRowActionsID(tableId)
|
||||
)
|
||||
return tableDoc
|
||||
})
|
||||
}
|
||||
|
||||
const table = await getTable()
|
||||
const tableId = table._id!
|
||||
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
await config.api.rowAction.save(tableId, {
|
||||
name: generator.guid(),
|
||||
})
|
||||
|
||||
const { actions } = (await getRowActionsFromDb(tableId))!
|
||||
expect(Object.entries(actions)).toHaveLength(2)
|
||||
|
||||
const { automations } = await config.api.automation.fetch()
|
||||
expect(automations).toHaveLength(2)
|
||||
|
||||
const datasource = await config.api.datasource.get(table.sourceId)
|
||||
await config.api.datasource.delete(datasource)
|
||||
|
||||
const automationsResp = await config.api.automation.fetch()
|
||||
expect(automationsResp.automations).toHaveLength(0)
|
||||
|
||||
expect(await getRowActionsFromDb(tableId)).toBeUndefined()
|
||||
})
|
||||
}
|
||||
)
|
||||
|
|
|
@ -95,7 +95,7 @@ datasourceDescribe(
|
|||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
client = ds.client
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ datasourceDescribe(
|
|||
let datasource: Datasource | undefined
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ datasourceDescribe(
|
|||
const database2 = generator.guid()
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
rawDatasource = ds.rawDatasource!
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
|
@ -88,7 +88,7 @@ datasourceDescribe(
|
|||
let client: Knex
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
|
|
|
@ -15,7 +15,7 @@ datasourceDescribe(
|
|||
let client: Knex
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
client = ds.client!
|
||||
})
|
||||
|
@ -218,7 +218,7 @@ datasourceDescribe(
|
|||
let schema2: string
|
||||
|
||||
beforeEach(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource!
|
||||
const rawDatasource = ds.rawDatasource!
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ export async function getIntegration(integration: SourceName) {
|
|||
}
|
||||
}
|
||||
}
|
||||
throw new Error("No datasource implementation found.")
|
||||
throw new Error(`No datasource implementation found called: "${integration}"`)
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
@ -49,7 +49,7 @@ export interface DatasourceDescribeReturnPromise {
|
|||
export interface DatasourceDescribeReturn {
|
||||
name: DatabaseName
|
||||
config: TestConfiguration
|
||||
dsProvider: Promise<DatasourceDescribeReturnPromise>
|
||||
dsProvider: () => Promise<DatasourceDescribeReturnPromise>
|
||||
isInternal: boolean
|
||||
isExternal: boolean
|
||||
isSql: boolean
|
||||
|
@ -116,7 +116,7 @@ export function datasourceDescribe(
|
|||
cb({
|
||||
name,
|
||||
config,
|
||||
dsProvider: createDatasources(config, name),
|
||||
dsProvider: () => createDatasources(config, name),
|
||||
isInternal: name === DatabaseName.SQS,
|
||||
isExternal: name !== DatabaseName.SQS,
|
||||
isSql: [
|
||||
|
|
|
@ -26,7 +26,7 @@ datasourceDescribe(
|
|||
let table: Table
|
||||
|
||||
beforeAll(async () => {
|
||||
const ds = await dsProvider
|
||||
const ds = await dsProvider()
|
||||
datasource = ds.datasource
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue