From e1a3e396b14029ea42bfc3df7260036bdfaa599e Mon Sep 17 00:00:00 2001 From: alinarublea Date: Tue, 26 Mar 2024 17:43:51 +0100 Subject: [PATCH 1/6] fix: code structure --- src/support/config.js | 13 ++++++++++--- test/support/config.test.js | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/support/config.js b/src/support/config.js index 68c87bc4..7ea7236b 100644 --- a/src/support/config.js +++ b/src/support/config.js @@ -11,16 +11,23 @@ */ import { isArray } from '@adobe/spacecat-shared-utils'; +export const getAlertConfig = (conf, alertType) => (isArray(conf?.alerts) + ? conf?.alerts.find((alert) => alert.type === alertType) : null); + export const isDigestReport = (conf, alertType) => { const alertConfig = isArray(conf?.alerts) ? conf?.alerts.find((alert) => alert.type === alertType) : {}; return alertConfig?.byOrg; }; +// TODO replace current implementation with the new one +// export const isDigestReport = (orgConf, siteConf, alertType) => { +// implement getAlertConfig for siteConf is not null/undefined return siteAlertConfig.byOrg value +// else return getAlertConfig for orgConf is not null/undefined return orgAlertConfig.byOrg value +// else return false +// }; -export const hasAlertConfig = (conf, alertType) => isArray(conf?.alerts) - && conf?.alerts.find((alert) => alert.type === alertType); - +export const hasAlertConfig = (conf, alertType) => !!getAlertConfig(conf, alertType); const getSlackContext = (conf, alertType) => { const channel = conf?.slack?.channel; const alertConfig = isArray(conf?.alerts) diff --git a/test/support/config.test.js b/test/support/config.test.js index 0d9c894a..f3a0f75e 100644 --- a/test/support/config.test.js +++ b/test/support/config.test.js @@ -70,6 +70,32 @@ describe('config util', () => { expect(slackContext.mentions).to.deep.equal(['slackId2']); }); + it('isDigestReport for valid configs bySite', () => { + const orgConfig = { + slack: { + workspace: 'workspace1', + channel: 'channel1', + }, + alerts: [{ + type: '404', + mentions: [{ slack: ['slackId1'] }], + }], + }; + const siteConfig = { + slack: { + workspace: 'workspace2', + channel: 'channel2', + }, + alerts: [{ + type: '404', + byOrg: false, + mentions: [{ slack: ['slackId2'] }], + }], + }; + const isDigest = isDigestReport(orgConfig, siteConfig, '404'); + expect(isDigest).to.be.false; + }); + it('getSlackContextForAlert returns only slack channel if no alerts are in config', () => { const orgConfig = { slack: { From 9a81977de297fbc068ec66730be19eb6441fe475 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Tue, 26 Mar 2024 17:45:34 +0100 Subject: [PATCH 2/6] fix: code structure --- src/support/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/support/config.js b/src/support/config.js index 7ea7236b..4686339f 100644 --- a/src/support/config.js +++ b/src/support/config.js @@ -22,7 +22,7 @@ export const isDigestReport = (conf, alertType) => { }; // TODO replace current implementation with the new one // export const isDigestReport = (orgConf, siteConf, alertType) => { -// implement getAlertConfig for siteConf is not null/undefined return siteAlertConfig.byOrg value +// if getAlertConfig for siteConf is not null/undefined return siteAlertConfig.byOrg value // else return getAlertConfig for orgConf is not null/undefined return orgAlertConfig.byOrg value // else return false // }; From 6f2b4389af0499e476fa8e7d6bfc45bbeb5236a8 Mon Sep 17 00:00:00 2001 From: alinarublea Date: Tue, 26 Mar 2024 18:02:24 +0100 Subject: [PATCH 3/6] fix: code structure --- test/support/config.test.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/support/config.test.js b/test/support/config.test.js index f3a0f75e..a3cabb25 100644 --- a/test/support/config.test.js +++ b/test/support/config.test.js @@ -72,13 +72,8 @@ describe('config util', () => { it('isDigestReport for valid configs bySite', () => { const orgConfig = { - slack: { - workspace: 'workspace1', - channel: 'channel1', - }, alerts: [{ type: '404', - mentions: [{ slack: ['slackId1'] }], }], }; const siteConfig = { From ed5166a2d9212dba89f1ffe670b3625db89dda5f Mon Sep 17 00:00:00 2001 From: Craig Hawkins Date: Tue, 2 Apr 2024 12:51:52 -0700 Subject: [PATCH 4/6] update idDigestReport --- .vscode/launch.json | 32 ++++++++++++++++++++++++++++++++ src/support/config.js | 26 +++++++++++++++++++++----- 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..3e14308b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + "version": "0.2.0", + "configurations": [ + + + { + "type": "node", + "request": "launch", + "name": "Mocha Tests", + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": [ + "--slow", + "5000", + "--colors", + "${workspaceFolder}/test/**/*.test.js", + ], + "internalConsoleOptions": "openOnSessionStart", + "skipFiles": [ + "/**" + ] + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/src/index.js" + } + ] +} \ No newline at end of file diff --git a/src/support/config.js b/src/support/config.js index 4686339f..8c8bec7e 100644 --- a/src/support/config.js +++ b/src/support/config.js @@ -14,12 +14,28 @@ import { isArray } from '@adobe/spacecat-shared-utils'; export const getAlertConfig = (conf, alertType) => (isArray(conf?.alerts) ? conf?.alerts.find((alert) => alert.type === alertType) : null); -export const isDigestReport = (conf, alertType) => { - const alertConfig = isArray(conf?.alerts) - ? conf?.alerts.find((alert) => alert.type === alertType) - : {}; - return alertConfig?.byOrg; +// export const isDigestReport = (conf, alertType) => { +// const alertConfig = isArray(conf?.alerts) +// ? conf?.alerts.find((alert) => alert.type === alertType) +// : {}; +// return alertConfig?.byOrg; +// }; + +export const isDigestReport = (orgConf, siteConf, alertType) => { + // Check site configuration first + if (getAlertConfig(siteConf, alertType) !== null) { + return getAlertConfig(siteConf, alertType).byOrg; + } + + // Check organization configuration if site configuration not found + if (getAlertConfig(orgConf, alertType) !== null) { + return getAlertConfig(orgConf, alertType).byOrg; + } + + // Return false if no matching alert config found + return false; }; + // TODO replace current implementation with the new one // export const isDigestReport = (orgConf, siteConf, alertType) => { // if getAlertConfig for siteConf is not null/undefined return siteAlertConfig.byOrg value From 6e7e8f0203dde218ad77d049bab7d8e731dbc85f Mon Sep 17 00:00:00 2001 From: Craig Hawkins Date: Wed, 3 Apr 2024 09:02:47 -0700 Subject: [PATCH 5/6] isDigestReport update --- src/support/config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/support/config.js b/src/support/config.js index 8c8bec7e..e569373f 100644 --- a/src/support/config.js +++ b/src/support/config.js @@ -22,17 +22,12 @@ export const getAlertConfig = (conf, alertType) => (isArray(conf?.alerts) // }; export const isDigestReport = (orgConf, siteConf, alertType) => { - // Check site configuration first if (getAlertConfig(siteConf, alertType) !== null) { return getAlertConfig(siteConf, alertType).byOrg; } - - // Check organization configuration if site configuration not found if (getAlertConfig(orgConf, alertType) !== null) { return getAlertConfig(orgConf, alertType).byOrg; } - - // Return false if no matching alert config found return false; }; From f9846785b6d3203151d8541032252520793189c8 Mon Sep 17 00:00:00 2001 From: Craig Hawkins Date: Wed, 3 Apr 2024 18:30:47 -0700 Subject: [PATCH 6/6] test of isDigestReport --- src/support/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/support/config.js b/src/support/config.js index e569373f..f9fd90bd 100644 --- a/src/support/config.js +++ b/src/support/config.js @@ -21,6 +21,7 @@ export const getAlertConfig = (conf, alertType) => (isArray(conf?.alerts) // return alertConfig?.byOrg; // }; +// used AI just to see if I could get the test to work -- it is still failing export const isDigestReport = (orgConf, siteConf, alertType) => { if (getAlertConfig(siteConf, alertType) !== null) { return getAlertConfig(siteConf, alertType).byOrg;