Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonPetkov96 committed Oct 23, 2023
1 parent cbbb273 commit 9995650
Show file tree
Hide file tree
Showing 3 changed files with 617 additions and 582 deletions.
22 changes: 2 additions & 20 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { existsSync, readFileSync } = require('fs');
const { basename } = require('path');
const cds = require("@sap/cds");
const LOG = cds.log('notifications');
const { executeHttpRequest } = require("@sap-cloud-sdk/http-client");
const { getDestination } = require("@sap-cloud-sdk/connectivity");
const PRIORITIES = ["LOW", "NEUTRAL", "MEDIUM", "HIGH"];

Expand All @@ -23,12 +22,12 @@ const messages = {
};

function validateNotificationTypes(notificationTypes) {
notificationTypes.forEach((notificationType) => {
for(notificationType of notificationTypes){
if (!("NotificationTypeKey" in notificationType)) {
LOG._warn && LOG.warn(messages.INVALID_NOTIFICATION_TYPES);
return false;
}
});
}

return true;
}
Expand Down Expand Up @@ -128,22 +127,6 @@ function getNotificationTypesKeyWithPrefix(notificationTypeKey) {
return `${prefix}/${notificationTypeKey}`;
}

async function executeRequest(httpMethod, targetUrl, payload, notificationDestination, csrfHeaders) {
let response = {};
try {
response = await executeHttpRequest(notificationDestination, {
url: targetUrl,
method: httpMethod,
data: payload,
headers: csrfHeaders,
});
} catch (e) {
console.log(e);
response = e.response.data;
}
return response;
}

function buildDefaultNotification(
recipients,
priority = "NEUTRAL",
Expand Down Expand Up @@ -255,6 +238,5 @@ module.exports = {
getNotificationDestination,
getPrefix,
getNotificationTypesKeyWithPrefix,
executeRequest,
buildNotification
};
Loading

0 comments on commit 9995650

Please sign in to comment.