Converting one test case to try using describe directly.
This commit is contained in:
parent
668df22176
commit
f25dd387b1
|
@ -3,6 +3,7 @@ import * as setup from "./utilities"
|
||||||
import {
|
import {
|
||||||
DatabaseName,
|
DatabaseName,
|
||||||
datasourceDescribe,
|
datasourceDescribe,
|
||||||
|
datasourceProps,
|
||||||
} from "../../../integrations/tests/utils"
|
} from "../../../integrations/tests/utils"
|
||||||
|
|
||||||
import tk from "timekeeper"
|
import tk from "timekeeper"
|
||||||
|
@ -85,9 +86,11 @@ function encodeJS(binding: string) {
|
||||||
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
datasourceDescribe(
|
const databases = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||||
{ name: "/rows (%s)", exclude: [DatabaseName.MONGODB] },
|
|
||||||
({ config, dsProvider, isInternal, isMSSQL, isOracle }) => {
|
describe.each(databases)("/rows (%s)", dbName => {
|
||||||
|
const { config, dsProvider, isInternal, isMSSQL, isOracle } =
|
||||||
|
datasourceProps(dbName)
|
||||||
let table: Table
|
let table: Table
|
||||||
let datasource: Datasource | undefined
|
let datasource: Datasource | undefined
|
||||||
let client: Knex | undefined
|
let client: Knex | undefined
|
||||||
|
@ -175,10 +178,7 @@ datasourceDescribe(
|
||||||
|
|
||||||
const getRowUsage = async () => {
|
const getRowUsage = async () => {
|
||||||
const { total } = await config.doInContext(undefined, () =>
|
const { total } = await config.doInContext(undefined, () =>
|
||||||
quotas.getCurrentUsageValues(
|
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
|
||||||
QuotaUsageType.STATIC,
|
|
||||||
StaticQuotaName.ROWS
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
@ -1362,9 +1362,7 @@ datasourceDescribe(
|
||||||
number: naturalValue,
|
number: naturalValue,
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(existing._id).toEqual(
|
expect(existing._id).toEqual(`%5B${naturalValue}%2C'${stringValue}'%5D`)
|
||||||
`%5B${naturalValue}%2C'${stringValue}'%5D`
|
|
||||||
)
|
|
||||||
|
|
||||||
const row = await config.api.row.patch(table._id!, {
|
const row = await config.api.row.patch(table._id!, {
|
||||||
_id: existing._id!,
|
_id: existing._id!,
|
||||||
|
@ -2351,16 +2349,10 @@ datasourceDescribe(
|
||||||
const stringified = (value: string) =>
|
const stringified = (value: string) =>
|
||||||
JSON.stringify(value).replace(/"/g, "'")
|
JSON.stringify(value).replace(/"/g, "'")
|
||||||
|
|
||||||
const matchingObject = (
|
const matchingObject = (key: string, value: any, isArray: boolean) => {
|
||||||
key: string,
|
|
||||||
value: any,
|
|
||||||
isArray: boolean
|
|
||||||
) => {
|
|
||||||
const objectMatcher = `{'${key}':'${value[key]}'.*?}`
|
const objectMatcher = `{'${key}':'${value[key]}'.*?}`
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
return expect.stringMatching(
|
return expect.stringMatching(new RegExp(`^\\[${objectMatcher}\\]$`))
|
||||||
new RegExp(`^\\[${objectMatcher}\\]$`)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return expect.stringMatching(new RegExp(`^${objectMatcher}$`))
|
return expect.stringMatching(new RegExp(`^${objectMatcher}$`))
|
||||||
}
|
}
|
||||||
|
@ -2633,9 +2625,7 @@ datasourceDescribe(
|
||||||
name: "foo",
|
name: "foo",
|
||||||
description: "bar",
|
description: "bar",
|
||||||
tableId,
|
tableId,
|
||||||
users: expect.arrayContaining(
|
users: expect.arrayContaining(selectedUsers.map(u => resultMapper(u))),
|
||||||
selectedUsers.map(u => resultMapper(u))
|
|
||||||
),
|
|
||||||
_id: expect.any(String),
|
_id: expect.any(String),
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
id: isInternal ? undefined : expect.any(Number),
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
@ -2680,9 +2670,7 @@ datasourceDescribe(
|
||||||
description: "bar",
|
description: "bar",
|
||||||
tableId,
|
tableId,
|
||||||
user: expect.arrayContaining([user1].map(u => resultMapper(u))),
|
user: expect.arrayContaining([user1].map(u => resultMapper(u))),
|
||||||
users: expect.arrayContaining(
|
users: expect.arrayContaining([user2, user3].map(u => resultMapper(u))),
|
||||||
[user2, user3].map(u => resultMapper(u))
|
|
||||||
),
|
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
_rev: expect.any(String),
|
_rev: expect.any(String),
|
||||||
id: isInternal ? undefined : expect.any(Number),
|
id: isInternal ? undefined : expect.any(Number),
|
||||||
|
@ -3479,7 +3467,6 @@ datasourceDescribe(
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
// todo: remove me
|
// todo: remove me
|
||||||
|
|
|
@ -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[]
|
||||||
}
|
}
|
||||||
|
@ -103,15 +102,14 @@ function createDummyTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function datasourceDescribe(
|
export function datasourceDescribe(
|
||||||
opts: DatasourceDescribeOpts,
|
opts: DatasourceDescribeOpts
|
||||||
cb: (args: DatasourceDescribeReturn) => void
|
): DatabaseName[] {
|
||||||
) {
|
|
||||||
if (process.env.DATASOURCE === "none") {
|
if (process.env.DATASOURCE === "none") {
|
||||||
createDummyTest()
|
createDummyTest()
|
||||||
return
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +128,32 @@ export function datasourceDescribe(
|
||||||
|
|
||||||
if (databases.length === 0) {
|
if (databases.length === 0) {
|
||||||
createDummyTest()
|
createDummyTest()
|
||||||
return
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.each(databases)(name, name => {
|
return databases
|
||||||
|
}
|
||||||
|
|
||||||
|
export function datasourceProps(dbName: DatabaseName) {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
return {
|
||||||
afterAll(() => {
|
|
||||||
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(
|
||||||
|
|
Loading…
Reference in New Issue