From 90b7603ef89fdb8e9229ef837c9b3b84fbd87136 Mon Sep 17 00:00:00 2001 From: Michael Levin Date: Fri, 3 Jan 2025 13:42:14 -0500 Subject: [PATCH] [Tech Debt] Do not run formatting action if no formats are set --- .../format_processed_analytics_data.js | 10 +++++++ .../format_processed_analytics_data.test.js | 30 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/actions/format_processed_analytics_data.js b/src/actions/format_processed_analytics_data.js index 8df8f38a..733aa9e8 100644 --- a/src/actions/format_processed_analytics_data.js +++ b/src/actions/format_processed_analytics_data.js @@ -5,6 +5,16 @@ const ResultFormatter = require("../process_results/result_formatter"); * Chain of responsibility action for formatting processed analytics data */ class FormatProcessedAnalyticsData extends Action { + /** + * @param {import('../report_processing_context')} context the context for the + * action chain. + * @returns {boolean} true if the application config is set to format + * processed analytics data. + */ + handles(context) { + return context.appConfig.formats.length > 0; + } + /** * Takes the processed analytics data from the context and changes the format * to JSON or CSV based on application and report config options. Writes the diff --git a/test/actions/format_processed_analytics_data.test.js b/test/actions/format_processed_analytics_data.test.js index 0dbe7386..465db03c 100644 --- a/test/actions/format_processed_analytics_data.test.js +++ b/test/actions/format_processed_analytics_data.test.js @@ -14,6 +14,36 @@ describe("FormatProcessedAnalyticsData", () => { let context; let subject; + describe(".handles", () => { + beforeEach(() => { + subject = new FormatProcessedAnalyticsData(); + }); + + describe("when appConfig.formats has values", () => { + beforeEach(() => { + context = { + appConfig: { formats: ["json"] }, + }; + }); + + it("returns true", () => { + expect(subject.handles(context)).to.equal(true); + }); + }); + + describe("when appConfig.formats does not have values", () => { + beforeEach(() => { + context = { + appConfig: { formats: [] }, + }; + }); + + it("returns false", () => { + expect(subject.handles(context)).to.equal(false); + }); + }); + }); + describe(".executeStrategy", () => { const debugLogSpy = sinon.spy();