Skip to content

Commit d3a581c

Browse files
authored
Changed StrategyValidator DATE format check to use YYYY-MM-DD HH:mm (#548)
1 parent ae0619c commit d3a581c

File tree

6 files changed

+62
-48
lines changed

6 files changed

+62
-48
lines changed

npm-shrinkwrap.json

Lines changed: 30 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
},
6060
"devDependencies": {
6161
"env-cmd": "^10.1.0",
62-
"eslint": "^9.14.0",
62+
"eslint": "^9.15.0",
6363
"jest": "^29.7.0",
6464
"jest-sonar-reporter": "^2.0.0",
6565
"node-notifier": "^10.0.1",

src/models/config-strategy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const StrategyRequirementDefinition = [
5353
{
5454
strategy: StrategiesType.DATE,
5555
operations: [OperationsType.BETWEEN, OperationsType.LOWER, OperationsType.GREATER],
56-
format: 'YYYY-MM-DD or YYYY-MM-DDTHH:mm',
57-
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])?$'
56+
format: 'YYYY-MM-DD or YYYY-MM-DD HH:mm',
57+
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])?$'
5858
},
5959
{
6060
strategy: StrategiesType.REGEX,

tests/config-strategy.test.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ afterAll(async () => {
2929
describe('Testing strategy creation #1', () => {
3030
beforeAll(setupDatabase);
3131

32-
test('STRATEGY_SUITE - Should create a new Config Strategy', async () => {
32+
test('STRATEGY_SUITE - Should create a new Config Strategy - NETWORK', async () => {
3333
const response = await request(app)
3434
.post('/configstrategy/create')
3535
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
3636
.send({
37-
description: 'Description of my new Config Strategy',
37+
description: 'Description of my new Config Strategy - NETWORK',
3838
strategy: StrategiesType.NETWORK,
3939
operation: OperationsType.EXIST,
4040
values: ['192.168.0.1/16'],
@@ -47,7 +47,28 @@ describe('Testing strategy creation #1', () => {
4747
expect(configStrategy).not.toBeNull();
4848

4949
// Response validation
50-
expect(response.body.description).toBe('Description of my new Config Strategy');
50+
expect(response.body.description).toBe('Description of my new Config Strategy - NETWORK');
51+
});
52+
53+
test('STRATEGY_SUITE - Should create a new Config Strategy - DATE/TIME', async () => {
54+
const response = await request(app)
55+
.post('/configstrategy/create')
56+
.set('Authorization', `Bearer ${adminMasterAccountToken}`)
57+
.send({
58+
description: 'Description of my new Config Strategy - DATE',
59+
strategy: StrategiesType.DATE,
60+
operation: OperationsType.GREATER,
61+
values: ['2019-12-12 00:00'],
62+
config: configId2,
63+
env: EnvType.DEFAULT
64+
}).expect(201);
65+
66+
// DB validation - document created
67+
const configStrategy = await ConfigStrategy.findById(response.body._id).lean().exec();
68+
expect(configStrategy).not.toBeNull();
69+
70+
// Response validation
71+
expect(response.body.description).toBe('Description of my new Config Strategy - DATE');
5172
});
5273

5374
test('STRATEGY_SUITE - Should NOT create a new Config Strategy - Config not found', async () => {

tests/fixtures/db_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const configStrategyTIME_GREATDocument = {
145145
config: configId,
146146
operation: OperationsType.GREATER,
147147
strategy: StrategiesType.DATE,
148-
values: ['2019-12-01T13:00'],
148+
values: ['2019-12-01 13:00'],
149149
domain: domainId
150150
};
151151

tests/graphql-utils/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const expected101 = `
145145
"strategy":"DATE_VALIDATION",
146146
"activated":false,
147147
"operation":"GREATER",
148-
"values":["2019-12-01T13:00"]
148+
"values":["2019-12-01 13:00"]
149149
}
150150
]
151151
}
@@ -260,7 +260,7 @@ export const expected103 = `
260260
"activated":false,
261261
"operation":"GREATER",
262262
"values":[
263-
"2019-12-01T13:00"
263+
"2019-12-01 13:00"
264264
]}
265265
]}
266266
]}
@@ -315,7 +315,7 @@ export const expected106 = `
315315
{"strategy":"VALUE_VALIDATION","statusByEnv":[{"env":"default","value":true}],"operation":"EXIST","values":["USER_1","USER_2","USER_3"]},
316316
{"strategy":"NETWORK_VALIDATION","statusByEnv":[{"env":"default","value":true}],"operation":"EXIST","values":["10.0.0.0/24"]},
317317
{"strategy":"TIME_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"BETWEEN","values":["13:00","14:00"]},
318-
{"strategy":"DATE_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"GREATER","values":["2019-12-01T13:00"]}]},
318+
{"strategy":"DATE_VALIDATION","statusByEnv":[{"env":"default","value":false}],"operation":"GREATER","values":["2019-12-01 13:00"]}]},
319319
{"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}],
320320
"strategies":[]}]}]}}}`;
321321

@@ -364,7 +364,7 @@ export const expected108 = `
364364
{"strategy":"VALUE_VALIDATION","operation":"EXIST","values":["USER_1","USER_2","USER_3"],"statusByEnv":[{"env":"default","value":true}]},
365365
{"strategy":"NETWORK_VALIDATION","operation":"EXIST","values":["10.0.0.0/24"],"statusByEnv":[{"env":"default","value":true}]},
366366
{"strategy":"TIME_VALIDATION","operation":"BETWEEN","values":["13:00","14:00"],"statusByEnv":[{"env":"default","value":false}]},
367-
{"strategy":"DATE_VALIDATION","operation":"GREATER","values":["2019-12-01T13:00"],"statusByEnv":[{"env":"default","value":false}]}]}}}`;
367+
{"strategy":"DATE_VALIDATION","operation":"GREATER","values":["2019-12-01 13:00"],"statusByEnv":[{"env":"default","value":false}]}]}}}`;
368368

369369
export const expected109 = `
370370
{"data":

0 commit comments

Comments
 (0)