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 {
|
||||
DatabaseName,
|
||||
datasourceDescribe,
|
||||
datasourceProps,
|
||||
} from "../../../integrations/tests/utils"
|
||||
|
||||
import tk from "timekeeper"
|
||||
|
@ -85,9 +86,11 @@ function encodeJS(binding: string) {
|
|||
return `{{ js "${Buffer.from(binding).toString("base64")}"}}`
|
||||
}
|
||||
|
||||
datasourceDescribe(
|
||||
{ name: "/rows (%s)", exclude: [DatabaseName.MONGODB] },
|
||||
({ config, dsProvider, isInternal, isMSSQL, isOracle }) => {
|
||||
const databases = datasourceDescribe({ exclude: [DatabaseName.MONGODB] })
|
||||
|
||||
describe.each(databases)("/rows (%s)", dbName => {
|
||||
const { config, dsProvider, isInternal, isMSSQL, isOracle } =
|
||||
datasourceProps(dbName)
|
||||
let table: Table
|
||||
let datasource: Datasource | undefined
|
||||
let client: Knex | undefined
|
||||
|
@ -175,10 +178,7 @@ datasourceDescribe(
|
|||
|
||||
const getRowUsage = async () => {
|
||||
const { total } = await config.doInContext(undefined, () =>
|
||||
quotas.getCurrentUsageValues(
|
||||
QuotaUsageType.STATIC,
|
||||
StaticQuotaName.ROWS
|
||||
)
|
||||
quotas.getCurrentUsageValues(QuotaUsageType.STATIC, StaticQuotaName.ROWS)
|
||||
)
|
||||
return total
|
||||
}
|
||||
|
@ -1362,9 +1362,7 @@ datasourceDescribe(
|
|||
number: naturalValue,
|
||||
})
|
||||
|
||||
expect(existing._id).toEqual(
|
||||
`%5B${naturalValue}%2C'${stringValue}'%5D`
|
||||
)
|
||||
expect(existing._id).toEqual(`%5B${naturalValue}%2C'${stringValue}'%5D`)
|
||||
|
||||
const row = await config.api.row.patch(table._id!, {
|
||||
_id: existing._id!,
|
||||
|
@ -2351,16 +2349,10 @@ datasourceDescribe(
|
|||
const stringified = (value: string) =>
|
||||
JSON.stringify(value).replace(/"/g, "'")
|
||||
|
||||
const matchingObject = (
|
||||
key: string,
|
||||
value: any,
|
||||
isArray: boolean
|
||||
) => {
|
||||
const matchingObject = (key: string, value: any, isArray: boolean) => {
|
||||
const objectMatcher = `{'${key}':'${value[key]}'.*?}`
|
||||
if (isArray) {
|
||||
return expect.stringMatching(
|
||||
new RegExp(`^\\[${objectMatcher}\\]$`)
|
||||
)
|
||||
return expect.stringMatching(new RegExp(`^\\[${objectMatcher}\\]$`))
|
||||
}
|
||||
return expect.stringMatching(new RegExp(`^${objectMatcher}$`))
|
||||
}
|
||||
|
@ -2633,9 +2625,7 @@ datasourceDescribe(
|
|||
name: "foo",
|
||||
description: "bar",
|
||||
tableId,
|
||||
users: expect.arrayContaining(
|
||||
selectedUsers.map(u => resultMapper(u))
|
||||
),
|
||||
users: expect.arrayContaining(selectedUsers.map(u => resultMapper(u))),
|
||||
_id: expect.any(String),
|
||||
_rev: expect.any(String),
|
||||
id: isInternal ? undefined : expect.any(Number),
|
||||
|
@ -2680,9 +2670,7 @@ datasourceDescribe(
|
|||
description: "bar",
|
||||
tableId,
|
||||
user: expect.arrayContaining([user1].map(u => resultMapper(u))),
|
||||
users: expect.arrayContaining(
|
||||
[user2, user3].map(u => resultMapper(u))
|
||||
),
|
||||
users: expect.arrayContaining([user2, user3].map(u => resultMapper(u))),
|
||||
_id: row._id,
|
||||
_rev: expect.any(String),
|
||||
id: isInternal ? undefined : expect.any(Number),
|
||||
|
@ -3479,7 +3467,6 @@ datasourceDescribe(
|
|||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
// todo: remove me
|
||||
|
|
|
@ -35,7 +35,6 @@ const providers: Record<DatabaseName, DatasourceProvider> = {
|
|||
}
|
||||
|
||||
export interface DatasourceDescribeOpts {
|
||||
name: string
|
||||
only?: DatabaseName[]
|
||||
exclude?: DatabaseName[]
|
||||
}
|
||||
|
@ -103,15 +102,14 @@ function createDummyTest() {
|
|||
}
|
||||
|
||||
export function datasourceDescribe(
|
||||
opts: DatasourceDescribeOpts,
|
||||
cb: (args: DatasourceDescribeReturn) => void
|
||||
) {
|
||||
opts: DatasourceDescribeOpts
|
||||
): DatabaseName[] {
|
||||
if (process.env.DATASOURCE === "none") {
|
||||
createDummyTest()
|
||||
return
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const { name, only, exclude } = opts
|
||||
const { only, exclude } = opts
|
||||
|
||||
if (only && exclude) {
|
||||
throw new Error("you can only supply one of 'only' or 'exclude'")
|
||||
|
@ -130,36 +128,32 @@ export function datasourceDescribe(
|
|||
|
||||
if (databases.length === 0) {
|
||||
createDummyTest()
|
||||
return
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
describe.each(databases)(name, name => {
|
||||
return databases
|
||||
}
|
||||
|
||||
export function datasourceProps(dbName: DatabaseName) {
|
||||
const config = new TestConfiguration()
|
||||
|
||||
afterAll(() => {
|
||||
config.end()
|
||||
})
|
||||
|
||||
cb({
|
||||
name,
|
||||
return {
|
||||
config,
|
||||
dsProvider: () => createDatasources(config, name),
|
||||
isInternal: name === DatabaseName.SQS,
|
||||
isExternal: name !== DatabaseName.SQS,
|
||||
dsProvider: () => createDatasources(config, dbName),
|
||||
isInternal: dbName === DatabaseName.SQS,
|
||||
isExternal: dbName !== DatabaseName.SQS,
|
||||
isSql: [
|
||||
DatabaseName.MARIADB,
|
||||
DatabaseName.MYSQL,
|
||||
DatabaseName.POSTGRES,
|
||||
DatabaseName.SQL_SERVER,
|
||||
DatabaseName.ORACLE,
|
||||
].includes(name),
|
||||
isMySQL: name === DatabaseName.MYSQL,
|
||||
isPostgres: name === DatabaseName.POSTGRES,
|
||||
isMongodb: name === DatabaseName.MONGODB,
|
||||
isMSSQL: name === DatabaseName.SQL_SERVER,
|
||||
isOracle: name === DatabaseName.ORACLE,
|
||||
})
|
||||
})
|
||||
].includes(dbName),
|
||||
isMySQL: dbName === DatabaseName.MYSQL,
|
||||
isPostgres: dbName === DatabaseName.POSTGRES,
|
||||
isMongodb: dbName === DatabaseName.MONGODB,
|
||||
isMSSQL: dbName === DatabaseName.SQL_SERVER,
|
||||
isOracle: dbName === DatabaseName.ORACLE,
|
||||
}
|
||||
}
|
||||
|
||||
function getDatasource(
|
||||
|
|
Loading…
Reference in New Issue