diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index 9fccd051..9d803bcc 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -153,6 +153,7 @@ import "./tests/SIGABA.mjs"; import "./tests/SM2.mjs"; import "./tests/SM4.mjs"; // import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet +import "./tests/SQLBeautify.mjs"; import "./tests/StrUtils.mjs"; import "./tests/StripIPv4Header.mjs"; import "./tests/StripTCPHeader.mjs"; diff --git a/tests/operations/tests/SQLBeautify.mjs b/tests/operations/tests/SQLBeautify.mjs new file mode 100644 index 00000000..92d02ade --- /dev/null +++ b/tests/operations/tests/SQLBeautify.mjs @@ -0,0 +1,54 @@ +/** + * SQLBeautify tests. + * + * @author GCHQDeveloper581 + * @copyright Crown Copyright 2026 + * @license Apache-2.0 + */ +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "SQL Beautify - basic", + input: "SELECT MONTH, ID, RAIN_I, TEMP_F FROM STATS;", + expectedOutput: +`SELECT + MONTH, + ID, + RAIN_I, + TEMP_F +FROM + STATS;`, + recipeConfig: [ + { + op: "SQL Beautify", + args: [" "], + }, + ], + }, + { + name: "SQL Beautify - upsert", + input: "INSERT INTO Table1 SELECT * FROM (SELECT :Bind1 as Field1, :Bind2 as Field2, :id as id) as new_data ON DUPLICATE KEY UPDATE Field1 = new_data.Field1, Field2 = new_data.Field2;", + expectedOutput: +`INSERT INTO + Table1 +SELECT + * +FROM + ( + SELECT + :Bind1 as Field1, + :Bind2 as Field2, + :id as id + ) as new_data +ON DUPLICATE KEY UPDATE + Field1 = new_data.Field1, + Field2 = new_data.Field2;`, + recipeConfig: [ + { + op: "SQL Beautify", + args: [" "], + }, + ], + }, +]);