Updating based on PR comments.

This commit is contained in:
mike12345567 2024-03-22 15:26:02 +00:00
parent defb925d16
commit cc8a0274a4
3 changed files with 14 additions and 35 deletions

View File

@ -149,11 +149,9 @@ function enrichParameters(
// first check parameters are all valid // first check parameters are all valid
validateQueryInputs(requestParameters) validateQueryInputs(requestParameters)
// make sure parameters are fully enriched with defaults // make sure parameters are fully enriched with defaults
for (let parameter of query.parameters) { for (const parameter of query.parameters) {
let value: string | null = requestParameters[parameter.name] let value: string | null =
if (!value) { requestParameters[parameter.name] || parameter.default
value = parameter.default
}
if (query.nullDefaultSupport && paramNotSet(value)) { if (query.nullDefaultSupport && paramNotSet(value)) {
value = null value = null
} }

View File

@ -34,30 +34,12 @@ const createTableSQL: Record<string, string> = {
const insertSQL = `INSERT INTO test_table (name) VALUES ('one'), ('two'), ('three'), ('four'), ('five')` const insertSQL = `INSERT INTO test_table (name) VALUES ('one'), ('two'), ('three'), ('four'), ('five')`
const dropTableSQL = `DROP TABLE test_table;` const dropTableSQL = `DROP TABLE test_table;`
const POSTGRES_SPECIFICS = {
nullError: 'invalid input syntax for type integer: ""',
}
const MYSQL_SPECIFICS = {
nullError: "Incorrect integer value: '' for column 'number' at row 1",
}
const MSSQL_SPECIFICS = {
// MS-SQL doesn't throw an error here, it casts empty string to nothing
nullError: undefined,
}
const MARIADB_SPECIFICS = {
nullError:
"Incorrect integer value: '' for column `mysql`.`test_table`.`number` at row 1",
}
describe.each([ describe.each([
["postgres", databaseTestProviders.postgres, POSTGRES_SPECIFICS], ["postgres", databaseTestProviders.postgres],
["mysql", databaseTestProviders.mysql, MYSQL_SPECIFICS], ["mysql", databaseTestProviders.mysql],
["mssql", databaseTestProviders.mssql, MSSQL_SPECIFICS], ["mssql", databaseTestProviders.mssql],
["mariadb", databaseTestProviders.mariadb, MARIADB_SPECIFICS], ["mariadb", databaseTestProviders.mariadb],
])("queries (%s)", (__, dsProvider, testSpecificInformation) => { ])("queries (%s)", (dbName, dsProvider) => {
const config = setup.getConfig() const config = setup.getConfig()
let datasource: Datasource let datasource: Datasource
@ -461,12 +443,11 @@ describe.each([
} catch (err: any) { } catch (err: any) {
error = err.message error = err.message
} }
const testExpectation = testSpecificInformation.nullError if (dbName === "mssql") {
if (testExpectation) {
expect(error).toBeDefined()
expect(error).toContain(testExpectation)
} else {
expect(error).toBeUndefined() expect(error).toBeUndefined()
} else {
expect(error).toBeDefined()
expect(error).toContain("integer")
} }
}) })

View File

@ -70,8 +70,8 @@ export async function enrichArrayContext(
inputs = {} inputs = {}
): Promise<any[]> { ): Promise<any[]> {
const map: Record<string, any> = {} const map: Record<string, any> = {}
for (let [key, value] of Object.entries(fields)) { for (let index in fields) {
map[key] = value map[index] = fields[index]
} }
const output = await enrichContext(map, inputs) const output = await enrichContext(map, inputs)
const outputArray: any[] = [] const outputArray: any[] = []