-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: revert breaking change in results creation (#2591)
* fix: revert breaking change in results creation * refactor: simplify prototype validation * ci: fix typo * chore: improve performance * chore: fix lint * chore: change from `nativeObjectProps` to `privateObjectProps` * chore: improve error message
- Loading branch information
1 parent
7f5b395
commit f7c60d0
Showing
9 changed files
with
189 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
test/esm/integration/parsers/execute-results-creation.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { test, describe, assert } from 'poku'; | ||
import { createConnection, describeOptions } from '../../../common.test.cjs'; | ||
|
||
const connection = createConnection().promise(); | ||
|
||
describe('Execute: Results Creation', describeOptions); | ||
|
||
Promise.all([ | ||
test(async () => { | ||
const expected = [ | ||
{ | ||
test: 2, | ||
}, | ||
]; | ||
const emptyObject = {}; | ||
const proto = Object.getPrototypeOf(emptyObject); | ||
const privateObjectProps = Object.getOwnPropertyNames(proto); | ||
|
||
const [results] = await connection.execute('SELECT 1+1 AS `test`'); | ||
|
||
assert.deepStrictEqual(results, expected, 'Ensure exact object "results"'); | ||
assert.deepStrictEqual( | ||
Object.getOwnPropertyNames(results[0]), | ||
Object.getOwnPropertyNames(expected[0]), | ||
'Deep ensure exact object "results"', | ||
); | ||
assert.deepStrictEqual( | ||
Object.getPrototypeOf(results[0]), | ||
Object.getPrototypeOf({}), | ||
'Ensure clean properties in results items', | ||
); | ||
|
||
privateObjectProps.forEach((prop) => { | ||
assert(prop in results[0], `Ensure ${prop} exists`); | ||
}); | ||
|
||
results[0].customProp = true; | ||
assert.strictEqual( | ||
results[0].customProp, | ||
true, | ||
'Ensure that the end-user is able to use custom props', | ||
); | ||
}), | ||
test(async () => { | ||
const [result] = await connection.execute('SET @1 = 1;'); | ||
|
||
assert.strictEqual( | ||
result.constructor.name, | ||
'ResultSetHeader', | ||
'Ensure constructor name in result object', | ||
); | ||
}), | ||
]).then(async () => { | ||
await connection.end(); | ||
}); |
55 changes: 55 additions & 0 deletions
55
test/esm/integration/parsers/query-results-creation.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { test, describe, assert } from 'poku'; | ||
import { createConnection, describeOptions } from '../../../common.test.cjs'; | ||
|
||
const connection = createConnection().promise(); | ||
|
||
describe('Query: Results Creation', describeOptions); | ||
|
||
Promise.all([ | ||
test(async () => { | ||
const expected = [ | ||
{ | ||
test: 2, | ||
}, | ||
]; | ||
const emptyObject = {}; | ||
const proto = Object.getPrototypeOf(emptyObject); | ||
const privateObjectProps = Object.getOwnPropertyNames(proto); | ||
|
||
const [results] = await connection.query('SELECT 1+1 AS `test`'); | ||
|
||
assert.deepStrictEqual(results, expected, 'Ensure exact object "results"'); | ||
assert.deepStrictEqual( | ||
Object.getOwnPropertyNames(results[0]), | ||
Object.getOwnPropertyNames(expected[0]), | ||
'Deep ensure exact object "results"', | ||
); | ||
assert.deepStrictEqual( | ||
Object.getPrototypeOf(results[0]), | ||
Object.getPrototypeOf({}), | ||
'Ensure clean properties in results items', | ||
); | ||
|
||
privateObjectProps.forEach((prop) => { | ||
assert(prop in results[0], `Ensure ${prop} exists`); | ||
}); | ||
|
||
results[0].customProp = true; | ||
assert.strictEqual( | ||
results[0].customProp, | ||
true, | ||
'Ensure that the end-user is able to use custom props', | ||
); | ||
}), | ||
test(async () => { | ||
const [result] = await connection.query('SET @1 = 1;'); | ||
|
||
assert.strictEqual( | ||
result.constructor.name, | ||
'ResultSetHeader', | ||
'Ensure constructor name in result object', | ||
); | ||
}), | ||
]).then(async () => { | ||
await connection.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { describe, assert } from 'poku'; | ||
import { describeOptions } from '../../../common.test.cjs'; | ||
import getBinaryParser from '../../../../lib/parsers/binary_parser.js'; | ||
import { srcEscape } from '../../../../lib/helpers.js'; | ||
import { privateObjectProps } from '../../../../lib/helpers.js'; | ||
|
||
describe('Binary Parser: Block Native Object Props', describeOptions); | ||
|
||
const blockedFields = Array.from(privateObjectProps).map((prop) => [ | ||
{ name: prop }, | ||
]); | ||
|
||
blockedFields.forEach((fields) => { | ||
try { | ||
getBinaryParser(fields, {}, {}); | ||
assert.fail('An error was expected'); | ||
} catch (error) { | ||
assert.strictEqual( | ||
error.message, | ||
`The field name (${srcEscape(fields[0].name)}) can't be the same as an object's private property.`, | ||
`Ensure safe ${fields[0].name}`, | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { describe, assert } from 'poku'; | ||
import { describeOptions } from '../../../common.test.cjs'; | ||
import TextRowParser from '../../../../lib/parsers/text_parser.js'; | ||
import { srcEscape } from '../../../../lib/helpers.js'; | ||
import { privateObjectProps } from '../../../../lib/helpers.js'; | ||
|
||
describe('Text Parser: Block Native Object Props', describeOptions); | ||
|
||
const blockedFields = Array.from(privateObjectProps).map((prop) => [ | ||
{ name: prop }, | ||
]); | ||
|
||
blockedFields.forEach((fields) => { | ||
try { | ||
TextRowParser(fields, {}, {}); | ||
assert.fail('An error was expected'); | ||
} catch (error) { | ||
assert.strictEqual( | ||
error.message, | ||
`The field name (${srcEscape(fields[0].name)}) can't be the same as an object's private property.`, | ||
`Ensure safe ${fields[0].name}`, | ||
); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.