From 6c340f17c1558909bc98c93e1751c7d281498237 Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Sat, 16 Nov 2024 15:04:34 -0800 Subject: [PATCH] Changed StrategyValidator DATE format check to use YYYY-MM-DD HH:mm --- npm-shrinkwrap.json | 67 ++++++++++++++++------------------- package.json | 2 +- src/models/config-strategy.js | 4 +-- tests/config-strategy.test.js | 27 ++++++++++++-- tests/fixtures/db_client.js | 2 +- tests/graphql-utils/index.js | 8 ++--- 6 files changed, 62 insertions(+), 48 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index a84f7d3..829156b 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -32,7 +32,7 @@ }, "devDependencies": { "env-cmd": "^10.1.0", - "eslint": "^9.14.0", + "eslint": "^9.15.0", "jest": "^29.7.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", @@ -555,9 +555,9 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", - "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.19.0.tgz", + "integrity": "sha512-zdHg2FPIFNKPdcHWtiNT+jEFCHYVplAXRDlQDyqy0zGx/q2parwh7brGJSiTxRk/TSMkbM//zt/f5CHgyTyaSQ==", "dev": true, "dependencies": { "@eslint/object-schema": "^2.1.4", @@ -569,18 +569,18 @@ } }, "node_modules/@eslint/core": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.7.0.tgz", - "integrity": "sha512-xp5Jirz5DyPYlPiKat8jaq0EmYvDXKKpzTbxXMpT9eqlRJkRKIz9AGMdlvYjih+im+QlhWrpvVjl8IPC/lHlUw==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.0.tgz", + "integrity": "sha512-7ATR9F0e4W85D/0w7cU0SNj7qkAexMG+bAHEZOjo9akvGuhHE2m7umzWzfnpa0XAg5Kxc1BWmtPMV67jJ+9VUg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@eslint/eslintrc": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", - "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.2.0.tgz", + "integrity": "sha512-grOjVNN8P3hjJn/eIETF1wwd12DdnwFDoyceUJLYYdkpbwq3nLi+4fqrTAONx7XDALqlL220wC/RHSC/QTI/0w==", "dev": true, "dependencies": { "ajv": "^6.12.4", @@ -601,9 +601,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.14.0.tgz", - "integrity": "sha512-pFoEtFWCPyDOl+C6Ift+wC7Ro89otjigCf5vcuWqWgqNSQbRrpjSvdeE6ofLz4dHmyxD5f7gIdGT4+p36L6Twg==", + "version": "9.15.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.15.0.tgz", + "integrity": "sha512-tMTqrY+EzbXmKJR5ToI8lxu7jaN5EdmrBFJpQk5JmSlyLsx6o4t27r883K5xsLuCYCpfKBCGswMSWXsM+jB7lg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -619,9 +619,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.2.tgz", - "integrity": "sha512-CXtq5nR4Su+2I47WPOlWud98Y5Lv8Kyxp2ukhgFx/eW6Blm18VXJO5WuQylPugRo8nbluoi6GvvxBLqHcvqUUw==", + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.3.tgz", + "integrity": "sha512-2b/g5hRmpbb1o4GnTZax9N9m0FXzz9OV42ZzI4rDDMDuHUqigAiQCEWChBWCY4ztAGVRjoWT19v0yMmc5/L5kA==", "dev": true, "dependencies": { "levn": "^0.4.1" @@ -2235,9 +2235,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.5.55", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.55.tgz", - "integrity": "sha512-6maZ2ASDOTBtjt9FhqYPRnbvKU5tjG0IN9SztUOWYw2AzNDNpKJYLJmlK0/En4Hs/aiWnB+JZ+gW19PIGszgKg==", + "version": "1.5.62", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.62.tgz", + "integrity": "sha512-t8c+zLmJHa9dJy96yBZRXGQYoiCEnHYgFwn1asvSPZSUdVxnB62A4RASd7k41ytG3ErFBA0TpHlKg9D9SQBmLg==", "dev": true }, "node_modules/emittery": { @@ -2345,26 +2345,26 @@ } }, "node_modules/eslint": { - "version": "9.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.14.0.tgz", - "integrity": "sha512-c2FHsVBr87lnUtjP4Yhvk4yEhKrQavGafRA/Se1ouse8PfbfC/Qh9Mxa00yWsZRlqeUB9raXip0aiiUZkgnr9g==", + "version": "9.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.15.0.tgz", + "integrity": "sha512-7CrWySmIibCgT1Os28lUU6upBshZ+GxybLOrmRzi08kS8MBuO8QA7pXEgYgY5W8vK3e74xv0lpjo9DbaGU9Rkw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", - "@eslint/config-array": "^0.18.0", - "@eslint/core": "^0.7.0", - "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.14.0", - "@eslint/plugin-kit": "^0.2.0", + "@eslint/config-array": "^0.19.0", + "@eslint/core": "^0.9.0", + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "9.15.0", + "@eslint/plugin-kit": "^0.2.3", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.4.0", + "@humanwhocodes/retry": "^0.4.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", + "cross-spawn": "^7.0.5", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0", @@ -2383,8 +2383,7 @@ "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", - "optionator": "^0.9.3", - "text-table": "^0.2.0" + "optionator": "^0.9.3" }, "bin": { "eslint": "bin/eslint.js" @@ -5835,12 +5834,6 @@ "node": ">=8" } }, - "node_modules/text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true - }, "node_modules/thread-stream": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-3.1.0.tgz", diff --git a/package.json b/package.json index 2a641aa..b2e9dd9 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "devDependencies": { "env-cmd": "^10.1.0", - "eslint": "^9.14.0", + "eslint": "^9.15.0", "jest": "^29.7.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", diff --git a/src/models/config-strategy.js b/src/models/config-strategy.js index bb88760..1ed8201 100644 --- a/src/models/config-strategy.js +++ b/src/models/config-strategy.js @@ -53,8 +53,8 @@ const StrategyRequirementDefinition = [ { strategy: StrategiesType.DATE, operations: [OperationsType.BETWEEN, OperationsType.LOWER, OperationsType.GREATER], - format: 'YYYY-MM-DD or YYYY-MM-DDTHH:mm', - validator: '([12][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))(T(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9])?$' + format: 'YYYY-MM-DD or YYYY-MM-DD HH:mm', + validator: '([12][0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01]))( (0[0-9]|1[0-9]|2[0-3]):[0-5][0-9])?$' }, { strategy: StrategiesType.REGEX, diff --git a/tests/config-strategy.test.js b/tests/config-strategy.test.js index d619496..68c7672 100644 --- a/tests/config-strategy.test.js +++ b/tests/config-strategy.test.js @@ -29,12 +29,12 @@ afterAll(async () => { describe('Testing strategy creation #1', () => { beforeAll(setupDatabase); - test('STRATEGY_SUITE - Should create a new Config Strategy', async () => { + test('STRATEGY_SUITE - Should create a new Config Strategy - NETWORK', async () => { const response = await request(app) .post('/configstrategy/create') .set('Authorization', `Bearer ${adminMasterAccountToken}`) .send({ - description: 'Description of my new Config Strategy', + description: 'Description of my new Config Strategy - NETWORK', strategy: StrategiesType.NETWORK, operation: OperationsType.EXIST, values: ['192.168.0.1/16'], @@ -47,7 +47,28 @@ describe('Testing strategy creation #1', () => { expect(configStrategy).not.toBeNull(); // Response validation - expect(response.body.description).toBe('Description of my new Config Strategy'); + expect(response.body.description).toBe('Description of my new Config Strategy - NETWORK'); + }); + + test('STRATEGY_SUITE - Should create a new Config Strategy - DATE/TIME', async () => { + const response = await request(app) + .post('/configstrategy/create') + .set('Authorization', `Bearer ${adminMasterAccountToken}`) + .send({ + description: 'Description of my new Config Strategy - DATE', + strategy: StrategiesType.DATE, + operation: OperationsType.GREATER, + values: ['2019-12-12 00:00'], + config: configId2, + env: EnvType.DEFAULT + }).expect(201); + + // DB validation - document created + const configStrategy = await ConfigStrategy.findById(response.body._id).lean().exec(); + expect(configStrategy).not.toBeNull(); + + // Response validation + expect(response.body.description).toBe('Description of my new Config Strategy - DATE'); }); test('STRATEGY_SUITE - Should NOT create a new Config Strategy - Config not found', async () => { diff --git a/tests/fixtures/db_client.js b/tests/fixtures/db_client.js index 77656e4..9444761 100644 --- a/tests/fixtures/db_client.js +++ b/tests/fixtures/db_client.js @@ -145,7 +145,7 @@ export const configStrategyTIME_GREATDocument = { config: configId, operation: OperationsType.GREATER, strategy: StrategiesType.DATE, - values: ['2019-12-01T13:00'], + values: ['2019-12-01 13:00'], domain: domainId }; diff --git a/tests/graphql-utils/index.js b/tests/graphql-utils/index.js index da88778..ba256ea 100644 --- a/tests/graphql-utils/index.js +++ b/tests/graphql-utils/index.js @@ -145,7 +145,7 @@ export const expected101 = ` "strategy":"DATE_VALIDATION", "activated":false, "operation":"GREATER", - "values":["2019-12-01T13:00"] + "values":["2019-12-01 13:00"] } ] } @@ -260,7 +260,7 @@ export const expected103 = ` "activated":false, "operation":"GREATER", "values":[ - "2019-12-01T13:00" + "2019-12-01 13:00" ]} ]} ]} @@ -315,7 +315,7 @@ export const expected106 = ` {"strategy":"VALUE_VALIDATION","statusByEnv":[{"env":"default","value":true}],"operation":"EXIST","values":["USER_1","USER_2","USER_3"]}, {"strategy":"NETWORK_VALIDATION","statusByEnv":[{"env":"default","value":true}],"operation":"EXIST","values":["10.0.0.0/24"]}, {"strategy":"TIME_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"BETWEEN","values":["13:00","14:00"]}, - {"strategy":"DATE_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"GREATER","values":["2019-12-01T13:00"]}]}, + {"strategy":"DATE_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"GREATER","values":["2019-12-01 13:00"]}]}, {"key":"TEST_CONFIG_KEY_PRD_QA","description":"Test config 2 - Off in PRD and ON in QA","statusByEnv":[{"env":"default","value":false},{"env":"QA","value":true}], "strategies":[]}]}]}}}`; @@ -364,7 +364,7 @@ export const expected108 = ` {"strategy":"VALUE_VALIDATION","operation":"EXIST","values":["USER_1","USER_2","USER_3"],"statusByEnv":[{"env":"default","value":true}]}, {"strategy":"NETWORK_VALIDATION","operation":"EXIST","values":["10.0.0.0/24"],"statusByEnv":[{"env":"default","value":true}]}, {"strategy":"TIME_VALIDATION","operation":"BETWEEN","values":["13:00","14:00"],"statusByEnv":[{"env":"default","value":false}]}, - {"strategy":"DATE_VALIDATION","operation":"GREATER","values":["2019-12-01T13:00"],"statusByEnv":[{"env":"default","value":false}]}]}}}`; + {"strategy":"DATE_VALIDATION","operation":"GREATER","values":["2019-12-01 13:00"],"statusByEnv":[{"env":"default","value":false}]}]}}}`; export const expected109 = ` {"data":