Merge pull request #15027 from Budibase/fix/use-direct-describe

Direct describe rather than datasourceDescribe
This commit is contained in:
Michael Drury 2024-11-20 15:29:08 +00:00 committed by GitHub
commit 0a3000e3ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 14372 additions and 14185 deletions

View File

@ -164,9 +164,12 @@ describe("/datasources", () => {
}) })
}) })
datasourceDescribe( const descriptions = datasourceDescribe({
{ name: "%s", exclude: [DatabaseName.MONGODB, DatabaseName.SQS] }, exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
({ config, dsProvider }) => { })
if (descriptions.length) {
describe.each(descriptions)("$dbName", ({ config, dsProvider }) => {
let datasource: Datasource let datasource: Datasource
let rawDatasource: Datasource let rawDatasource: Datasource
let client: Knex let client: Knex
@ -492,5 +495,5 @@ datasourceDescribe(
) )
}) })
}) })
} })
) }

View File

@ -14,8 +14,13 @@ import { events } from "@budibase/backend-core"
import { Knex } from "knex" import { Knex } from "knex"
import { generator } from "@budibase/backend-core/tests" import { generator } from "@budibase/backend-core/tests"
datasourceDescribe( const descriptions = datasourceDescribe({
{ name: "queries (%s)", exclude: [DatabaseName.MONGODB, DatabaseName.SQS] }, exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
})
if (descriptions.length) {
describe.each(descriptions)(
"queries ($dbName)",
({ config, dsProvider, isOracle, isMSSQL, isPostgres }) => { ({ config, dsProvider, isOracle, isMSSQL, isPostgres }) => {
let rawDatasource: Datasource let rawDatasource: Datasource
let datasource: Datasource let datasource: Datasource
@ -945,4 +950,5 @@ datasourceDescribe(
}) })
}) })
} }
) )
}

View File

@ -9,8 +9,11 @@ import { generator } from "@budibase/backend-core/tests"
const expectValidId = expect.stringMatching(/^\w{24}$/) const expectValidId = expect.stringMatching(/^\w{24}$/)
const expectValidBsonObjectId = expect.any(BSON.ObjectId) const expectValidBsonObjectId = expect.any(BSON.ObjectId)
datasourceDescribe( const descriptions = datasourceDescribe({ only: [DatabaseName.MONGODB] })
{ name: "/queries", only: [DatabaseName.MONGODB] },
if (descriptions.length) {
describe.each(descriptions)(
"/queries ($dbName)",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let collection: string let collection: string
let datasource: Datasource let datasource: Datasource
@ -714,4 +717,5 @@ datasourceDescribe(
}) })
}) })
} }
) )
}

View File

@ -85,8 +85,11 @@ function encodeJS(binding: string) {
return `{{ js "${Buffer.from(binding).toString("base64")}"}}` return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
} }
datasourceDescribe( const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
{ name: "/rows (%s)", exclude: [DatabaseName.MONGODB] },
if (descriptions.length) {
describe.each(descriptions)(
"/rows ($dbName)",
({ config, dsProvider, isInternal, isMSSQL, isOracle }) => { ({ config, dsProvider, isInternal, isMSSQL, isOracle }) => {
let table: Table let table: Table
let datasource: Datasource | undefined let datasource: Datasource | undefined
@ -338,7 +341,9 @@ datasourceDescribe(
await new Promise(r => setTimeout(r, Math.random() * 50)) await new Promise(r => setTimeout(r, Math.random() * 50))
} }
} }
throw new Error(`Failed to create row after ${attempts} attempts`) throw new Error(
`Failed to create row after ${attempts} attempts`
)
}) })
) )
@ -1495,7 +1500,9 @@ datasourceDescribe(
it("should return no errors on valid row", async () => { it("should return no errors on valid row", async () => {
const rowUsage = await getRowUsage() const rowUsage = await getRowUsage()
const res = await config.api.row.validate(table._id!, { name: "ivan" }) const res = await config.api.row.validate(table._id!, {
name: "ivan",
})
expect(res.valid).toBe(true) expect(res.valid).toBe(true)
expect(Object.keys(res.errors)).toEqual([]) expect(Object.keys(res.errors)).toEqual([])
@ -2244,7 +2251,10 @@ datasourceDescribe(
const table = await config.api.table.save(tableRequest) const table = await config.api.table.save(tableRequest)
const toCreate = generator const toCreate = generator
.unique(() => generator.integer({ min: 0, max: 10000 }), 10) .unique(() => generator.integer({ min: 0, max: 10000 }), 10)
.map(number => ({ number, string: generator.word({ length: 30 }) })) .map(number => ({
number,
string: generator.word({ length: 30 }),
}))
const rows = await Promise.all( const rows = await Promise.all(
toCreate.map(d => config.api.row.save(table._id!, d)) toCreate.map(d => config.api.row.save(table._id!, d))
@ -3019,7 +3029,10 @@ datasourceDescribe(
}, },
], ],
["from original saved row", (row: Row) => row], ["from original saved row", (row: Row) => row],
["from updated row", (row: Row) => config.api.row.save(viewId, row)], [
"from updated row",
(row: Row) => config.api.row.save(viewId, row),
],
] ]
it.each(testScenarios)( it.each(testScenarios)(
@ -3243,7 +3256,10 @@ datasourceDescribe(
async function updateFormulaColumn( async function updateFormulaColumn(
formula: string, formula: string,
opts?: { responseType?: FormulaResponseType; formulaType?: FormulaType } opts?: {
responseType?: FormulaResponseType
formulaType?: FormulaType
}
) { ) {
table = await config.api.table.save({ table = await config.api.table.save({
...table, ...table,
@ -3480,6 +3496,5 @@ datasourceDescribe(
}) })
}) })
} }
) )
}
// todo: remove me

View File

