Add test deleting external ds
This commit is contained in:
parent
ccdb032449
commit
f2e46863f6
|
@ -1,17 +1,20 @@
|
|||
import _ from "lodash"
|
||||
import tk from "timekeeper"
|
||||
|
||||
import { context, roles } from "@budibase/backend-core"
|
||||
import { automations } from "@budibase/pro"
|
||||
import {
|
||||
CreateRowActionRequest,
|
||||
DocumentType,
|
||||
PermissionLevel,
|
||||
RowActionResponse,
|
||||
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 { roles } from "@budibase/backend-core"
|
||||
import { automations } from "@budibase/pro"
|
||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||
import { generateRowActionsID } from "../../../db/utils"
|
||||
|
||||
const expectAutomationId = () =>
|
||||
expect.stringMatching(`^${DocumentType.AUTOMATION}_.+`)
|
||||
|
@ -962,5 +965,57 @@ describe("/rowsActions", () => {
|
|||
status: 200,
|
||||
})
|
||||
})
|
||||
|
||||
it.each([
|
||||
[
|
||||
"external",
|
||||
async () => {
|
||||
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()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue