From 6623b615f104172c72b71f37262545913e6d59f7 Mon Sep 17 00:00:00 2001 From: I339886 Date: Wed, 18 Oct 2023 14:54:25 +0300 Subject: [PATCH 1/3] Tests for Notification Types --- .prettierrc | 2 +- lib/content-deployment.js | 8 +- lib/notificationTypes.js | 112 ++-- package.json | 6 +- test/lib/content-deployment.test.js | 49 ++ test/lib/notificationTypes.test.js | 891 ++++++++++++++++++++++++++++ 6 files changed, 1006 insertions(+), 62 deletions(-) create mode 100644 test/lib/content-deployment.test.js create mode 100644 test/lib/notificationTypes.test.js diff --git a/.prettierrc b/.prettierrc index cf03df3..8cf0cf3 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { "tabWidth": 2, "useTabs": false, - "printWidth": 150 + "printWidth": 200 } \ No newline at end of file diff --git a/lib/content-deployment.js b/lib/content-deployment.js index 37279a2..ed11c0f 100644 --- a/lib/content-deployment.js +++ b/lib/content-deployment.js @@ -1,13 +1,13 @@ const cds = require("@sap/cds"); const { validateNotificationTypes, readFile } = require("./utils"); -const { createNotificationTypesMap, processNotificationTypes } = require("./notificationTypes"); +const { processNotificationTypes } = require("./notificationTypes"); const { setGlobalLogLevel } = require("@sap-cloud-sdk/util"); async function deployNotificationTypes() { setGlobalLogLevel("error"); // read notification types - const notificationTypes = readFile(cds.env.requires?.notifications?.types); + const notificationTypes = readFile(cds.env?.requires?.notifications?.types); if (validateNotificationTypes(notificationTypes)) { await processNotificationTypes(notificationTypes); @@ -15,3 +15,7 @@ async function deployNotificationTypes() { } deployNotificationTypes(); + +module.exports = { + deployNotificationTypes +} \ No newline at end of file diff --git a/lib/notificationTypes.js b/lib/notificationTypes.js index 93bc8f9..012e63d 100644 --- a/lib/notificationTypes.js +++ b/lib/notificationTypes.js @@ -1,45 +1,45 @@ const { executeHttpRequest } = require("@sap-cloud-sdk/http-client"); const { buildHeadersForDestination } = require("@sap-cloud-sdk/connectivity"); -const { getNotificationDestination, doesKeyExist, getPrefix, getNotificationTypesKeyWithPrefix, executeRequest } = require("./utils"); +const { getNotificationDestination, doesKeyExist, getPrefix, getNotificationTypesKeyWithPrefix } = require("./utils"); const _ = require("lodash"); const NOTIFICATION_TYPES_API_ENDPOINT = "v2/NotificationType.svc"; const defaultTemplate = { - "NotificationTypeKey": "Default", - "NotificationTypeVersion": "1", - "Templates": [ + NotificationTypeKey: "Default", + NotificationTypeVersion: "1", + Templates: [ { - "Language": "en", - "Description": "Other Notifications", - "TemplatePublic": "{{title}}", - "TemplateSensitive": "{{title}}", - "TemplateGrouped": "Other Notifications", - "TemplateLanguage": "mustache", - "Subtitle": "{{description}}" - } - ] -} + Language: "en", + Description: "Other Notifications", + TemplatePublic: "{{title}}", + TemplateSensitive: "{{title}}", + TemplateGrouped: "Other Notifications", + TemplateLanguage: "mustache", + Subtitle: "{{description}}", + }, + ], +}; function fromOdataArrayFormat(objectInArray) { if (objectInArray === undefined || objectInArray === null || Array.isArray(objectInArray)) { - return objectInArray; + return objectInArray === undefined || objectInArray === null ? [] : objectInArray; } else { - return objectInArray.results; + return objectInArray.results === undefined || objectInArray.results === null ? [] : objectInArray.results; } } function createNotificationTypesMap(notificationTypesJSON, isLocal = false) { const types = {}; - if(isLocal) { - types["Default"] = { "1": defaultTemplate }; + if (isLocal) { + types["Default"] = { 1: defaultTemplate }; } // add user provided templates notificationTypesJSON.forEach((notificationType) => { // set default NotificationTypeVersion if required - if(notificationType.NotificationTypeVersion === undefined) { + if (notificationType.NotificationTypeVersion === undefined) { notificationType.NotificationTypeVersion = "1"; } @@ -91,7 +91,7 @@ async function updateNotificationType(id, notificationType) { const csrfHeaders = await buildHeadersForDestination(notificationDestination, { url: NOTIFICATION_TYPES_API_ENDPOINT, }); - + console.log( `Detected change in notification type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion}. Updating it...` ); @@ -124,30 +124,26 @@ async function deleteNotificationType(notificationType) { } function _createChannelsMap(channels) { - if(channels === null || channels === undefined) { - return {}; - } - const channelMap = {}; channels.forEach((channel) => { channelMap[channel.Type] = channel; - }) + }); return channelMap; } function areDeliveryChannelsEqual(oldChannels, newChannels) { - if(_.size(oldChannels) !== _.size(newChannels)) { + if (_.size(oldChannels) !== _.size(newChannels)) { return false; } const oldChannelsMap = _createChannelsMap(oldChannels); const newChannelsMap = _createChannelsMap(newChannels); - for(type of Object.keys(oldChannelsMap)) { - if(!(type in newChannelsMap)) return false; - + for (type of Object.keys(oldChannelsMap)) { + if (!(type in newChannelsMap)) return false; + const oldChannel = oldChannelsMap[type]; const newChannel = newChannelsMap[type]; @@ -158,7 +154,7 @@ function areDeliveryChannelsEqual(oldChannels, newChannels) { oldChannel.DefaultPreference == newChannel.DefaultPreference && oldChannel.EditablePreference == newChannel.EditablePreference; - if(!equal) return false; + if (!equal) return false; delete newChannelsMap[type]; } @@ -172,11 +168,11 @@ function isActionEqual(oldAction, newAction) { oldAction.ActionText == newAction.ActionText && oldAction.GroupActionText == newAction.GroupActionText && oldAction.Nature == newAction.Nature - ) + ); } function areActionsEqual(oldActions, newActions) { - if(_.size(oldActions) !== _.size(newActions)) { + if (_.size(oldActions) !== _.size(newActions)) { return false; } @@ -208,11 +204,11 @@ function isTemplateEqual(oldTemplate, newTemplate) { oldTemplate.EmailSubject == newTemplate.EmailSubject && oldTemplate.EmailText == newTemplate.EmailText && oldTemplate.EmailHtml == newTemplate.EmailHtml - ) + ); } function areTemplatesEqual(oldTemplates, newTemplates) { - if(_.size(oldTemplates) !== _.size(newTemplates)) { + if (_.size(oldTemplates) !== _.size(newTemplates)) { return false; } @@ -233,16 +229,16 @@ function areTemplatesEqual(oldTemplates, newTemplates) { } function isNotificationTypeEqual(oldNotificationType, newNotificationType) { - if(newNotificationType.IsGroupable === undefined) { + if (newNotificationType.IsGroupable === undefined) { newNotificationType.IsGroupable = true; } return ( oldNotificationType.IsGroupable == newNotificationType.IsGroupable && - areTemplatesEqual(oldNotificationType.Templates.results, fromOdataArrayFormat(newNotificationType.Templates)) && - areActionsEqual(oldNotificationType.Actions.results, fromOdataArrayFormat(newNotificationType.Actions)) && - areDeliveryChannelsEqual(oldNotificationType.DeliveryChannels.results, fromOdataArrayFormat(newNotificationType.DeliveryChannels)) - ) + areTemplatesEqual(fromOdataArrayFormat(oldNotificationType.Templates), fromOdataArrayFormat(newNotificationType.Templates)) && + areActionsEqual(fromOdataArrayFormat(oldNotificationType.Actions), fromOdataArrayFormat(newNotificationType.Actions)) && + areDeliveryChannelsEqual(fromOdataArrayFormat(oldNotificationType.DeliveryChannels), fromOdataArrayFormat(newNotificationType.DeliveryChannels)) + ); } async function processNotificationTypes(notificationTypesJSON) { @@ -254,21 +250,22 @@ async function processNotificationTypes(notificationTypesJSON) { const existingTypes = await getNotificationTypes(); // iterate through notification types - for(const existingType of existingTypes) { - if(existingType.NotificationTypeKey == "Default") { + for (const existingType of existingTypes) { + if (existingType.NotificationTypeKey == "Default") { defaultTemplateExists = true; continue; } - if(!existingType.NotificationTypeKey.startsWith(`${prefix}/`)) { - console.log( - `Skipping Notification Type of other application: ${existingType.NotificationTypeKey}.` - ); + if (!existingType.NotificationTypeKey.startsWith(`${prefix}/`)) { + console.log(`Skipping Notification Type of other application: ${existingType.NotificationTypeKey}.`); continue; } // if the type isn't present in the JSON file, delete it - if(notificationTypes[existingType.NotificationTypeKey] === undefined || notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] === undefined) { + if ( + notificationTypes[existingType.NotificationTypeKey] === undefined || + notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] === undefined + ) { await deleteNotificationType(existingType); continue; } @@ -276,28 +273,29 @@ async function processNotificationTypes(notificationTypesJSON) { const newType = JSON.parse(JSON.stringify(notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion])); // if the type is there then verify if everything is same or not - if(!isNotificationTypeEqual(existingType, newType)) { - await updateNotificationType(existingType.NotificationTypeId, notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion]) - } else { - console.log( - `Notification Type of key ${existingType.NotificationTypeKey} and version ${existingType.NotificationTypeVersion} unchanged.` + if (!isNotificationTypeEqual(existingType, newType)) { + await updateNotificationType( + existingType.NotificationTypeId, + notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] ); + } else { + console.log(`Notification Type of key ${existingType.NotificationTypeKey} and version ${existingType.NotificationTypeVersion} unchanged.`); } delete notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion]; - if(Object.keys(notificationTypes[existingType.NotificationTypeKey]).length == 0) { + if (Object.keys(notificationTypes[existingType.NotificationTypeKey]).length == 0) { delete notificationTypes[existingType.NotificationTypeKey]; } } // create default template if required - if(!defaultTemplateExists) { + if (!defaultTemplateExists) { await createNotificationType(defaultTemplate); } // create notification types that aren't there - for(const notificationTypeKey in notificationTypes) { - for(const notificationTypeVersion in notificationTypes[notificationTypeKey]) { + for (const notificationTypeKey in notificationTypes) { + for (const notificationTypeVersion in notificationTypes[notificationTypeKey]) { await createNotificationType(notificationTypes[notificationTypeKey][notificationTypeVersion]); } } @@ -305,5 +303,5 @@ async function processNotificationTypes(notificationTypesJSON) { module.exports = { createNotificationTypesMap, - processNotificationTypes -} \ No newline at end of file + processNotificationTypes, +}; diff --git a/package.json b/package.json index 835a1c0..7d13acb 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,13 @@ "lodash": "4.17.21" }, "devDependencies": { - "jest": "^29.6.4" + "jest": "^29.6.4", + "chai": "^4.3.10" }, "scripts": { "lint": "npx eslint .", - "test": "npx jest --silent" + "test": "npx jest", + "test-with-coverage": "npx jest --coverage" }, "cds": { "requires": { diff --git a/test/lib/content-deployment.test.js b/test/lib/content-deployment.test.js new file mode 100644 index 0000000..7fd6c34 --- /dev/null +++ b/test/lib/content-deployment.test.js @@ -0,0 +1,49 @@ +// import required modules and functions +const cds = require("@sap/cds"); +const { validateNotificationTypes, readFile } = require("../../lib/utils"); +const { processNotificationTypes } = require("../../lib/notificationTypes"); +const { setGlobalLogLevel } = require("@sap-cloud-sdk/util"); +const assert = require("chai"); + +jest.mock("@sap/cds"); +jest.mock("../../lib/utils"); +jest.mock("../../lib/notificationTypes"); +jest.mock("@sap-cloud-sdk/util"); + +const contentDeployment = require("../../lib/content-deployment"); + +describe("contentDeployment", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test("Given valid notification types | When Deploy is called | Then process is called", async () => { + setGlobalLogLevel.mockImplementation(() => undefined); + readFile.mockImplementation(() => []); + validateNotificationTypes.mockImplementation(() => true); + processNotificationTypes.mockImplementation(() => Promise.resolve()); + + await contentDeployment.deployNotificationTypes(); + + console.log(setGlobalLogLevel.mock.calls) + assert.expect(setGlobalLogLevel.mock.calls[0][0]).to.be.equal("error"); + assert.expect(readFile.mock.calls[0][0]).to.be.equal(cds.env?.requires?.notifications?.types); + assert.expect(validateNotificationTypes.mock.calls[0][0]).to.be.deep.equal([]); + assert.expect(processNotificationTypes.mock.calls[0][0]).to.be.deep.equal([]); + }); + + test("Given invalid notification types | When Deploy is called | Then process is called", async () => { + setGlobalLogLevel.mockImplementation(() => undefined); + readFile.mockImplementation(() => []); + validateNotificationTypes.mockImplementation(() => false); + processNotificationTypes.mockImplementation(() => Promise.resolve()); + + await contentDeployment.deployNotificationTypes(); + + console.log(setGlobalLogLevel.mock.calls) + assert.expect(setGlobalLogLevel.mock.calls[0][0]).to.be.equal("error"); + assert.expect(readFile.mock.calls[0][0]).to.be.equal(cds.env?.requires?.notifications?.types); + assert.expect(validateNotificationTypes.mock.calls[0][0]).to.be.deep.equal([]); + assert.expect(processNotificationTypes.mock.calls[0]).to.be.deep.equal(undefined); + }); +}); diff --git a/test/lib/notificationTypes.test.js b/test/lib/notificationTypes.test.js new file mode 100644 index 0000000..2f27cba --- /dev/null +++ b/test/lib/notificationTypes.test.js @@ -0,0 +1,891 @@ +const utils = require("../../lib/utils"); +const httpClient = require("@sap-cloud-sdk/http-client"); +const connectivity = require("@sap-cloud-sdk/connectivity"); +const notificationTypes = require("../../lib/notificationTypes"); +const assert = require("chai"); + +jest.mock("../../lib/utils"); +jest.mock("@sap-cloud-sdk/http-client"); +jest.mock("@sap-cloud-sdk/connectivity"); + +describe("Managing of Notification Types", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test("Given 2 New Notification Types and 0 Existing Notification Types | When process is called | Than Default and 2 New Notification Types are created", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(emptyResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.be.equal("get"); + + const createDefaultNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(createDefaultNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes"); + assert.expect(createDefaultNotificationType.method).to.be.equal("post"); + assert.expect(createDefaultNotificationType.data).to.be.deep.equal(defaultNotificationType); + + const createFirstNotificationType = httpClient.executeHttpRequest.mock.calls[2][1]; + assert.expect(createFirstNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes"); + assert.expect(createFirstNotificationType.method).to.be.equal("post"); + assert.expect(createFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(notificationTypeWithAllProperties)); + + const createSecondNotificationType = httpClient.executeHttpRequest.mock.calls[3][1]; + assert.expect(createSecondNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes"); + assert.expect(createSecondNotificationType.method).to.be.equal("post"); + assert + .expect(createSecondNotificationType.data) + .to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(notificationTypeWithoutVersion))); + + assert.expect(httpClient.executeHttpRequest.mock.calls[4]).to.be.equal(undefined); + }); + }); + + test("Given 2 New Notification Types and 2 Existing Notification Types (+ 1 from another app) and they are the same | When process is called | Than nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given 1 New Notification Types and 2 Existing Notification Types (+ 1 from another app) and they are the same | When process is called | Than One Notification Type is deleted", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const deleteSecondNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(deleteSecondNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); + assert.expect(deleteSecondNotificationType.method).to.be.equal("delete"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + }); + + test("Given 2 New Notification Types and 2 Existing Notification Types (+ 1 from another app) and they are changed | When process is called | Than notification types are updated", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const updatedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + updatedNotificationTypeWithAllProperties.Templates[0].Description = "New Description"; + const updatedNotificationTypeWithoutVersion = copy(notificationTypeWithoutVersion); + updatedNotificationTypeWithoutVersion.Templates[0].Description = "New Description"; + + notificationTypes + .processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(updatedNotificationTypeWithoutVersion)]) + .then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); + + const updateSecondNotificationType = httpClient.executeHttpRequest.mock.calls[2][1]; + assert + .expect(updateSecondNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); + assert.expect(updateSecondNotificationType.method).to.be.equal("patch"); + assert + .expect(updateSecondNotificationType.data) + .to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(updatedNotificationTypeWithoutVersion))); + + assert.expect(httpClient.executeHttpRequest.mock.calls[3]).to.be.equal(undefined); + }); + }); + + test("Given NType with additional Template | When process is called | Than notification type is updated", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const updatedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + updatedNotificationTypeWithAllProperties.Templates[1] = updatedNotificationTypeWithAllProperties.Templates[0]; + updatedNotificationTypeWithAllProperties.Templates[1].Language = "DE"; + + notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + }); + + test("Given NType with additional Actions | When process is called | Than notification type is updated", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const updatedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + updatedNotificationTypeWithAllProperties.Actions[1] = updatedNotificationTypeWithAllProperties.Actions[0]; + updatedNotificationTypeWithAllProperties.Actions[1].Language = "DE"; + + notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + }); + + test("Given NType with additional DeliveryChannels | When process is called | Than notification type is updated", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const updatedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + updatedNotificationTypeWithAllProperties.DeliveryChannels[1] = updatedNotificationTypeWithAllProperties.DeliveryChannels[0]; + updatedNotificationTypeWithAllProperties.DeliveryChannels[1].Type = "MOBILE"; + + notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + }); + + test("Given arrays with results | When process is called | Then nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + changedNotificationTypeWithAllProperties.Templates = { results: notificationTypeWithAllProperties.Templates }; + changedNotificationTypeWithAllProperties.Actions = { results: notificationTypeWithAllProperties.Actions }; + changedNotificationTypeWithAllProperties.DeliveryChannels = { results: notificationTypeWithAllProperties.DeliveryChannels }; + + notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given arrays with results | When process is called | Then nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + changedNotificationTypeWithAllProperties.IsGroupable = undefined; + notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given language in lower case | When process is called | Then nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + changedNotificationTypeWithAllProperties.Templates[0].Language = notificationTypeWithAllProperties.Templates[0].Language.toLowerCase(); + changedNotificationTypeWithAllProperties.Actions[0].Language = notificationTypeWithAllProperties.Actions[0].Language.toLowerCase(); + + notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given template language in lower case | When process is called | Then nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + changedNotificationTypeWithAllProperties.Templates[0].TemplateLanguage = + notificationTypeWithAllProperties.Templates[0].TemplateLanguage.toLowerCase(); + + notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given empty Templates, Actions and Delivery Channels in both new and old | When process is called | Then nothing is done", () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + notificationTypes.processNotificationTypes([copy(notificationTypeWithNullTemplatesActionsAndDeliveryChannels)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); + }); + }); + + test("Given that NType is different | When process is called | Then NType is updated", async () => { + utils.getNotificationDestination.mockReturnValue(undefined); + httpClient.executeHttpRequest.mockReturnValue(allExistingResponseBody); + connectivity.buildHeadersForDestination.mockReturnValue({}); + utils.getNotificationTypesKeyWithPrefix.mockImplementation((str) => testPrefix + "/" + str); + utils.getPrefix.mockReturnValue(testPrefix); + + var ntypeProperties = Object.entries(notificationTypeWithAllProperties); + for (var ntypeProperty of ntypeProperties) { + if (ntypeProperty[0] == "NotificationTypeKey" || ntypeProperty[0] == "NotificationTypeVersion") { + continue; + } + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + + console.log(ntypeProperty); + if (typeof ntypeProperty[1] === "string") { + changedNotificationTypeWithAllProperties[ntypeProperty[0]] = ntypeProperty[1] + " UPDATED"; + } else if (typeof ntypeProperty[1] === "boolean") { + changedNotificationTypeWithAllProperties[ntypeProperty[0]] = !ntypeProperty[1]; + } else if (typeof ntypeProperty[1] === "number") { + changedNotificationTypeWithAllProperties[ntypeProperty[0]] = ntypeProperty[1] + 1; + } else { + continue; + } + await notificationTypes + .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) + .then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + jest.clearAllMocks(); + } + + var templateProperties = Object.entries(notificationTypeWithAllProperties.Templates[0]); + for (var templateProperty of templateProperties) { + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + + if (typeof templateProperty[1] === "string") { + changedNotificationTypeWithAllProperties.Templates[0][templateProperty[0]] = templateProperty[1] + " UPDATED"; + } else if (typeof templateProperty[1] === "boolean") { + changedNotificationTypeWithAllProperties.Templates[0][templateProperty[0]] = !templateProperty[1]; + } else if (typeof templateProperty[1] === "number") { + changedNotificationTypeWithAllProperties.Templates[0][templateProperty[0]] = templateProperty[1] + 1; + } else { + continue; + } + await notificationTypes + .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) + .then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + jest.clearAllMocks(); + } + + var actionProperties = Object.entries(notificationTypeWithAllProperties.Actions[0]); + for (var actionProperty of actionProperties) { + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + + if (typeof actionProperty[1] === "string") { + changedNotificationTypeWithAllProperties.Actions[0][actionProperty[0]] = actionProperty[1] + " UPDATED"; + } else if (typeof actionProperty[1] === "boolean") { + changedNotificationTypeWithAllProperties.Actions[0][actionProperty[0]] = !actionProperty[1]; + } else if (typeof actionProperty[1] === "number") { + changedNotificationTypeWithAllProperties.Actions[0][actionProperty[0]] = actionProperty[1] + 1; + } else { + continue; + } + await notificationTypes + .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) + .then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + jest.clearAllMocks(); + } + + var deliveryChannelProperties = Object.entries(notificationTypeWithAllProperties.DeliveryChannels[0]); + for (var deliveryChannelProperty of deliveryChannelProperties) { + const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); + + if (typeof deliveryChannelProperty[1] === "string") { + changedNotificationTypeWithAllProperties.DeliveryChannels[0][deliveryChannelProperty[0]] = deliveryChannelProperty[1] + " UPDATED"; + } else if (typeof deliveryChannelProperty[1] === "boolean") { + changedNotificationTypeWithAllProperties.DeliveryChannels[0][deliveryChannelProperty[0]] = !deliveryChannelProperty[1]; + } else if (typeof deliveryChannelProperty[1] === "number") { + changedNotificationTypeWithAllProperties.DeliveryChannels[0][deliveryChannelProperty[0]] = deliveryChannelProperty[1] + 1; + } else { + continue; + } + await notificationTypes + .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) + .then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert + .expect(getAllNotificationTypesRequest.url) + .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert + .expect(updateFirstNotificationType.url) + .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); + jest.clearAllMocks(); + } + }); +}); + +function toNTypeWithPrefixedKey(ntype) { + var prefixedNtype = copy(ntype); + prefixedNtype.NotificationTypeKey = testPrefix + "/" + prefixedNtype.NotificationTypeKey; + return prefixedNtype; +} + +function toNTypeWithDefaultVersion(ntype) { + var ntypeWithVersion = copy(ntype); + ntypeWithVersion.NotificationTypeVersion = "1"; + return ntypeWithVersion; +} + +function copy(obj) { + return JSON.parse(JSON.stringify(obj)); +} + +const defaultNotificationType = { + NotificationTypeKey: "Default", + NotificationTypeVersion: "1", + Templates: [ + { + Language: "en", + Description: "Other Notifications", + TemplatePublic: "{{title}}", + TemplateSensitive: "{{title}}", + TemplateGrouped: "Other Notifications", + TemplateLanguage: "mustache", + Subtitle: "{{description}}", + }, + ], +}; + +const notificationTypeWithAllProperties = { + NotificationTypeKey: "notificationTypeWithAllProperties", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: [ + { + Language: "EN", + TemplatePublic: "TemplatePublic", + TemplateSensitive: "TemplateSensitive", + TemplateGrouped: "TemplateGrouped", + Description: "Description", + TemplateLanguage: "MUSTACHE", + Subtitle: "Subtitle", + EmailSubject: "EmailSubject", + EmailText: "EmailText", + EmailHtml: "EmailHtml", + }, + ], + Actions: [ + { + ActionId: "Accept", + Language: "EN", + ActionText: "Accept", + GroupActionText: "Accept All", + Nature: "POSITIVE", + }, + ], + DeliveryChannels: [ + { + Type: "WEB", + Enabled: true, + DefaultPreference: false, + EditablePreference: true, + }, + ], +}; + +const notificationTypeWithoutVersion = { + NotificationTypeKey: "notificationTypeWithoutVersion", + IsGroupable: true, + Templates: [ + { + Language: "EN", + TemplatePublic: "TemplatePublic", + TemplateSensitive: "TemplateSensitive", + TemplateGrouped: "TemplateGrouped", + Description: "Description", + TemplateLanguage: "MUSTACHE", + Subtitle: "Subtitle", + EmailSubject: "EmailSubject", + EmailText: "EmailText", + EmailHtml: "EmailHtml", + }, + ], + Actions: [ + { + ActionId: "Accept", + Language: "EN", + ActionText: "Accept", + GroupActionText: "Accept All", + Nature: "POSITIVE", + }, + ], + DeliveryChannels: [ + { + Type: "WEB", + Enabled: true, + DefaultPreference: false, + EditablePreference: true, + }, + ], +}; + +const notificationTypeWithNullTemplatesActionsAndDeliveryChannels = { + NotificationTypeKey: "notificationTypeWithAllProperties", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: null, + Actions: null, + DeliveryChannels: null, +}; + +const testPrefix = "test-prefix"; + +const emptyResponseBody = { data: { d: { results: [] } } }; + +const allExistingResponseBody = { + data: { + d: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", + NotificationTypeKey: "Default", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", + type: "com.SAP.OData.V2.NotificationTypeService.Template", + }, + NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", + Language: "EN", + TemplatePublic: "{{title}}", + TemplateSensitive: "{{title}}", + TemplateGrouped: "Other Notifications", + Description: "Other Notifications", + TemplateLanguage: "MUSTACHE", + Subtitle: "{{description}}", + EmailSubject: null, + EmailText: null, + EmailHtml: null, + }, + ], + }, + Actions: { + results: [], + }, + DeliveryChannels: { + results: [], + }, + }, + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", + NotificationTypeKey: "test-prefix/notificationTypeWithAllProperties", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8',Language='EN')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8',Language='EN')", + type: "com.SAP.OData.V2.NotificationTypeService.Template", + }, + NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", + Language: "EN", + TemplatePublic: "TemplatePublic", + TemplateSensitive: "TemplateSensitive", + TemplateGrouped: "TemplateGrouped", + Description: "Description", + TemplateLanguage: "MUSTACHE", + Subtitle: "Subtitle", + EmailSubject: "EmailSubject", + EmailText: "EmailText", + EmailHtml: "EmailHtml", + }, + ], + }, + Actions: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + type: "com.SAP.OData.V2.NotificationTypeService.Action", + }, + NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", + ActionId: "Accept", + ActionText: "Accept", + GroupActionText: "Accept All", + Language: "EN", + Nature: "POSITIVE", + }, + ], + }, + DeliveryChannels: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + }, + Type: "WEB", + Enabled: true, + DefaultPreference: false, + EditablePreference: true, + }, + ], + }, + }, + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", + NotificationTypeKey: "test-prefix-2/notificationTypeWithAllProperties", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad',Language='EN')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad',Language='EN')", + type: "com.SAP.OData.V2.NotificationTypeService.Template", + }, + NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", + Language: "EN", + TemplatePublic: "TemplatePublic", + TemplateSensitive: "TemplateSensitive", + TemplateGrouped: "TemplateGrouped", + Description: "Description", + TemplateLanguage: "MUSTACHE", + Subtitle: "Subtitle", + EmailSubject: "EmailSubject", + EmailText: "EmailText", + EmailHtml: "EmailHtml", + }, + ], + }, + Actions: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", + type: "com.SAP.OData.V2.NotificationTypeService.Action", + }, + NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", + ActionId: "Accept", + ActionText: "Accept", + GroupActionText: "Accept All", + Language: "EN", + Nature: "POSITIVE", + }, + ], + }, + DeliveryChannels: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + }, + Type: "WEB", + Enabled: true, + DefaultPreference: false, + EditablePreference: true, + }, + ], + }, + }, + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", + NotificationTypeKey: "test-prefix/notificationTypeWithoutVersion", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492',Language='EN')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492',Language='EN')", + type: "com.SAP.OData.V2.NotificationTypeService.Template", + }, + NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", + Language: "EN", + TemplatePublic: "TemplatePublic", + TemplateSensitive: "TemplateSensitive", + TemplateGrouped: "TemplateGrouped", + Description: "Description", + TemplateLanguage: "MUSTACHE", + Subtitle: "Subtitle", + EmailSubject: "EmailSubject", + EmailText: "EmailText", + EmailHtml: "EmailHtml", + }, + ], + }, + Actions: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492')", + type: "com.SAP.OData.V2.NotificationTypeService.Action", + }, + NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", + ActionId: "Accept", + ActionText: "Accept", + GroupActionText: "Accept All", + Language: "EN", + Nature: "POSITIVE", + }, + ], + }, + DeliveryChannels: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + }, + Type: "WEB", + Enabled: true, + DefaultPreference: false, + EditablePreference: true, + }, + ], + }, + }, + ], + }, + }, +}; + +const allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody = { + data: { + d: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", + NotificationTypeKey: "Default", + NotificationTypeVersion: "1", + IsGroupable: true, + Templates: { + results: [ + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", + type: "com.SAP.OData.V2.NotificationTypeService.Template", + }, + NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", + Language: "EN", + TemplatePublic: "{{title}}", + TemplateSensitive: "{{title}}", + TemplateGrouped: "Other Notifications", + Description: "Other Notifications", + TemplateLanguage: "MUSTACHE", + Subtitle: "{{description}}", + EmailSubject: null, + EmailText: null, + EmailHtml: null, + }, + ], + }, + Actions: { + results: null, + }, + DeliveryChannels: {}, + }, + { + __metadata: { + id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + }, + NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", + NotificationTypeKey: "test-prefix/notificationTypeWithAllProperties", + NotificationTypeVersion: "1", + IsGroupable: true, + }, + ], + }, + }, +}; From bc449d4e6a1f261d9c88ab7b590cb23c6822141c Mon Sep 17 00:00:00 2001 From: I339886 Date: Thu, 19 Oct 2023 10:36:18 +0300 Subject: [PATCH 2/3] Fix comments --- .prettierrc | 5 - .prettierrc.json | 6 + lib/notificationTypes.js | 44 ++- test/lib/content-deployment.test.js | 4 +- test/lib/notificationTypes.test.js | 399 ++++++++++++---------------- 5 files changed, 190 insertions(+), 268 deletions(-) delete mode 100644 .prettierrc create mode 100644 .prettierrc.json diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 8cf0cf3..0000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "tabWidth": 2, - "useTabs": false, - "printWidth": 200 -} \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..ef7d0a4 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "tabWidth": 2, + "useTabs": false, + "printWidth": 200, + "trailingComma" : "none" +} \ No newline at end of file diff --git a/lib/notificationTypes.js b/lib/notificationTypes.js index 012e63d..2e78ce3 100644 --- a/lib/notificationTypes.js +++ b/lib/notificationTypes.js @@ -16,9 +16,9 @@ const defaultTemplate = { TemplateSensitive: "{{title}}", TemplateGrouped: "Other Notifications", TemplateLanguage: "mustache", - Subtitle: "{{description}}", - }, - ], + Subtitle: "{{description}}" + } + ] }; function fromOdataArrayFormat(objectInArray) { @@ -62,7 +62,7 @@ async function getNotificationTypes() { const notificationDestination = await getNotificationDestination(); const response = await executeHttpRequest(notificationDestination, { url: `${NOTIFICATION_TYPES_API_ENDPOINT}/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels`, - method: "get", + method: "get" }); return response.data.d.results; } @@ -70,18 +70,16 @@ async function getNotificationTypes() { async function createNotificationType(notificationType) { const notificationDestination = await getNotificationDestination(); const csrfHeaders = await buildHeadersForDestination(notificationDestination, { - url: NOTIFICATION_TYPES_API_ENDPOINT, + url: NOTIFICATION_TYPES_API_ENDPOINT }); - console.log( - `Notification Type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion} was not found. Creating it...` - ); + console.log(`Notification Type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion} was not found. Creating it...`); const response = await executeHttpRequest(notificationDestination, { url: `${NOTIFICATION_TYPES_API_ENDPOINT}/NotificationTypes`, method: "post", data: notificationType, - headers: csrfHeaders, + headers: csrfHeaders }); return response.data.d; } @@ -89,18 +87,16 @@ async function createNotificationType(notificationType) { async function updateNotificationType(id, notificationType) { const notificationDestination = await getNotificationDestination(); const csrfHeaders = await buildHeadersForDestination(notificationDestination, { - url: NOTIFICATION_TYPES_API_ENDPOINT, + url: NOTIFICATION_TYPES_API_ENDPOINT }); - console.log( - `Detected change in notification type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion}. Updating it...` - ); + console.log(`Detected change in notification type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion}. Updating it...`); const response = await executeHttpRequest(notificationDestination, { url: `${NOTIFICATION_TYPES_API_ENDPOINT}/NotificationTypes(guid'${id}')`, method: "patch", data: notificationType, - headers: csrfHeaders, + headers: csrfHeaders }); return response.status; } @@ -108,17 +104,15 @@ async function updateNotificationType(id, notificationType) { async function deleteNotificationType(notificationType) { const notificationDestination = await getNotificationDestination(); const csrfHeaders = await buildHeadersForDestination(notificationDestination, { - url: NOTIFICATION_TYPES_API_ENDPOINT, + url: NOTIFICATION_TYPES_API_ENDPOINT }); - console.log( - `Notification Type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion} not present in the types file. Deleting it...` - ); + console.log(`Notification Type of key ${notificationType.NotificationTypeKey} and version ${notificationType.NotificationTypeVersion} not present in the types file. Deleting it...`); const response = await executeHttpRequest(notificationDestination, { url: `${NOTIFICATION_TYPES_API_ENDPOINT}/NotificationTypes(guid'${notificationType.NotificationTypeId}')`, method: "delete", - headers: csrfHeaders, + headers: csrfHeaders }); return response.status; } @@ -262,10 +256,7 @@ async function processNotificationTypes(notificationTypesJSON) { } // if the type isn't present in the JSON file, delete it - if ( - notificationTypes[existingType.NotificationTypeKey] === undefined || - notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] === undefined - ) { + if (notificationTypes[existingType.NotificationTypeKey] === undefined || notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] === undefined) { await deleteNotificationType(existingType); continue; } @@ -274,10 +265,7 @@ async function processNotificationTypes(notificationTypesJSON) { // if the type is there then verify if everything is same or not if (!isNotificationTypeEqual(existingType, newType)) { - await updateNotificationType( - existingType.NotificationTypeId, - notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion] - ); + await updateNotificationType(existingType.NotificationTypeId, notificationTypes[existingType.NotificationTypeKey][existingType.NotificationTypeVersion]); } else { console.log(`Notification Type of key ${existingType.NotificationTypeKey} and version ${existingType.NotificationTypeVersion} unchanged.`); } @@ -303,5 +291,5 @@ async function processNotificationTypes(notificationTypesJSON) { module.exports = { createNotificationTypesMap, - processNotificationTypes, + processNotificationTypes }; diff --git a/test/lib/content-deployment.test.js b/test/lib/content-deployment.test.js index 7fd6c34..d1bd469 100644 --- a/test/lib/content-deployment.test.js +++ b/test/lib/content-deployment.test.js @@ -25,7 +25,7 @@ describe("contentDeployment", () => { await contentDeployment.deployNotificationTypes(); - console.log(setGlobalLogLevel.mock.calls) + console.log(setGlobalLogLevel.mock.calls); assert.expect(setGlobalLogLevel.mock.calls[0][0]).to.be.equal("error"); assert.expect(readFile.mock.calls[0][0]).to.be.equal(cds.env?.requires?.notifications?.types); assert.expect(validateNotificationTypes.mock.calls[0][0]).to.be.deep.equal([]); @@ -40,7 +40,7 @@ describe("contentDeployment", () => { await contentDeployment.deployNotificationTypes(); - console.log(setGlobalLogLevel.mock.calls) + console.log(setGlobalLogLevel.mock.calls); assert.expect(setGlobalLogLevel.mock.calls[0][0]).to.be.equal("error"); assert.expect(readFile.mock.calls[0][0]).to.be.equal(cds.env?.requires?.notifications?.types); assert.expect(validateNotificationTypes.mock.calls[0][0]).to.be.deep.equal([]); diff --git a/test/lib/notificationTypes.test.js b/test/lib/notificationTypes.test.js index 2f27cba..cde5111 100644 --- a/test/lib/notificationTypes.test.js +++ b/test/lib/notificationTypes.test.js @@ -22,9 +22,7 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.be.equal("get"); const createDefaultNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; @@ -40,9 +38,7 @@ describe("Managing of Notification Types", () => { const createSecondNotificationType = httpClient.executeHttpRequest.mock.calls[3][1]; assert.expect(createSecondNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes"); assert.expect(createSecondNotificationType.method).to.be.equal("post"); - assert - .expect(createSecondNotificationType.data) - .to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(notificationTypeWithoutVersion))); + assert.expect(createSecondNotificationType.data).to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(notificationTypeWithoutVersion))); assert.expect(httpClient.executeHttpRequest.mock.calls[4]).to.be.equal(undefined); }); @@ -57,9 +53,7 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -75,15 +69,11 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(notificationTypeWithAllProperties)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); const deleteSecondNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(deleteSecondNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); + assert.expect(deleteSecondNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); assert.expect(deleteSecondNotificationType.method).to.be.equal("delete"); assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); @@ -102,33 +92,23 @@ describe("Managing of Notification Types", () => { const updatedNotificationTypeWithoutVersion = copy(notificationTypeWithoutVersion); updatedNotificationTypeWithoutVersion.Templates[0].Description = "New Description"; - notificationTypes - .processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(updatedNotificationTypeWithoutVersion)]) - .then(() => { - const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); - assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(updatedNotificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); - const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); - assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); - assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); - - const updateSecondNotificationType = httpClient.executeHttpRequest.mock.calls[2][1]; - assert - .expect(updateSecondNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); - assert.expect(updateSecondNotificationType.method).to.be.equal("patch"); - assert - .expect(updateSecondNotificationType.data) - .to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(updatedNotificationTypeWithoutVersion))); - - assert.expect(httpClient.executeHttpRequest.mock.calls[3]).to.be.equal(undefined); - }); + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(updateFirstNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); + + const updateSecondNotificationType = httpClient.executeHttpRequest.mock.calls[2][1]; + assert.expect(updateSecondNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')"); + assert.expect(updateSecondNotificationType.method).to.be.equal("patch"); + assert.expect(updateSecondNotificationType.data).to.be.deep.eql(toNTypeWithPrefixedKey(toNTypeWithDefaultVersion(updatedNotificationTypeWithoutVersion))); + + assert.expect(httpClient.executeHttpRequest.mock.calls[3]).to.be.equal(undefined); + }); }); test("Given NType with additional Template | When process is called | Than notification type is updated", () => { @@ -144,15 +124,11 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); @@ -173,15 +149,11 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); @@ -202,15 +174,11 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(updatedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.url).to.be.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); assert.expect(updateFirstNotificationType.method).to.be.equal("patch"); assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(updatedNotificationTypeWithAllProperties)); @@ -232,9 +200,7 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -252,9 +218,7 @@ describe("Managing of Notification Types", () => { changedNotificationTypeWithAllProperties.IsGroupable = undefined; notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -274,9 +238,7 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -291,14 +253,11 @@ describe("Managing of Notification Types", () => { utils.getPrefix.mockReturnValue(testPrefix); const changedNotificationTypeWithAllProperties = copy(notificationTypeWithAllProperties); - changedNotificationTypeWithAllProperties.Templates[0].TemplateLanguage = - notificationTypeWithAllProperties.Templates[0].TemplateLanguage.toLowerCase(); + changedNotificationTypeWithAllProperties.Templates[0].TemplateLanguage = notificationTypeWithAllProperties.Templates[0].TemplateLanguage.toLowerCase(); notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -314,9 +273,7 @@ describe("Managing of Notification Types", () => { notificationTypes.processNotificationTypes([copy(notificationTypeWithNullTemplatesActionsAndDeliveryChannels)]).then(() => { const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); assert.expect(httpClient.executeHttpRequest.mock.calls[1]).to.be.equal(undefined); @@ -347,24 +304,18 @@ describe("Managing of Notification Types", () => { } else { continue; } - await notificationTypes - .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) - .then(() => { - const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); - assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); - - const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); - assert.expect(updateFirstNotificationType.method).to.equal("patch"); - assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); - - assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); - }); + await notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(updateFirstNotificationType.url).to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); jest.clearAllMocks(); } @@ -381,24 +332,18 @@ describe("Managing of Notification Types", () => { } else { continue; } - await notificationTypes - .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) - .then(() => { - const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); - assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); - - const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); - assert.expect(updateFirstNotificationType.method).to.equal("patch"); - assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); - - assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); - }); + await notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(updateFirstNotificationType.url).to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); jest.clearAllMocks(); } @@ -415,24 +360,18 @@ describe("Managing of Notification Types", () => { } else { continue; } - await notificationTypes - .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) - .then(() => { - const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); - assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); - - const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); - assert.expect(updateFirstNotificationType.method).to.equal("patch"); - assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); - - assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); - }); + await notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(updateFirstNotificationType.url).to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); jest.clearAllMocks(); } @@ -449,24 +388,18 @@ describe("Managing of Notification Types", () => { } else { continue; } - await notificationTypes - .processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]) - .then(() => { - const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; - assert - .expect(getAllNotificationTypesRequest.url) - .to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); - assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); - - const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; - assert - .expect(updateFirstNotificationType.url) - .to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); - assert.expect(updateFirstNotificationType.method).to.equal("patch"); - assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); - - assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); - }); + await notificationTypes.processNotificationTypes([copy(changedNotificationTypeWithAllProperties), copy(notificationTypeWithoutVersion)]).then(() => { + const getAllNotificationTypesRequest = httpClient.executeHttpRequest.mock.calls[0][1]; + assert.expect(getAllNotificationTypesRequest.url).to.equal("v2/NotificationType.svc/NotificationTypes?$format=json&$expand=Templates,Actions,DeliveryChannels"); + assert.expect(getAllNotificationTypesRequest.method).to.equal("get"); + + const updateFirstNotificationType = httpClient.executeHttpRequest.mock.calls[1][1]; + assert.expect(updateFirstNotificationType.url).to.equal("v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')"); + assert.expect(updateFirstNotificationType.method).to.equal("patch"); + assert.expect(updateFirstNotificationType.data).to.be.deep.equal(toNTypeWithPrefixedKey(changedNotificationTypeWithAllProperties)); + + assert.expect(httpClient.executeHttpRequest.mock.calls[2]).to.be.equal(undefined); + }); jest.clearAllMocks(); } }); @@ -499,9 +432,9 @@ const defaultNotificationType = { TemplateSensitive: "{{title}}", TemplateGrouped: "Other Notifications", TemplateLanguage: "mustache", - Subtitle: "{{description}}", - }, - ], + Subtitle: "{{description}}" + } + ] }; const notificationTypeWithAllProperties = { @@ -519,8 +452,8 @@ const notificationTypeWithAllProperties = { Subtitle: "Subtitle", EmailSubject: "EmailSubject", EmailText: "EmailText", - EmailHtml: "EmailHtml", - }, + EmailHtml: "EmailHtml" + } ], Actions: [ { @@ -528,17 +461,17 @@ const notificationTypeWithAllProperties = { Language: "EN", ActionText: "Accept", GroupActionText: "Accept All", - Nature: "POSITIVE", - }, + Nature: "POSITIVE" + } ], DeliveryChannels: [ { Type: "WEB", Enabled: true, DefaultPreference: false, - EditablePreference: true, - }, - ], + EditablePreference: true + } + ] }; const notificationTypeWithoutVersion = { @@ -555,8 +488,8 @@ const notificationTypeWithoutVersion = { Subtitle: "Subtitle", EmailSubject: "EmailSubject", EmailText: "EmailText", - EmailHtml: "EmailHtml", - }, + EmailHtml: "EmailHtml" + } ], Actions: [ { @@ -564,17 +497,17 @@ const notificationTypeWithoutVersion = { Language: "EN", ActionText: "Accept", GroupActionText: "Accept All", - Nature: "POSITIVE", - }, + Nature: "POSITIVE" + } ], DeliveryChannels: [ { Type: "WEB", Enabled: true, DefaultPreference: false, - EditablePreference: true, - }, - ], + EditablePreference: true + } + ] }; const notificationTypeWithNullTemplatesActionsAndDeliveryChannels = { @@ -583,7 +516,7 @@ const notificationTypeWithNullTemplatesActionsAndDeliveryChannels = { IsGroupable: true, Templates: null, Actions: null, - DeliveryChannels: null, + DeliveryChannels: null }; const testPrefix = "test-prefix"; @@ -598,7 +531,7 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", NotificationTypeKey: "Default", @@ -610,7 +543,7 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", - type: "com.SAP.OData.V2.NotificationTypeService.Template", + type: "com.SAP.OData.V2.NotificationTypeService.Template" }, NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", Language: "EN", @@ -622,22 +555,22 @@ const allExistingResponseBody = { Subtitle: "{{description}}", EmailSubject: null, EmailText: null, - EmailHtml: null, - }, - ], + EmailHtml: null + } + ] }, Actions: { - results: [], + results: [] }, DeliveryChannels: { - results: [], - }, + results: [] + } }, { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", NotificationTypeKey: "test-prefix/notificationTypeWithAllProperties", @@ -649,7 +582,7 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8',Language='EN')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8',Language='EN')", - type: "com.SAP.OData.V2.NotificationTypeService.Template", + type: "com.SAP.OData.V2.NotificationTypeService.Template" }, NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", Language: "EN", @@ -661,9 +594,9 @@ const allExistingResponseBody = { Subtitle: "Subtitle", EmailSubject: "EmailSubject", EmailText: "EmailText", - EmailHtml: "EmailHtml", - }, - ], + EmailHtml: "EmailHtml" + } + ] }, Actions: { results: [ @@ -671,16 +604,16 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", - type: "com.SAP.OData.V2.NotificationTypeService.Action", + type: "com.SAP.OData.V2.NotificationTypeService.Action" }, NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", ActionId: "Accept", ActionText: "Accept", GroupActionText: "Accept All", Language: "EN", - Nature: "POSITIVE", - }, - ], + Nature: "POSITIVE" + } + ] }, DeliveryChannels: { results: [ @@ -688,21 +621,21 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", - type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel" }, Type: "WEB", Enabled: true, DefaultPreference: false, - EditablePreference: true, - }, - ], - }, + EditablePreference: true + } + ] + } }, { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", NotificationTypeKey: "test-prefix-2/notificationTypeWithAllProperties", @@ -714,7 +647,7 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad',Language='EN')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad',Language='EN')", - type: "com.SAP.OData.V2.NotificationTypeService.Template", + type: "com.SAP.OData.V2.NotificationTypeService.Template" }, NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", Language: "EN", @@ -726,9 +659,9 @@ const allExistingResponseBody = { Subtitle: "Subtitle", EmailSubject: "EmailSubject", EmailText: "EmailText", - EmailHtml: "EmailHtml", - }, - ], + EmailHtml: "EmailHtml" + } + ] }, Actions: { results: [ @@ -736,16 +669,16 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'5b641f19-7c05-404b-b9a3-f6326f8b23ad')", - type: "com.SAP.OData.V2.NotificationTypeService.Action", + type: "com.SAP.OData.V2.NotificationTypeService.Action" }, NotificationTypeId: "5b641f19-7c05-404b-b9a3-f6326f8b23ad", ActionId: "Accept", ActionText: "Accept", GroupActionText: "Accept All", Language: "EN", - Nature: "POSITIVE", - }, - ], + Nature: "POSITIVE" + } + ] }, DeliveryChannels: { results: [ @@ -753,21 +686,21 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", - type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel" }, Type: "WEB", Enabled: true, DefaultPreference: false, - EditablePreference: true, - }, - ], - }, + EditablePreference: true + } + ] + } }, { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'719d8f6a-1e07-4981-b2be-07197cec7492')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", NotificationTypeKey: "test-prefix/notificationTypeWithoutVersion", @@ -779,7 +712,7 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492',Language='EN')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492',Language='EN')", - type: "com.SAP.OData.V2.NotificationTypeService.Template", + type: "com.SAP.OData.V2.NotificationTypeService.Template" }, NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", Language: "EN", @@ -791,9 +724,9 @@ const allExistingResponseBody = { Subtitle: "Subtitle", EmailSubject: "EmailSubject", EmailText: "EmailText", - EmailHtml: "EmailHtml", - }, - ], + EmailHtml: "EmailHtml" + } + ] }, Actions: { results: [ @@ -801,16 +734,16 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Actions(ActionId='Accept',Language='EN',NotificationTypeId=guid'719d8f6a-1e07-4981-b2be-07197cec7492')", - type: "com.SAP.OData.V2.NotificationTypeService.Action", + type: "com.SAP.OData.V2.NotificationTypeService.Action" }, NotificationTypeId: "719d8f6a-1e07-4981-b2be-07197cec7492", ActionId: "Accept", ActionText: "Accept", GroupActionText: "Accept All", Language: "EN", - Nature: "POSITIVE", - }, - ], + Nature: "POSITIVE" + } + ] }, DeliveryChannels: { results: [ @@ -818,19 +751,19 @@ const allExistingResponseBody = { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/DeliveryChannels('WEB')", - type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel", + type: "com.SAP.OData.V2.NotificationTypeService.DeliveryChannel" }, Type: "WEB", Enabled: true, DefaultPreference: false, - EditablePreference: true, - }, - ], - }, - }, - ], - }, - }, + EditablePreference: true + } + ] + } + } + ] + } + } }; const allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody = { @@ -841,7 +774,7 @@ const allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody = __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'a6771115-42f4-4ac3-9c85-49a819927b9c')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", NotificationTypeKey: "Default", @@ -853,7 +786,7 @@ const allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody = __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/Templates(NotificationTypeId=guid'a6771115-42f4-4ac3-9c85-49a819927b9c',Language='EN')", - type: "com.SAP.OData.V2.NotificationTypeService.Template", + type: "com.SAP.OData.V2.NotificationTypeService.Template" }, NotificationTypeId: "a6771115-42f4-4ac3-9c85-49a819927b9c", Language: "EN", @@ -865,27 +798,27 @@ const allExistingWithUndefinedTemplatesActionsAndDeliveryChannelsResponseBody = Subtitle: "{{description}}", EmailSubject: null, EmailText: null, - EmailHtml: null, - }, - ], + EmailHtml: null + } + ] }, Actions: { - results: null, + results: null }, - DeliveryChannels: {}, + DeliveryChannels: {} }, { __metadata: { id: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", uri: "https://notifications.cfapps.eu12.hana.ondemand.com:443/v2/NotificationType.svc/NotificationTypes(guid'26f1fad0-de4c-4869-9b4e-62f445c8a7a8')", - type: "com.SAP.OData.V2.NotificationTypeService.NotificationType", + type: "com.SAP.OData.V2.NotificationTypeService.NotificationType" }, NotificationTypeId: "26f1fad0-de4c-4869-9b4e-62f445c8a7a8", NotificationTypeKey: "test-prefix/notificationTypeWithAllProperties", NotificationTypeVersion: "1", - IsGroupable: true, - }, - ], - }, - }, + IsGroupable: true + } + ] + } + } }; From ce35fb5ff4b155e178bb992bb9c33e6486215190 Mon Sep 17 00:00:00 2001 From: Anmol Binani Date: Mon, 23 Oct 2023 11:57:06 +0530 Subject: [PATCH 3/3] removing `cds` mocking from test --- test/lib/content-deployment.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/lib/content-deployment.test.js b/test/lib/content-deployment.test.js index d1bd469..8d093c4 100644 --- a/test/lib/content-deployment.test.js +++ b/test/lib/content-deployment.test.js @@ -5,7 +5,6 @@ const { processNotificationTypes } = require("../../lib/notificationTypes"); const { setGlobalLogLevel } = require("@sap-cloud-sdk/util"); const assert = require("chai"); -jest.mock("@sap/cds"); jest.mock("../../lib/utils"); jest.mock("../../lib/notificationTypes"); jest.mock("@sap-cloud-sdk/util");