Skip to content

Commit

Permalink
ci: improve parser tests (#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel committed Apr 9, 2024
1 parent 74abf9e commit 71115d8
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 7 deletions.
@@ -0,0 +1,66 @@
import { describe, test, assert } from 'poku';
import { createConnection, describeOptions } from '../../../common.test.cjs';

const connection = createConnection().promise();

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

describe('Binary Parser: bigNumberStrings Sanitization', describeOptions);

Promise.all([
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: true,
bigNumberStrings: true,
});

assert.strictEqual(
typeof results[0].total,
'string',
'Valid bigNumberStrings enabled',
);
}),
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: false,
bigNumberStrings: false,
});

assert.strictEqual(
typeof results[0].total,
'number',
'Valid bigNumberStrings disabled',
);
}),

test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: 'text',
bigNumberStrings: 'text',
});

assert.strictEqual(
typeof results[0].total,
'string',
'bigNumberStrings as a random string should be enabled',
);
}),
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: '',
bigNumberStrings: '',
});

assert.strictEqual(
typeof results[0].total,
'number',
'bigNumberStrings as an empty string should be disabled',
);
}),
]).then(async () => {
await connection.end();
});
Expand Up @@ -5,7 +5,7 @@ const connection = createConnection().promise();

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

describe('bigNumberStrings Sanitization', describeOptions);
describe('Text Parser: bigNumberStrings Sanitization', describeOptions);

Promise.all([
test(async () => {
Expand Down
@@ -1,8 +1,5 @@
'use strict';

const { assert } = require('poku');
const _keyFromFields =
require('../../../lib/parsers/parser_cache.js')._keyFromFields;
import { assert } from 'poku';
import { _keyFromFields } from '../../../../lib/parsers/parser_cache.js';

// Invalid
const test1 = {
Expand Down
@@ -0,0 +1,62 @@
import { describe, test, assert } from 'poku';
import { createConnection, describeOptions } from '../../../common.test.cjs';

const connection = createConnection().promise();

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

describe('Binary Parser: supportBigNumbers Sanitization', describeOptions);

Promise.all([
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: true,
});

assert.strictEqual(
typeof results[0].total,
'string',
'Valid supportBigNumbers enabled',
);
}),
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: false,
});

assert.strictEqual(
typeof results[0].total,
'number',
'Valid supportBigNumbers disabled',
);
}),

test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: 'text',
});

assert.strictEqual(
typeof results[0].total,
'string',
'supportBigNumbers as a random string should be enabled',
);
}),
test(async () => {
const [results] = await connection.execute({
sql,
supportBigNumbers: '',
});

assert.strictEqual(
typeof results[0].total,
'number',
'supportBigNumbers as an empty string should be disabled',
);
}),
]).then(async () => {
await connection.end();
});
Expand Up @@ -5,7 +5,7 @@ const connection = createConnection().promise();

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

describe('supportBigNumbers Sanitization', describeOptions);
describe('Text Parser: supportBigNumbers Sanitization', describeOptions);

Promise.all([
test(async () => {
Expand Down

0 comments on commit 71115d8

Please sign in to comment.