Convert rowAction.spec.ts to datasourceDescribe

This commit is contained in:
Sam Rose 2024-11-06 16:51:40 +00:00
parent 26aaac1d06
commit 6801ade481
No known key found for this signature in database
12 changed files with 96 additions and 94 deletions

View File

@ -19,8 +19,7 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { import {
DatabaseName, DatabaseName,
getDatasource, datasourceDescribe,
knexClient,
} from "../../../integrations/tests/utils" } from "../../../integrations/tests/utils"
import { tableForDatasource } from "../../../tests/utilities/structures" import { tableForDatasource } from "../../../tests/utilities/structures"
import nock from "nock" import nock from "nock"
@ -69,7 +68,7 @@ describe("/datasources", () => {
{ {
status: 500, status: 500,
body: { body: {
message: "No datasource implementation found.", message: 'No datasource implementation found called: "invalid"',
}, },
} }
) )
@ -163,21 +162,23 @@ describe("/datasources", () => {
}) })
}) })
}) })
})
describe.each([ datasourceDescribe(
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], { name: "%s", exclude: [DatabaseName.MONGODB, DatabaseName.SQS] },
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], ({ config, dsProvider }) => {
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], let datasource: Datasource
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("%s", (_, dsProvider) => {
let rawDatasource: Datasource let rawDatasource: Datasource
let client: Knex let client: Knex
beforeEach(async () => { beforeEach(async () => {
rawDatasource = await dsProvider const ds = await dsProvider()
datasource = await config.api.datasource.create(rawDatasource) rawDatasource = ds.rawDatasource!
client = await knexClient(rawDatasource) datasource = ds.datasource!
client = ds.client!
jest.clearAllMocks()
nock.cleanAll()
}) })
describe("get", () => { describe("get", () => {
@ -491,5 +492,5 @@ describe("/datasources", () => {
) )
}) })
}) })
}) }
}) )

View File

@ -46,7 +46,7 @@ datasourceDescribe(
} }
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
rawDatasource = ds.rawDatasource! rawDatasource = ds.rawDatasource!
datasource = ds.datasource! datasource = ds.datasource!
client = ds.client! client = ds.client!

View File

@ -64,7 +64,7 @@ datasourceDescribe(
} }
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource! datasource = ds.datasource!
}) })

View File

@ -92,7 +92,7 @@ datasourceDescribe(
let table: Table let table: Table
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource datasource = ds.datasource
client = ds.client client = ds.client
}) })

View File

