Skip to content

Commit

Permalink
ci: add tests to JSON parsers (#2720)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored May 30, 2024
1 parent 9820fe5 commit b5df699
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/common.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ exports.createConnection = function (args) {
connectTimeout: args && args.connectTimeout,
nestTables: args && args.nestTables,
ssl: (args && args.ssl) ?? config.ssl,
jsonStrings: args && args.jsonStrings,
};

const conn = driver.createConnection(params);
Expand Down Expand Up @@ -137,6 +138,7 @@ exports.getConfig = function (input) {
connectionLimit: args && args.connectionLimit,
maxIdle: args && args.maxIdle,
idleTimeout: args && args.idleTimeout,
jsonStrings: args && args.jsonStrings,
};
return params;
};
Expand Down
39 changes: 39 additions & 0 deletions test/esm/integration/parsers/json-parse.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, describe, assert } from 'poku';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
createConnection,
describeOptions,
} = require('../../../common.test.cjs');

describe('JSON Parser', describeOptions);

const connection = createConnection().promise();

Promise.all([
test(async () => {
const [result] = await connection.query(
`SELECT CAST('{"test": true}' AS JSON) AS json_result`,
);

assert.deepStrictEqual(
result[0].json_result,
{ test: true },
'Ensure JSON return parsed (query)',
);
}),
test(async () => {
const [result] = await connection.execute(
`SELECT CAST('{"test": true}' AS JSON) AS json_result`,
);

assert.deepStrictEqual(
result[0].json_result,
{ test: true },
'Ensure JSON return parsed (execute)',
);
}),
]).then(async () => {
await connection.end();
});
41 changes: 41 additions & 0 deletions test/esm/integration/parsers/json-string.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { test, describe, assert } from 'poku';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
createConnection,
describeOptions,
} = require('../../../common.test.cjs');

describe('JSON String', describeOptions);

const connection = createConnection({
jsonStrings: true,
}).promise();

Promise.all([
test(async () => {
const [result] = await connection.query(
`SELECT CAST('{"test": true}' AS JSON) AS json_result`,
);

assert.deepStrictEqual(
result[0].json_result,
'{"test": true}',
'Ensure JSON return as string (query)',
);
}),
test(async () => {
const [result] = await connection.execute(
`SELECT CAST('{"test": true}' AS JSON) AS json_result`,
);

assert.deepStrictEqual(
result[0].json_result,
'{"test": true}',
'Ensure JSON return as string (execute)',
);
}),
]).then(async () => {
await connection.end();
});

0 comments on commit b5df699

Please sign in to comment.