@ -977,8 +977,13 @@ describe("/rowsActions", () => {
}) })
}) })
datasourceDescribe( const descriptions = datasourceDescribe({
{ name: "row actions (%s)", only: [DatabaseName.SQS, DatabaseName.POSTGRES] }, only: [DatabaseName.SQS, DatabaseName.POSTGRES],
})
if (descriptions.length) {
describe.each(descriptions)(
"row actions ($dbName)",
({ config, dsProvider, isInternal }) => { ({ config, dsProvider, isInternal }) => {
let datasource: Datasource | undefined let datasource: Datasource | undefined
@ -1036,4 +1041,5 @@ datasourceDescribe(
expect(await getRowActionsFromDb(tableId)).toBeUndefined() expect(await getRowActionsFromDb(tableId)).toBeUndefined()
}) })
} }
) )
}

View File

@ -59,11 +59,11 @@ jest.mock("@budibase/pro", () => ({
}, },
})) }))
datasourceDescribe( const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
{
name: "search (%s)", if (descriptions.length) {
exclude: [DatabaseName.MONGODB], describe.each(descriptions)(
}, "search ($dbName)",
({ config, dsProvider, isInternal, isOracle, isSql }) => { ({ config, dsProvider, isInternal, isOracle, isSql }) => {
let datasource: Datasource | undefined let datasource: Datasource | undefined
let client: Knex | undefined let client: Knex | undefined
@ -198,7 +198,9 @@ datasourceDescribe(
]) ])
} }
describe.each(tableOrView)("from %s", (sourceType, createTableOrView) => { describe.each(tableOrView)(
"from %s",
(sourceType, createTableOrView) => {
const isView = sourceType === "view" const isView = sourceType === "view"
class SearchAssertion { class SearchAssertion {
@ -263,12 +265,16 @@ datasourceDescribe(
expectedRow: T, expectedRow: T,
foundRows: T[] foundRows: T[]
): NonNullable<T> { ): NonNullable<T> {
const row = foundRows.find(row => this.isMatch(expectedRow, row)) const row = foundRows.find(row =>
this.isMatch(expectedRow, row)
)
if (!row) { if (!row) {
const fields = Object.keys(expectedRow) const fields = Object.keys(expectedRow)
// To make the error message more readable, we only include the fields // To make the error message more readable, we only include the fields
// that are present in the expected row. // that are present in the expected row.
const searchedObjects = foundRows.map(row => _.pick(row, fields)) const searchedObjects = foundRows.map(row =>
_.pick(row, fields)
)
throw new Error( throw new Error(
`Failed to find row:\n\n${JSON.stringify( `Failed to find row:\n\n${JSON.stringify(
expectedRow, expectedRow,
@ -316,7 +322,9 @@ datasourceDescribe(
expect([...foundRows]).toEqual( expect([...foundRows]).toEqual(
expect.arrayContaining( expect.arrayContaining(
expectedRows.map((expectedRow: any) => expectedRows.map((expectedRow: any) =>
expect.objectContaining(this.popRow(expectedRow, foundRows)) expect.objectContaining(
this.popRow(expectedRow, foundRows)
)
) )
) )
) )
@ -344,7 +352,9 @@ datasourceDescribe(
} }
// Asserts that the query doesn't return a property, e.g. pagination parameters. // Asserts that the query doesn't return a property, e.g. pagination parameters.
async toNotHaveProperty(properties: (keyof SearchResponse<Row>)[]) { async toNotHaveProperty(
properties: (keyof SearchResponse<Row>)[]
) {
const response = await this.performSearch() const response = await this.performSearch()
const cloned = cloneDeep(response) const cloned = cloneDeep(response)
for (let property of properties) { for (let property of properties) {
@ -366,7 +376,9 @@ datasourceDescribe(
expect([...foundRows]).toEqual( expect([...foundRows]).toEqual(
expect.arrayContaining( expect.arrayContaining(
expectedRows.map((expectedRow: any) => expectedRows.map((expectedRow: any) =>
expect.objectContaining(this.popRow(expectedRow, foundRows)) expect.objectContaining(
this.popRow(expectedRow, foundRows)
)
) )
) )
) )
@ -403,15 +415,15 @@ datasourceDescribe(
describe("equal", () => { describe("equal", () => {
it("successfully finds true row", async () => { it("successfully finds true row", async () => {
await expectQuery({ equal: { isTrue: true } }).toMatchExactly([ await expectQuery({ equal: { isTrue: true } }).toMatchExactly(
{ isTrue: true }, [{ isTrue: true }]
]) )
}) })
it("successfully finds false row", async () => { it("successfully finds false row", async () => {
await expectQuery({ equal: { isTrue: false } }).toMatchExactly([ await expectQuery({
{ isTrue: false }, equal: { isTrue: false },
]) }).toMatchExactly([{ isTrue: false }])
}) })
}) })
@ -431,9 +443,9 @@ datasourceDescribe(
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds true row", async () => { it("successfully finds true row", async () => {
await expectQuery({ oneOf: { isTrue: [true] } }).toContainExactly( await expectQuery({
[{ isTrue: true }] oneOf: { isTrue: [true] },
) }).toContainExactly([{ isTrue: true }])
}) })
it("successfully finds false row", async () => { it("successfully finds false row", async () => {
@ -485,7 +497,10 @@ datasourceDescribe(
name: currentUser.firstName, name: currentUser.firstName,
appointment: future.toISOString(), appointment: future.toISOString(),
}, },
{ name: "serverDate", appointment: serverTime.toISOString() }, {
name: "serverDate",
appointment: serverTime.toISOString(),
},
{ {
name: "single user, session user", name: "single user, session user",
single_user: currentUser, single_user: currentUser,
@ -540,7 +555,10 @@ datasourceDescribe(
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
appointment: { name: "appointment", type: FieldType.DATETIME }, appointment: {
name: "appointment",
type: FieldType.DATETIME,
},
single_user: { single_user: {
name: "single_user", name: "single_user",
type: FieldType.BB_REFERENCE_SINGLE, type: FieldType.BB_REFERENCE_SINGLE,
@ -586,7 +604,9 @@ datasourceDescribe(
it("should return all rows matching the session user firstname when logical operator used", async () => { it("should return all rows matching the session user firstname when logical operator used", async () => {
await expectQuery({ await expectQuery({
$and: { $and: {
conditions: [{ equal: { name: "{{ [user].firstName }}" } }], conditions: [
{ equal: { name: "{{ [user].firstName }}" } },
],
}, },
}).toContainExactly([ }).toContainExactly([
{ {
@ -610,7 +630,10 @@ datasourceDescribe(
name: config.getUser().firstName, name: config.getUser().firstName,
appointment: future.toISOString(), appointment: future.toISOString(),
}, },
{ name: "serverDate", appointment: serverTime.toISOString() }, {
name: "serverDate",
appointment: serverTime.toISOString(),
},
]) ])
}) })
}) })
@ -626,7 +649,10 @@ datasourceDescribe(
}).toContainExactly([ }).toContainExactly([
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" }, { name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" }, { name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
{ name: "serverDate", appointment: serverTime.toISOString() }, {
name: "serverDate",
appointment: serverTime.toISOString(),
},
]) ])
}) })
@ -736,7 +762,9 @@ datasourceDescribe(
it("should not match the session user id in a deprecated multi user field", async () => { it("should not match the session user id in a deprecated multi user field", async () => {
await expectQuery({ await expectQuery({
notContains: { deprecated_multi_user: ["{{ [user]._id }}"] }, notContains: {
deprecated_multi_user: ["{{ [user]._id }}"],
},
notEmpty: { deprecated_multi_user: true }, notEmpty: { deprecated_multi_user: true },
}).toContainExactly([ }).toContainExactly([
{ {
@ -870,9 +898,9 @@ datasourceDescribe(
describe("equal", () => { describe("equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ equal: { name: "foo" } }).toContainExactly([ await expectQuery({
{ name: "foo" }, equal: { name: "foo" },
]) }).toContainExactly([{ name: "foo" }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -897,27 +925,29 @@ datasourceDescribe(
describe("notEqual", () => { describe("notEqual", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ notEqual: { name: "foo" } }).toContainExactly( await expectQuery({
[{ name: "bar" }] notEqual: { name: "foo" },
) }).toContainExactly([{ name: "bar" }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ notEqual: { name: "bar" } }).toContainExactly( await expectQuery({
[{ name: "foo" }] notEqual: { name: "bar" },
) }).toContainExactly([{ name: "foo" }])
}) })
}) })
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ oneOf: { name: ["foo"] } }).toContainExactly([ await expectQuery({
{ name: "foo" }, oneOf: { name: ["foo"] },
]) }).toContainExactly([{ name: "foo" }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ oneOf: { name: ["none"] } }).toFindNothing() await expectQuery({
oneOf: { name: ["none"] },
}).toFindNothing()
}) })
it("can have multiple values for same column", async () => { it("can have multiple values for same column", async () => {
@ -965,9 +995,9 @@ datasourceDescribe(
describe("fuzzy", () => { describe("fuzzy", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ fuzzy: { name: "oo" } }).toContainExactly([ await expectQuery({ fuzzy: { name: "oo" } }).toContainExactly(
{ name: "foo" }, [{ name: "foo" }]
]) )
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -977,19 +1007,21 @@ datasourceDescribe(
describe("string", () => { describe("string", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ string: { name: "fo" } }).toContainExactly([ await expectQuery({
{ name: "foo" }, string: { name: "fo" },
]) }).toContainExactly([{ name: "foo" }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ string: { name: "none" } }).toFindNothing() await expectQuery({
string: { name: "none" },
}).toFindNothing()
}) })
it("is case-insensitive", async () => { it("is case-insensitive", async () => {
await expectQuery({ string: { name: "FO" } }).toContainExactly([ await expectQuery({
{ name: "foo" }, string: { name: "FO" },
]) }).toContainExactly([{ name: "foo" }])
}) })
}) })
@ -1048,10 +1080,9 @@ datasourceDescribe(
describe("notEmpty", () => { describe("notEmpty", () => {
it("finds all non-empty rows", async () => { it("finds all non-empty rows", async () => {
await expectQuery({ notEmpty: { name: null } }).toContainExactly([ await expectQuery({
{ name: "foo" }, notEmpty: { name: null },
{ name: "bar" }, }).toContainExactly([{ name: "foo" }, { name: "bar" }])
])
}) })
it("should not be affected by when filter empty behaviour", async () => { it("should not be affected by when filter empty behaviour", async () => {
@ -1167,9 +1198,9 @@ datasourceDescribe(
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ notEqual: { age: 10 } }).toContainExactly([ await expectQuery({ notEqual: { age: 10 } }).toContainExactly(
{ age: 1 }, [{ age: 1 }]
]) )
}) })
}) })
@ -1317,9 +1348,9 @@ datasourceDescribe(
describe("equal", () => { describe("equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ equal: { dob: JAN_1ST } }).toContainExactly([ await expectQuery({
{ dob: JAN_1ST }, equal: { dob: JAN_1ST },
]) }).toContainExactly([{ dob: JAN_1ST }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -1343,13 +1374,15 @@ datasourceDescribe(
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ oneOf: { dob: [JAN_1ST] } }).toContainExactly( await expectQuery({
[{ dob: JAN_1ST }] oneOf: { dob: [JAN_1ST] },
) }).toContainExactly([{ dob: JAN_1ST }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ oneOf: { dob: [JAN_2ND] } }).toFindNothing() await expectQuery({
oneOf: { dob: [JAN_2ND] },
}).toFindNothing()
}) })
}) })
@ -1381,7 +1414,10 @@ datasourceDescribe(
it("greater than equal to", async () => { it("greater than equal to", async () => {
await expectQuery({ await expectQuery({
range: { range: {
dob: { low: JAN_10TH, high: MAX_VALID_DATE.toISOString() }, dob: {
low: JAN_10TH,
high: MAX_VALID_DATE.toISOString(),
},
}, },
}).toContainExactly([{ dob: JAN_10TH }]) }).toContainExactly([{ dob: JAN_10TH }])
}) })
@ -1484,9 +1520,9 @@ datasourceDescribe(
describe("equal", () => { describe("equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ equal: { time: T_1000 } }).toContainExactly( await expectQuery({
[{ time: "10:00:00" }] equal: { time: T_1000 },
) }).toContainExactly([{ time: "10:00:00" }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -1692,7 +1728,9 @@ datasourceDescribe(
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ await expectQuery({
oneOf: { ai: ["Mock LLM Response", "Other LLM Response"] }, oneOf: {
ai: ["Mock LLM Response", "Other LLM Response"],
},
}).toContainExactly([ }).toContainExactly([
{ product: "Big Mac" }, { product: "Big Mac" },
{ product: "McCrispy" }, { product: "McCrispy" },
@ -1745,9 +1783,12 @@ datasourceDescribe(
}) })
it("finds all with empty list", async () => { it("finds all with empty list", async () => {
await expectQuery({ contains: { numbers: [] } }).toContainExactly( await expectQuery({
[{ numbers: ["one", "two"] }, { numbers: ["three"] }] contains: { numbers: [] },
) }).toContainExactly([
{ numbers: ["one", "two"] },
{ numbers: ["three"] },
])
}) })
}) })
@ -1817,14 +1858,18 @@ datasourceDescribe(
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
num: { name: "num", type: FieldType.BIGINT }, num: { name: "num", type: FieldType.BIGINT },
}) })
await createRows([{ num: SMALL }, { num: MEDIUM }, { num: BIG }]) await createRows([
{ num: SMALL },
{ num: MEDIUM },
{ num: BIG },
])
}) })
describe("equal", () => { describe("equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ equal: { num: SMALL } }).toContainExactly([ await expectQuery({ equal: { num: SMALL } }).toContainExactly(
{ num: SMALL }, [{ num: SMALL }]
]) )
}) })
it("successfully finds a big value", async () => { it("successfully finds a big value", async () => {
@ -1840,26 +1885,23 @@ datasourceDescribe(
describe("notEqual", () => { describe("notEqual", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ notEqual: { num: SMALL } }).toContainExactly([ await expectQuery({
{ num: MEDIUM }, notEqual: { num: SMALL },
{ num: BIG }, }).toContainExactly([{ num: MEDIUM }, { num: BIG }])
])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ notEqual: { num: 10 } }).toContainExactly([ await expectQuery({ notEqual: { num: 10 } }).toContainExactly(
{ num: SMALL }, [{ num: SMALL }, { num: MEDIUM }, { num: BIG }]
{ num: MEDIUM }, )
{ num: BIG },
])
}) })
}) })
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ oneOf: { num: [SMALL] } }).toContainExactly([ await expectQuery({
{ num: SMALL }, oneOf: { num: [SMALL] },
]) }).toContainExactly([{ num: SMALL }])
}) })
it("successfully finds all rows", async () => { it("successfully finds all rows", async () => {
@ -1944,7 +1986,9 @@ datasourceDescribe(
describe("not equal", () => { describe("not equal", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ notEqual: { auto: 1 } }).toContainExactly([ await expectQuery({
notEqual: { auto: 1 },
}).toContainExactly([
{ auto: 2 }, { auto: 2 },
{ auto: 3 }, { auto: 3 },
{ auto: 4 }, { auto: 4 },
@ -1958,7 +2002,9 @@ datasourceDescribe(
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ notEqual: { auto: 0 } }).toContainExactly([ await expectQuery({
notEqual: { auto: 0 },
}).toContainExactly([
{ auto: 1 }, { auto: 1 },
{ auto: 2 }, { auto: 2 },
{ auto: 3 }, { auto: 3 },
@ -1975,9 +2021,9 @@ datasourceDescribe(
describe("oneOf", () => { describe("oneOf", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ oneOf: { auto: [1] } }).toContainExactly([ await expectQuery({
{ auto: 1 }, oneOf: { auto: [1] },
]) }).toContainExactly([{ auto: 1 }])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -2081,13 +2127,16 @@ datasourceDescribe(
hasNextPage: boolean | undefined = true, hasNextPage: boolean | undefined = true,
rowCount: number = 0 rowCount: number = 0
do { do {
const response = await config.api.row.search(tableOrViewId, { const response = await config.api.row.search(
tableOrViewId,
{
tableId: tableOrViewId, tableId: tableOrViewId,
limit: 1, limit: 1,
paginate: true, paginate: true,
query: {}, query: {},
bookmark, bookmark,
}) }
)
bookmark = response.bookmark bookmark = response.bookmark
hasNextPage = response.hasNextPage hasNextPage = response.hasNextPage
expect(response.rows.length).toEqual(1) expect(response.rows.length).toEqual(1)
@ -2105,13 +2154,16 @@ datasourceDescribe(
// eslint-disable-next-line no-constant-condition // eslint-disable-next-line no-constant-condition
while (true) { while (true) {
const response = await config.api.row.search(tableOrViewId, { const response = await config.api.row.search(
tableOrViewId,
{
tableId: tableOrViewId, tableId: tableOrViewId,
limit: 3, limit: 3,
query: {}, query: {},
bookmark, bookmark,
paginate: true, paginate: true,
}) }
)
rows.push(...response.rows) rows.push(...response.rows)
@ -2144,7 +2196,9 @@ datasourceDescribe(
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ equal: { "1:1:name": "none" } }).toFindNothing() await expectQuery({
equal: { "1:1:name": "none" },
}).toFindNothing()
}) })
}) })
@ -2221,7 +2275,11 @@ datasourceDescribe(
}, },
}) })
await createRows([{ user: user1 }, { user: user2 }, { user: null }]) await createRows([
{ user: user1 },
{ user: user2 },
{ user: null },
])
}) })
describe("equal", () => { describe("equal", () => {
@ -2232,7 +2290,9 @@ datasourceDescribe(
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ equal: { user: "us_none" } }).toFindNothing() await expectQuery({
equal: { user: "us_none" },
}).toFindNothing()
}) })
}) })
@ -2270,15 +2330,17 @@ datasourceDescribe(
describe("empty", () => { describe("empty", () => {
it("finds empty rows", async () => { it("finds empty rows", async () => {
await expectQuery({ empty: { user: null } }).toContainExactly([ await expectQuery({ empty: { user: null } }).toContainExactly(
{}, [{}]
]) )
}) })
}) })
describe("notEmpty", () => { describe("notEmpty", () => {
it("finds non-empty rows", async () => { it("finds non-empty rows", async () => {
await expectQuery({ notEmpty: { user: null } }).toContainExactly([ await expectQuery({
notEmpty: { user: null },
}).toContainExactly([
{ user: { _id: user1._id } }, { user: { _id: user1._id } },
{ user: { _id: user2._id } }, { user: { _id: user2._id } },
]) ])
@ -2385,7 +2447,9 @@ datasourceDescribe(
await expectQuery({ await expectQuery({
equal: { number: 1 }, equal: { number: 1 },
contains: { users: [user1._id] }, contains: { users: [user1._id] },
}).toContainExactly([{ users: [{ _id: user1._id }], number: 1 }]) }).toContainExactly([
{ users: [{ _id: user1._id }], number: 1 },
])
}) })
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
@ -2408,15 +2472,18 @@ datasourceDescribe(
let productCategoryTable: Table, productCatRows: Row[] let productCategoryTable: Table, productCatRows: Row[]
beforeAll(async () => { beforeAll(async () => {
const { relatedTable, tableId } = await basicRelationshipTables( const { relatedTable, tableId } =
relationshipType await basicRelationshipTables(relationshipType)
)
tableOrViewId = tableId tableOrViewId = tableId
productCategoryTable = relatedTable productCategoryTable = relatedTable
productCatRows = await Promise.all([ productCatRows = await Promise.all([
config.api.row.save(productCategoryTable._id!, { name: "foo" }), config.api.row.save(productCategoryTable._id!, {
config.api.row.save(productCategoryTable._id!, { name: "bar" }), name: "foo",
}),
config.api.row.save(productCategoryTable._id!, {
name: "bar",
}),
]) ])
await Promise.all([ await Promise.all([
@ -2439,7 +2506,10 @@ datasourceDescribe(
await expectQuery({ await expectQuery({
equal: { ["productCat.name"]: "foo" }, equal: { ["productCat.name"]: "foo" },
}).toContainExactly([ }).toContainExactly([
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, {
name: "foo",
productCat: [{ _id: productCatRows[0]._id }],
},
]) ])
}) })
@ -2447,7 +2517,10 @@ datasourceDescribe(
await expectQuery({ await expectQuery({
equal: { [`${productCategoryTable.name}.name`]: "foo" }, equal: { [`${productCategoryTable.name}.name`]: "foo" },
}).toContainExactly([ }).toContainExactly([
{ name: "foo", productCat: [{ _id: productCatRows[0]._id }] }, {
name: "foo",
productCat: [{ _id: productCatRows[0]._id }],
},
]) ])
}) })
@ -2458,7 +2531,10 @@ datasourceDescribe(
}) })
describe("logical filters", () => { describe("logical filters", () => {
const logicalOperators = [LogicalOperator.AND, LogicalOperator.OR] const logicalOperators = [
LogicalOperator.AND,
LogicalOperator.OR,
]
describe("$and", () => { describe("$and", () => {
it("should allow single conditions", async () => { it("should allow single conditions", async () => {
@ -2699,9 +2775,8 @@ datasourceDescribe(
RelationshipType.MANY_TO_MANY, RelationshipType.MANY_TO_MANY,
])("big relations (%s)", relationshipType => { ])("big relations (%s)", relationshipType => {
beforeAll(async () => { beforeAll(async () => {
const { relatedTable, tableId } = await basicRelationshipTables( const { relatedTable, tableId } =
relationshipType await basicRelationshipTables(relationshipType)
)
tableOrViewId = tableId tableOrViewId = tableId
const mainRow = await config.api.row.save(tableOrViewId, { const mainRow = await config.api.row.save(tableOrViewId, {
name: "foo", name: "foo",
@ -2715,12 +2790,15 @@ datasourceDescribe(
}) })
it("can only pull 10 related rows", async () => { it("can only pull 10 related rows", async () => {
await withCoreEnv({ SQL_MAX_RELATED_ROWS: "10" }, async () => { await withCoreEnv(
{ SQL_MAX_RELATED_ROWS: "10" },
async () => {
const response = await expectQuery({}).toContain([ const response = await expectQuery({}).toContain([
{ name: "foo" }, { name: "foo" },
]) ])
expect(response.rows[0].productCat).toBeArrayOfSize(10) expect(response.rows[0].productCat).toBeArrayOfSize(10)
}) }
)
}) })
it("can pull max rows when env not set (defaults to 500)", async () => { it("can pull max rows when env not set (defaults to 500)", async () => {
@ -2935,9 +3013,11 @@ datasourceDescribe(
}) })
}) })
describe.each(["data_name_test", "name_data_test", "name_test_data_"])( describe.each([
"special (%s) case", "data_name_test",
column => { "name_data_test",
"name_test_data_",
])("special (%s) case", column => {
beforeAll(async () => { beforeAll(async () => {
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
[column]: { [column]: {
@ -2957,8 +3037,7 @@ datasourceDescribe(
}, },
}).toContainExactly([{ [column]: "a" }]) }).toContainExactly([{ [column]: "a" }])
}) })
} })
)
isInternal && isInternal &&
describe("sample data", () => { describe("sample data", () => {
@ -2980,10 +3059,22 @@ datasourceDescribe(
}) })
describe.each([ describe.each([
{ low: "2024-07-03T00:00:00.000Z", high: "9999-00-00T00:00:00.000Z" }, {
{ low: "2024-07-03T00:00:00.000Z", high: "9998-00-00T00:00:00.000Z" }, low: "2024-07-03T00:00:00.000Z",
{ low: "0000-00-00T00:00:00.000Z", high: "2024-07-04T00:00:00.000Z" }, high: "9999-00-00T00:00:00.000Z",
{ low: "0001-00-00T00:00:00.000Z", high: "2024-07-04T00:00:00.000Z" }, },
{
low: "2024-07-03T00:00:00.000Z",
high: "9998-00-00T00:00:00.000Z",
},
{
low: "0000-00-00T00:00:00.000Z",
high: "2024-07-04T00:00:00.000Z",
},
{
low: "0001-00-00T00:00:00.000Z",
high: "2024-07-04T00:00:00.000Z",
},
])("date special cases", ({ low, high }) => { ])("date special cases", ({ low, high }) => {
const earlyDate = "2024-07-03T10:00:00.000Z", const earlyDate = "2024-07-03T10:00:00.000Z",
laterDate = "2024-07-03T11:00:00.000Z" laterDate = "2024-07-03T11:00:00.000Z"
@ -3260,13 +3351,17 @@ datasourceDescribe(
}, },
}) })
const toRelateTable = await config.api.table.get(toRelateTableId) const toRelateTable = await config.api.table.get(
toRelateTableId
)
await config.api.table.save({ await config.api.table.save({
...toRelateTable, ...toRelateTable,
primaryDisplay: "link", primaryDisplay: "link",
}) })
const relatedRows = await Promise.all([ const relatedRows = await Promise.all([
config.api.row.save(toRelateTable._id!, { name: "related" }), config.api.row.save(toRelateTable._id!, {
name: "related",
}),
]) ])
await config.api.row.save(tableOrViewId, { await config.api.row.save(tableOrViewId, {
name: "test", name: "test",
@ -3645,7 +3740,9 @@ datasourceDescribe(
"'; SHUTDOWN --", "'; SHUTDOWN --",
] ]
describe.each(badStrings)("bad string: %s", badStringTemplate => { describe.each(badStrings)(
"bad string: %s",
badStringTemplate => {
// The SQL that knex generates when you try to use a double quote in a // The SQL that knex generates when you try to use a double quote in a
// field name is always invalid and never works, so we skip it for these // field name is always invalid and never works, so we skip it for these
// tests. // tests.
@ -3665,12 +3762,17 @@ datasourceDescribe(
...table, ...table,
schema: { schema: {
...table.schema, ...table.schema,
[badString]: { name: badString, type: FieldType.STRING }, [badString]: {
name: badString,
type: FieldType.STRING,
},
}, },
}) })
if (docIds.isViewId(tableOrViewId)) { if (docIds.isViewId(tableOrViewId)) {
const view = await config.api.viewV2.get(tableOrViewId) const view = await config.api.viewV2.get(
tableOrViewId
)
await config.api.viewV2.update({ await config.api.viewV2.update({
...view, ...view,
schema: { schema: {
@ -3726,9 +3828,12 @@ datasourceDescribe(
await assertTableExists(table) await assertTableExists(table)
await assertTableNumRows(table, 1) await assertTableNumRows(table, 1)
}) })
}) }
}) )
})
}) })
} }
) )
})
}
)
}

View File

@ -38,8 +38,11 @@ import timekeeper from "timekeeper"
const { basicTable } = setup.structures const { basicTable } = setup.structures
const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/ const ISO_REGEX_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
datasourceDescribe( const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
{ name: "/tables (%s)", exclude: [DatabaseName.MONGODB] },
if (descriptions.length) {
describe.each(descriptions)(
"/tables ($dbName)",
({ config, dsProvider, isInternal, isOracle }) => { ({ config, dsProvider, isInternal, isOracle }) => {
let datasource: Datasource | undefined let datasource: Datasource | undefined
@ -332,7 +335,9 @@ datasourceDescribe(
expect(updatedTable).toEqual(expect.objectContaining(expected)) expect(updatedTable).toEqual(expect.objectContaining(expected))
const persistedTable = await config.api.table.get(updatedTable._id!) const persistedTable = await config.api.table.get(
updatedTable._id!
)
expected = { expected = {
...table, ...table,
name: newName, name: newName,
@ -561,8 +566,14 @@ datasourceDescribe(
await config.api.table.save(saveTableRequest, { await config.api.table.save(saveTableRequest, {
status: 200, status: 200,
}) })
saveTableRequest.schema.foo = { type: FieldType.STRING, name: "foo" } saveTableRequest.schema.foo = {
saveTableRequest.schema.FOO = { type: FieldType.STRING, name: "FOO" } type: FieldType.STRING,
name: "foo",
}
saveTableRequest.schema.FOO = {
type: FieldType.STRING,
name: "FOO",
}
await config.api.table.save(saveTableRequest, { await config.api.table.save(saveTableRequest, {
status: 400, status: 400,
@ -1180,10 +1191,12 @@ datasourceDescribe(
schema, schema,
}) })
) )
const result = await config.api.table.validateExistingTableImport({ const result = await config.api.table.validateExistingTableImport(
{
tableId: table._id, tableId: table._id,
rows, rows,
}) }
)
return result return result
}, },
], ],
@ -1267,7 +1280,9 @@ datasourceDescribe(
isInternal && isInternal &&
it.each( it.each(
isInternal ? PROTECTED_INTERNAL_COLUMNS : PROTECTED_EXTERNAL_COLUMNS isInternal
? PROTECTED_INTERNAL_COLUMNS
: PROTECTED_EXTERNAL_COLUMNS
)( )(
"don't allow protected names in the rows (%s)", "don't allow protected names in the rows (%s)",
async columnName => { async columnName => {
@ -1487,7 +1502,8 @@ datasourceDescribe(
schema: basicSchema, schema: basicSchema,
}) })
) )
const result = await config.api.table.validateExistingTableImport({ const result = await config.api.table.validateExistingTableImport(
{
tableId: table._id, tableId: table._id,
rows: [ rows: [
{ {
@ -1496,7 +1512,8 @@ datasourceDescribe(
name: generator.first(), name: generator.first(),
}, },
], ],
}) }
)
expect(result).toEqual({ expect(result).toEqual({
allValid: true, allValid: true,
@ -1512,4 +1529,5 @@ datasourceDescribe(
}) })
}) })
} }
) )
}

View File

@ -44,8 +44,11 @@ import merge from "lodash/merge"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { db, roles, context } from "@budibase/backend-core" import { db, roles, context } from "@budibase/backend-core"
datasourceDescribe( const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
{ name: "/v2/views (%s)", exclude: [DatabaseName.MONGODB] },
if (descriptions.length) {
describe.each(descriptions)(
"/v2/views ($dbName)",
({ config, isInternal, dsProvider }) => { ({ config, isInternal, dsProvider }) => {
let table: Table let table: Table
let rawDatasource: Datasource | undefined let rawDatasource: Datasource | undefined
@ -129,7 +132,8 @@ datasourceDescribe(
}) })
it("can persist views with all fields", async () => { it("can persist views with all fields", async () => {
const newView: Required<Omit<CreateViewRequest, "query" | "type">> = { const newView: Required<Omit<CreateViewRequest, "query" | "type">> =
{
name: generator.name(), name: generator.name(),
tableId: table._id!, tableId: table._id!,
primaryDisplay: "id", primaryDisplay: "id",
@ -194,8 +198,9 @@ datasourceDescribe(
}) })
it("can create a view with just a query field, no queryUI, for backwards compatibility", async () => { it("can create a view with just a query field, no queryUI, for backwards compatibility", async () => {
const newView: Required<Omit<CreateViewRequest, "queryUI" | "type">> = const newView: Required<
{ Omit<CreateViewRequest, "queryUI" | "type">
> = {
name: generator.name(), name: generator.name(),
tableId: table._id!, tableId: table._id!,
primaryDisplay: "id", primaryDisplay: "id",
@ -1162,7 +1167,8 @@ datasourceDescribe(
.expect(400) .expect(400)
expect(result.body).toEqual({ expect(result.body).toEqual({
message: "View id does not match between the body and the uri path", message:
"View id does not match between the body and the uri path",
status: 400, status: 400,
}) })
}) })
@ -2016,7 +2022,10 @@ datasourceDescribe(
schema, schema,
}) })
const renameColumn = async (table: Table, renaming: RenameColumn) => { const renameColumn = async (
table: Table,
renaming: RenameColumn
) => {
const newSchema = { ...table.schema } const newSchema = { ...table.schema }
newSchema[renaming.updated] = { newSchema[renaming.updated] = {
...table.schema[renaming.old], ...table.schema[renaming.old],
@ -2617,7 +2626,9 @@ datasourceDescribe(
]) ])
const rowUsage = await getRowUsage() const rowUsage = await getRowUsage()
await config.api.row.bulkDelete(view.id, { rows: [rows[0], rows[2]] }) await config.api.row.bulkDelete(view.id, {
rows: [rows[0], rows[2]],
})
await assertRowUsage(isInternal ? rowUsage - 2 : rowUsage) await assertRowUsage(isInternal ? rowUsage - 2 : rowUsage)
@ -3470,7 +3481,10 @@ datasourceDescribe(
expect(response.rows).toEqual( expect(response.rows).toEqual(
expect.arrayContaining([ expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
"Quantity Sum": rows.reduce((acc, r) => acc + r.quantity, 0), "Quantity Sum": rows.reduce(
(acc, r) => acc + r.quantity,
0
),
}), }),
]) ])
) )
@ -3511,7 +3525,9 @@ datasourceDescribe(
} }
for (const row of response.rows) { for (const row of response.rows) {
expect(row["Total Price"]).toEqual(priceByQuantity[row.quantity]) expect(row["Total Price"]).toEqual(
priceByQuantity[row.quantity]
)
} }
}) })
@ -3701,9 +3717,12 @@ datasourceDescribe(
}, },
}) })
const apertureScience = await config.api.row.save(companies._id!, { const apertureScience = await config.api.row.save(
companies._id!,
{
name: "Aperture Science Laboratories", name: "Aperture Science Laboratories",
}) }
)
const blackMesa = await config.api.row.save(companies._id!, { const blackMesa = await config.api.row.save(companies._id!, {
name: "Black Mesa", name: "Black Mesa",
@ -4402,7 +4421,9 @@ datasourceDescribe(
}), }),
expected: () => [ expected: () => [
{ {
user: expect.objectContaining({ _id: config.getUser()._id }), user: expect.objectContaining({
_id: config.getUser()._id,
}),
}, },
], ],
}, },
@ -4631,4 +4652,5 @@ datasourceDescribe(
}) })
}) })
} }
) )
}

