|
| 1 | +import { describe, test, assert } from 'poku'; |
| 2 | +import { createConnection, describeOptions } from '../../../common.test.cjs'; |
| 3 | + |
| 4 | +const connection = createConnection().promise(); |
| 5 | + |
| 6 | +const sql = 'SELECT 9007199254740991+100 AS `total`'; |
| 7 | + |
| 8 | +describe('Binary Parser: bigNumberStrings Sanitization', describeOptions); |
| 9 | + |
| 10 | +Promise.all([ |
| 11 | + test(async () => { |
| 12 | + const [results] = await connection.execute({ |
| 13 | + sql, |
| 14 | + supportBigNumbers: true, |
| 15 | + bigNumberStrings: true, |
| 16 | + }); |
| 17 | + |
| 18 | + assert.strictEqual( |
| 19 | + typeof results[0].total, |
| 20 | + 'string', |
| 21 | + 'Valid bigNumberStrings enabled', |
| 22 | + ); |
| 23 | + }), |
| 24 | + test(async () => { |
| 25 | + const [results] = await connection.execute({ |
| 26 | + sql, |
| 27 | + supportBigNumbers: false, |
| 28 | + bigNumberStrings: false, |
| 29 | + }); |
| 30 | + |
| 31 | + assert.strictEqual( |
| 32 | + typeof results[0].total, |
| 33 | + 'number', |
| 34 | + 'Valid bigNumberStrings disabled', |
| 35 | + ); |
| 36 | + }), |
| 37 | + |
| 38 | + test(async () => { |
| 39 | + const [results] = await connection.execute({ |
| 40 | + sql, |
| 41 | + supportBigNumbers: 'text', |
| 42 | + bigNumberStrings: 'text', |
| 43 | + }); |
| 44 | + |
| 45 | + assert.strictEqual( |
| 46 | + typeof results[0].total, |
| 47 | + 'string', |
| 48 | + 'bigNumberStrings as a random string should be enabled', |
| 49 | + ); |
| 50 | + }), |
| 51 | + test(async () => { |
| 52 | + const [results] = await connection.execute({ |
| 53 | + sql, |
| 54 | + supportBigNumbers: '', |
| 55 | + bigNumberStrings: '', |
| 56 | + }); |
| 57 | + |
| 58 | + assert.strictEqual( |
| 59 | + typeof results[0].total, |
| 60 | + 'number', |
| 61 | + 'bigNumberStrings as an empty string should be disabled', |
| 62 | + ); |
| 63 | + }), |
| 64 | +]).then(async () => { |
| 65 | + await connection.end(); |
| 66 | +}); |
0 commit comments