diff --git a/test/common.test.cjs b/test/common.test.cjs index e46510c0cc..f3cf230766 100644 --- a/test/common.test.cjs +++ b/test/common.test.cjs @@ -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); @@ -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; }; diff --git a/test/esm/integration/parsers/json-parse.test.mjs b/test/esm/integration/parsers/json-parse.test.mjs new file mode 100644 index 0000000000..99a0690e99 --- /dev/null +++ b/test/esm/integration/parsers/json-parse.test.mjs @@ -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(); +}); diff --git a/test/esm/integration/parsers/json-string.test.mjs b/test/esm/integration/parsers/json-string.test.mjs new file mode 100644 index 0000000000..098777051e --- /dev/null +++ b/test/esm/integration/parsers/json-string.test.mjs @@ -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(); +});