@ -9,15 +9,20 @@ import {
import { automations } from "@budibase/pro" import { automations } from "@budibase/pro"
import { import {
CreateRowActionRequest, CreateRowActionRequest,
Datasource,
DocumentType, DocumentType,
PermissionLevel, PermissionLevel,
RowActionResponse, RowActionResponse,
Table,
TableRowActions, TableRowActions,
} from "@budibase/types" } from "@budibase/types"
import * as setup from "./utilities" import * as setup from "./utilities"
import { generator, mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
import { Expectations } from "../../../tests/utilities/api/base" 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" import { generateRowActionsID } from "../../../db/utils"
const expectAutomationId = () => const expectAutomationId = () =>
@ -969,36 +974,33 @@ describe("/rowsActions", () => {
status: 200, status: 200,
}) })
}) })
})
})
it.each([ datasourceDescribe(
[ { name: "row actions (%s)", only: [DatabaseName.SQS, DatabaseName.POSTGRES] },
"internal", ({ config, dsProvider, isInternal }) => {
async () => { let datasource: Datasource | undefined
await config.newTenant()
beforeAll(async () => {
const ds = await dsProvider()
datasource = ds.datasource
})
async function getTable(): Promise<Table> {
if (isInternal) {
await config.api.application.addSampleData(config.getAppId()) await config.api.application.addSampleData(config.getAppId())
const tables = await config.api.table.fetch() const tables = await config.api.table.fetch()
const table = tables.find( return tables.find(t => t.sourceId === DEFAULT_BB_DATASOURCE_ID)!
t => t.sourceId === DEFAULT_BB_DATASOURCE_ID } else {
)!
return table
},
],
[
"external",
async () => {
await config.newTenant()
const ds = await config.createDatasource({
datasource: await getDatasource(DatabaseName.POSTGRES),
})
const table = await config.api.table.save( const table = await config.api.table.save(
setup.structures.tableForDatasource(ds) setup.structures.tableForDatasource(datasource!)
) )
return table return table
}, }
], }
])(
"should delete all the row actions (and automations) for its tables when a datasource is deleted", it("should delete all the row actions (and automations) for its tables when a datasource is deleted", async () => {
async (_, getTable) => {
async function getRowActionsFromDb(tableId: string) { async function getRowActionsFromDb(tableId: string) {
return await context.doInAppContext(config.getAppId(), async () => { return await context.doInAppContext(config.getAppId(), async () => {
const db = context.getAppDB() const db = context.getAppDB()
@ -1032,7 +1034,6 @@ describe("/rowsActions", () => {
expect(automationsResp.automations).toHaveLength(0) expect(automationsResp.automations).toHaveLength(0)
expect(await getRowActionsFromDb(tableId)).toBeUndefined() expect(await getRowActionsFromDb(tableId)).toBeUndefined()
})
} }
) )
})
})

View File

@ -95,7 +95,7 @@ datasourceDescribe(
} }
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource datasource = ds.datasource
client = ds.client client = ds.client

View File

@ -44,7 +44,7 @@ datasourceDescribe(
let datasource: Datasource | undefined let datasource: Datasource | undefined
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource datasource = ds.datasource
}) })

View File

@ -24,7 +24,7 @@ datasourceDescribe(
const database2 = generator.guid() const database2 = generator.guid()
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
rawDatasource = ds.rawDatasource! rawDatasource = ds.rawDatasource!
datasource = ds.datasource! datasource = ds.datasource!
client = ds.client! client = ds.client!
@ -88,7 +88,7 @@ datasourceDescribe(
let client: Knex let client: Knex
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource! datasource = ds.datasource!
client = ds.client! client = ds.client!
}) })

View File

@ -15,7 +15,7 @@ datasourceDescribe(
let client: Knex let client: Knex
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource! datasource = ds.datasource!
client = ds.client! client = ds.client!
}) })
@ -218,7 +218,7 @@ datasourceDescribe(
let schema2: string let schema2: string
beforeEach(async () => { beforeEach(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource! datasource = ds.datasource!
const rawDatasource = ds.rawDatasource! const rawDatasource = ds.rawDatasource!

View File

@ -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 { export default {

View File

@ -49,7 +49,7 @@ export interface DatasourceDescribeReturnPromise {
export interface DatasourceDescribeReturn { export interface DatasourceDescribeReturn {
name: DatabaseName name: DatabaseName
config: TestConfiguration config: TestConfiguration
dsProvider: Promise<DatasourceDescribeReturnPromise> dsProvider: () => Promise<DatasourceDescribeReturnPromise>
isInternal: boolean isInternal: boolean
isExternal: boolean isExternal: boolean
isSql: boolean isSql: boolean
@ -116,7 +116,7 @@ export function datasourceDescribe(
cb({ cb({
name, name,
config, config,
dsProvider: createDatasources(config, name), dsProvider: () => createDatasources(config, name),
isInternal: name === DatabaseName.SQS, isInternal: name === DatabaseName.SQS,
isExternal: name !== DatabaseName.SQS, isExternal: name !== DatabaseName.SQS,
isSql: [ isSql: [

View File

@ -26,7 +26,7 @@ datasourceDescribe(
let table: Table let table: Table
beforeAll(async () => { beforeAll(async () => {
const ds = await dsProvider const ds = await dsProvider()
datasource = ds.datasource datasource = ds.datasource
}) })