From 33346e0cee95c14714038a3642bc306def86ccdd Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 29 Jan 2025 17:28:46 +0100 Subject: [PATCH] test(server/utils): add tests for sanitizeSqlIdentifier --- src/services/utils.spec.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index 6ead22576..57f658b5b 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -43,7 +43,28 @@ describe("#isEmptyOrWhitespace", () => { }); -describe.todo("#sanitizeSqlIdentifier", () => {}); +describe("#sanitizeSqlIdentifier", () => { + + const testCases: TestCase[] = [ + ["w/ 'test' it should not strip anything", ["test"], "test"], + ["w/ 'test123' it should not strip anything", ["test123"], "test123"], + ["w/ 'tEst_TeSt' it should not strip anything", ["tEst_TeSt"], "tEst_TeSt"], + ["w/ 'test_test' it should not strip '_'", ["test_test"], "test_test"], + ["w/ 'test-' it should strip the '-'", ["test-"], "test"], + ["w/ 'test-test' it should strip the '-'", ["test-test"], "testtest"], + ["w/ 'test; --test' it should strip the '; --'", ["test; --test"], "testtest"], + ["w/ 'test test' it should strip the ' '", ["test test"], "testtest"], + ]; + + testCases.forEach(testCase => { + const [desc, fnParams, expected] = testCase; + it(desc, () => { + const result = utils.sanitizeSqlIdentifier(...fnParams); + expect(result).toStrictEqual(expected); + }) + }); + +}); describe.todo("#escapeHtml", () => {});