View File

@ -7,11 +7,13 @@ import {
import { Knex } from "knex" import { Knex } from "knex"
import { generator } from "@budibase/backend-core/tests" import { generator } from "@budibase/backend-core/tests"
datasourceDescribe( const descriptions = datasourceDescribe({
{
name: "execute query action",
exclude: [DatabaseName.MONGODB, DatabaseName.SQS], exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
}, })
if (descriptions.length) {
describe.each(descriptions)(
"execute query action ($dbName)",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let tableName: string let tableName: string
let client: Knex let client: Knex
@ -74,4 +76,5 @@ datasourceDescribe(
expect(res.success).toEqual(false) expect(res.success).toEqual(false)
}) })
} }
) )
}

View File

@ -433,9 +433,10 @@ describe("Automation Scenarios", () => {
}) })
}) })
datasourceDescribe( const descriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
{ name: "", only: [DatabaseName.MYSQL] },
({ config, dsProvider }) => { if (descriptions.length) {
describe.each(descriptions)("/rows ($dbName)", ({ config, dsProvider }) => {
let datasource: Datasource let datasource: Datasource
let client: Knex let client: Knex
@ -531,5 +532,5 @@ datasourceDescribe(
) )
}) })
}) })
} })
) }

View File

@ -10,11 +10,11 @@ function uniqueTableName(length?: number): string {
.substring(0, length || 10) .substring(0, length || 10)
} }
datasourceDescribe( const mainDescriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
{
name: "Integration compatibility with mysql search_path", if (mainDescriptions.length) {
only: [DatabaseName.MYSQL], describe.each(mainDescriptions)(
}, "/Integration compatibility with mysql search_path ($dbName)",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let rawDatasource: Datasource let rawDatasource: Datasource
let datasource: Datasource let datasource: Datasource
@ -71,18 +71,20 @@ datasourceDescribe(
datasourceId: datasource._id!, datasourceId: datasource._id!,
tablesFilter: [repeated_table_name], tablesFilter: [repeated_table_name],
}) })
expect(res.datasource.entities![repeated_table_name].schema).toBeDefined() expect(
res.datasource.entities![repeated_table_name].schema
).toBeDefined()
const schema = res.datasource.entities![repeated_table_name].schema const schema = res.datasource.entities![repeated_table_name].schema
expect(Object.keys(schema).sort()).toEqual(["id", "val1"]) expect(Object.keys(schema).sort()).toEqual(["id", "val1"])
}) })
} }
) )
datasourceDescribe( const descriptions = datasourceDescribe({ only: [DatabaseName.MYSQL] })
{
name: "POST /api/datasources/:datasourceId/schema", if (descriptions.length) {
only: [DatabaseName.MYSQL], describe.each(descriptions)(
}, "POST /api/datasources/:datasourceId/schema ($dbName)",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let datasource: Datasource let datasource: Datasource
let client: Knex let client: Knex
@ -125,4 +127,6 @@ datasourceDescribe(
expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS) expect(table.schema[enumColumnName].type).toEqual(FieldType.OPTIONS)
}) })
} }
) )
}
}

