Skip to content

Commit 71115d8

Browse files
authoredApr 9, 2024··
ci: improve parser tests (#2573)
1 parent 74abf9e commit 71115d8

5 files changed

+132
-7
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
});

‎test/esm/unit/parsers/big-numbers-strings-sanitization.test.mjs ‎test/esm/unit/parsers/big-numbers-strings-text-sanitization.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const connection = createConnection().promise();
55

66
const sql = 'SELECT 9007199254740991+100 AS `total`';
77

8-
describe('bigNumberStrings Sanitization', describeOptions);
8+
describe('Text Parser: bigNumberStrings Sanitization', describeOptions);
99

1010
Promise.all([
1111
test(async () => {

‎test/unit/parsers/cache-key-serialization.test.cjs ‎test/esm/unit/parsers/cache-key-serialization.test.mjs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
'use strict';
2-
3-
const { assert } = require('poku');
4-
const _keyFromFields =
5-
require('../../../lib/parsers/parser_cache.js')._keyFromFields;
1+
import { assert } from 'poku';
2+
import { _keyFromFields } from '../../../../lib/parsers/parser_cache.js';
63

74
// Invalid
85
const test1 = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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: supportBigNumbers Sanitization', describeOptions);
9+
10+
Promise.all([
11+
test(async () => {
12+
const [results] = await connection.execute({
13+
sql,
14+
supportBigNumbers: true,
15+
});
16+
17+
assert.strictEqual(
18+
typeof results[0].total,
19+
'string',
20+
'Valid supportBigNumbers enabled',
21+
);
22+
}),
23+
test(async () => {
24+
const [results] = await connection.execute({
25+
sql,
26+
supportBigNumbers: false,
27+
});
28+
29+
assert.strictEqual(
30+
typeof results[0].total,
31+
'number',
32+
'Valid supportBigNumbers disabled',
33+
);
34+
}),
35+
36+
test(async () => {
37+
const [results] = await connection.execute({
38+
sql,
39+
supportBigNumbers: 'text',
40+
});
41+
42+
assert.strictEqual(
43+
typeof results[0].total,
44+
'string',
45+
'supportBigNumbers as a random string should be enabled',
46+
);
47+
}),
48+
test(async () => {
49+
const [results] = await connection.execute({
50+
sql,
51+
supportBigNumbers: '',
52+
});
53+
54+
assert.strictEqual(
55+
typeof results[0].total,
56+
'number',
57+
'supportBigNumbers as an empty string should be disabled',
58+
);
59+
}),
60+
]).then(async () => {
61+
await connection.end();
62+
});

‎test/esm/unit/parsers/support-big-numbers-sanitization.test.mjs ‎test/esm/unit/parsers/support-big-numbers-text-sanitization.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const connection = createConnection().promise();
55

66
const sql = 'SELECT 9007199254740991+100 AS `total`';
77

8-
describe('supportBigNumbers Sanitization', describeOptions);
8+
describe('Text Parser: supportBigNumbers Sanitization', describeOptions);
99

1010
Promise.all([
1111
test(async () => {

0 commit comments

Comments
 (0)
Please sign in to comment.