Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/index.js"
}
]
}
33 changes: 26 additions & 7 deletions src/support/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@
*/
import { isArray } from '@adobe/spacecat-shared-utils';

export const isDigestReport = (conf, alertType) => {
const alertConfig = isArray(conf?.alerts)
? conf?.alerts.find((alert) => alert.type === alertType)
: {};
return alertConfig?.byOrg;
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;
// };

// 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;
}
if (getAlertConfig(orgConf, alertType) !== null) {
return getAlertConfig(orgConf, alertType).byOrg;
}
return false;
};

export const hasAlertConfig = (conf, alertType) => isArray(conf?.alerts)
&& conf?.alerts.find((alert) => alert.type === alertType);
// 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
// else return getAlertConfig for orgConf is not null/undefined return orgAlertConfig.byOrg value
// else return false
// };

export const hasAlertConfig = (conf, alertType) => !!getAlertConfig(conf, alertType);
const getSlackContext = (conf, alertType) => {
const channel = conf?.slack?.channel;
const alertConfig = isArray(conf?.alerts)
Expand Down
21 changes: 21 additions & 0 deletions test/support/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ describe('config util', () => {
expect(slackContext.mentions).to.deep.equal(['slackId2']);
});

it('isDigestReport for valid configs bySite', () => {
const orgConfig = {
alerts: [{
type: '404',
}],
};
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: {
Expand Down