View File

@ -8,8 +8,11 @@ import {
} from "../integrations/tests/utils" } from "../integrations/tests/utils"
import { Knex } from "knex" import { Knex } from "knex"
datasourceDescribe( const mainDescriptions = datasourceDescribe({ only: [DatabaseName.POSTGRES] })
{ name: "postgres integrations", only: [DatabaseName.POSTGRES] },
if (mainDescriptions.length) {
describe.each(mainDescriptions)(
"/postgres integrations",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let datasource: Datasource let datasource: Datasource
let client: Knex let client: Knex
@ -199,18 +202,21 @@ datasourceDescribe(
row = await config.api.row.save(table._id!, { ...row, price: 300 }) row = await config.api.row.save(table._id!, { ...row, price: 300 })
expect(row.price).toBe("300.00") expect(row.price).toBe("300.00")
row = await config.api.row.save(table._id!, { ...row, price: "400.00" }) row = await config.api.row.save(table._id!, {
...row,
price: "400.00",
})
expect(row.price).toBe("400.00") expect(row.price).toBe("400.00")
}) })
}) })
} }
) )
datasourceDescribe( const descriptions = datasourceDescribe({ only: [DatabaseName.POSTGRES] })
{
name: "Integration compatibility with postgres search_path", if (descriptions.length) {
only: [DatabaseName.POSTGRES], describe.each(descriptions)(
}, "Integration compatibility with postgres search_path",
({ config, dsProvider }) => { ({ config, dsProvider }) => {
let datasource: Datasource let datasource: Datasource
let client: Knex let client: Knex
@ -283,8 +289,11 @@ datasourceDescribe(
expect( expect(
response.datasource.entities?.[repeated_table_name].schema response.datasource.entities?.[repeated_table_name].schema
).toBeDefined() ).toBeDefined()
const schema = response.datasource.entities?.[repeated_table_name].schema const schema =
response.datasource.entities?.[repeated_table_name].schema
expect(Object.keys(schema || {}).sort()).toEqual(["id", "val1"]) expect(Object.keys(schema || {}).sort()).toEqual(["id", "val1"])
}) })
} }
) )
}
}

