From 1edf32be893f7442d0c6ad2a292c00bfcf1e66bd Mon Sep 17 00:00:00 2001 From: Nina Ciocanu Date: Tue, 12 Nov 2024 14:25:34 +0200 Subject: [PATCH] cleanup unused files --- .../Personalization/createActionsProvider.js | 85 ---------------- .../Personalization/createPreprocessors.js | 20 ---- .../createActionsProvider.spec.js | 99 ------------------- .../createPreprocessors.spec.js | 46 --------- 4 files changed, 250 deletions(-) delete mode 100644 src/components/Personalization/createActionsProvider.js delete mode 100644 src/components/Personalization/createPreprocessors.js delete mode 100644 test/unit/specs/components/Personalization/createActionsProvider.spec.js delete mode 100644 test/unit/specs/components/Personalization/createPreprocessors.spec.js diff --git a/src/components/Personalization/createActionsProvider.js b/src/components/Personalization/createActionsProvider.js deleted file mode 100644 index b8a84800d..000000000 --- a/src/components/Personalization/createActionsProvider.js +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -import createPreprocessors from "./createPreprocessors.js"; - -export default ({ modules, preprocessors = createPreprocessors(), logger }) => { - const logActionError = (action, error) => { - if (logger.enabled) { - const details = JSON.stringify(action); - const { message, stack } = error; - const errorMessage = `Failed to execute action ${details}. ${message} ${ - stack ? `\n ${stack}` : "" - }`; - - logger.warn(errorMessage); - } - }; - - const logActionCompleted = (action) => { - if (logger.enabled) { - const details = JSON.stringify(action); - - logger.info(`Action ${details} executed.`); - } - }; - - const getExecuteAction = (schema, type) => { - if (!modules[schema] || !modules[schema][type]) { - return () => - Promise.reject( - new Error(`Action "${type}" not found for schema "${schema}"`), - ); - } - - return modules[schema][type]; - }; - - const applyPreprocessors = (action) => { - const { schema } = action; - - const preprocessorsList = preprocessors[schema]; - - if ( - !schema || - !(preprocessorsList instanceof Array) || - preprocessorsList.length === 0 - ) { - return action; - } - - return preprocessorsList.reduce( - (processed, fn) => ({ ...processed, ...fn(processed) }), - action, - ); - }; - - const executeAction = (action) => { - const processedAction = applyPreprocessors(action); - const { type, schema } = processedAction; - - const execute = getExecuteAction(schema, type); - - return execute(processedAction) - .then((result) => { - logActionCompleted(processedAction); - return result; - }) - .catch((error) => { - logActionError(processedAction, error); - throw error; - }); - }; - - return { - executeAction, - }; -}; diff --git a/src/components/Personalization/createPreprocessors.js b/src/components/Personalization/createPreprocessors.js deleted file mode 100644 index dcfe7f80b..000000000 --- a/src/components/Personalization/createPreprocessors.js +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -import { DOM_ACTION } from "../../constants/schema.js"; -import remapHeadOffers from "./dom-actions/remapHeadOffers.js"; -import remapCustomCodeOffers from "./dom-actions/remapCustomCodeOffers.js"; - -export default () => { - return { - [DOM_ACTION]: [remapHeadOffers, remapCustomCodeOffers], - }; -}; diff --git a/test/unit/specs/components/Personalization/createActionsProvider.spec.js b/test/unit/specs/components/Personalization/createActionsProvider.spec.js deleted file mode 100644 index d736a11db..000000000 --- a/test/unit/specs/components/Personalization/createActionsProvider.spec.js +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -import createActionsProvider from "../../../../../src/components/Personalization/createActionsProvider.js"; - -describe("createActionsProvider", () => { - let actionsProvider; - let logger; - - beforeEach(() => { - logger = jasmine.createSpyObj("logger", ["warn", "error", "info"]); - logger.enabled = true; - - actionsProvider = createActionsProvider({ - modules: { - something: { - eat: () => Promise.resolve("yum"), - sleep: () => Promise.resolve(), - exercise: () => Promise.resolve(), - }, - }, - preprocessors: { - something: [(action) => action], - superfluous: [ - (action) => action, - (action) => action, - (action) => action, - ], - }, - logger, - }); - }); - - it("executes appropriate action", (done) => { - const actionDetails = { - schema: "something", - type: "eat", - itWorked: true, - }; - - actionsProvider.executeAction(actionDetails).then((result) => { - expect(result).toEqual("yum"); - expect(logger.info).toHaveBeenCalledOnceWith( - jasmine.stringContaining( - `Action ${JSON.stringify(actionDetails)} executed.`, - ), - ); - done(); - }); - }); - - it("throws error if missing schema", (done) => { - const actionDetails = { - schema: "hidden-valley", - type: "truckee", - itWorked: true, - }; - - actionsProvider.executeAction(actionDetails).catch((error) => { - expect(error.message).toEqual( - `Action "truckee" not found for schema "hidden-valley"`, - ); - expect(logger.warn).toHaveBeenCalledOnceWith( - jasmine.stringContaining( - `Failed to execute action ${JSON.stringify(actionDetails)}.`, - ), - ); - done(); - }); - }); - - it("throws error if missing action", (done) => { - const actionDetails = { - schema: "something", - type: "truckee", - itWorked: true, - }; - - actionsProvider.executeAction(actionDetails).catch((error) => { - expect(error.message).toEqual( - `Action "truckee" not found for schema "something"`, - ); - expect(logger.warn).toHaveBeenCalledOnceWith( - jasmine.stringContaining( - `Failed to execute action ${JSON.stringify(actionDetails)}.`, - ), - ); - done(); - }); - }); -}); diff --git a/test/unit/specs/components/Personalization/createPreprocessors.spec.js b/test/unit/specs/components/Personalization/createPreprocessors.spec.js deleted file mode 100644 index cd9bc806c..000000000 --- a/test/unit/specs/components/Personalization/createPreprocessors.spec.js +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -import { DOM_ACTION } from "../../../../../src/constants/schema.js"; -import createPreprocessors from "../../../../../src/components/Personalization/createPreprocessors.js"; - -describe("Personalization::createPreprocessors", () => { - it("has dom-action preprocessors", () => { - const preprocessors = createPreprocessors(); - - expect(preprocessors).toEqual({ - [DOM_ACTION]: jasmine.any(Array), - }); - - expect(preprocessors[DOM_ACTION].length).toEqual(2); - - preprocessors[DOM_ACTION].forEach((preprocessor) => { - expect(preprocessor).toEqual(jasmine.any(Function)); - }); - }); - - it("is structured correctly", () => { - const preprocessors = createPreprocessors(); - - Object.keys(preprocessors).forEach((key) => { - expect( - key.startsWith("https://ns.adobe.com/personalization/"), - ).toBeTrue(); - }); - - Object.values(preprocessors).forEach((list) => { - expect(list instanceof Array).toBeTrue(); - list.forEach((preprocessor) => { - expect(preprocessor).toEqual(jasmine.any(Function)); - }); - }); - }); -});