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();