View File

@ -35,7 +35,6 @@ const providers: Record<DatabaseName, DatasourceProvider> = {
} }
export interface DatasourceDescribeOpts { export interface DatasourceDescribeOpts {
name: string
only?: DatabaseName[] only?: DatabaseName[]
exclude?: DatabaseName[] exclude?: DatabaseName[]
} }
@ -102,16 +101,12 @@ function createDummyTest() {
}) })
} }
export function datasourceDescribe( export function datasourceDescribe(opts: DatasourceDescribeOpts) {
opts: DatasourceDescribeOpts,
cb: (args: DatasourceDescribeReturn) => void
) {
if (process.env.DATASOURCE === "none") { if (process.env.DATASOURCE === "none") {
createDummyTest() createDummyTest()
return
} }
const { name, only, exclude } = opts const { only, exclude } = opts
if (only && exclude) { if (only && exclude) {
throw new Error("you can only supply one of 'only' or 'exclude'") throw new Error("you can only supply one of 'only' or 'exclude'")
@ -130,36 +125,28 @@ export function datasourceDescribe(
if (databases.length === 0) { if (databases.length === 0) {
createDummyTest() createDummyTest()
return
} }
describe.each(databases)(name, name => {
const config = new TestConfiguration() const config = new TestConfiguration()
return databases.map(dbName => ({
afterAll(() => { dbName,
config.end()
})
cb({
name,
config, config,
dsProvider: () => createDatasources(config, name), dsProvider: () => createDatasources(config, dbName),
isInternal: name === DatabaseName.SQS, isInternal: dbName === DatabaseName.SQS,
isExternal: name !== DatabaseName.SQS, isExternal: dbName !== DatabaseName.SQS,
isSql: [ isSql: [
DatabaseName.MARIADB, DatabaseName.MARIADB,
DatabaseName.MYSQL, DatabaseName.MYSQL,
DatabaseName.POSTGRES, DatabaseName.POSTGRES,
DatabaseName.SQL_SERVER, DatabaseName.SQL_SERVER,
DatabaseName.ORACLE, DatabaseName.ORACLE,
].includes(name), ].includes(dbName),
isMySQL: name === DatabaseName.MYSQL, isMySQL: dbName === DatabaseName.MYSQL,
isPostgres: name === DatabaseName.POSTGRES, isPostgres: dbName === DatabaseName.POSTGRES,
isMongodb: name === DatabaseName.MONGODB, isMongodb: dbName === DatabaseName.MONGODB,
isMSSQL: name === DatabaseName.SQL_SERVER, isMSSQL: dbName === DatabaseName.SQL_SERVER,
isOracle: name === DatabaseName.ORACLE, isOracle: dbName === DatabaseName.ORACLE,
}) }))
})
} }
function getDatasource( function getDatasource(

View File

@ -19,8 +19,11 @@ import { tableForDatasource } from "../../../../../tests/utilities/structures"
// These test cases are only for things that cannot be tested through the API // These test cases are only for things that cannot be tested through the API
// (e.g. limiting searches to returning specific fields). If it's possible to // (e.g. limiting searches to returning specific fields). If it's possible to
// test through the API, it should be done there instead. // test through the API, it should be done there instead.
datasourceDescribe( const descriptions = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
{ name: "search sdk (%s)", exclude: [DatabaseName.MONGODB] },
if (descriptions.length) {
describe.each(descriptions)(
"search sdk ($dbName)",
({ config, dsProvider, isInternal }) => { ({ config, dsProvider, isInternal }) => {
let datasource: Datasource | undefined let datasource: Datasource | undefined
let table: Table let table: Table
@ -217,4 +220,5 @@ datasourceDescribe(
} }
) )
} }
) )
}