Skip to content

Commit

Permalink
[Tech Debt] Do not run formatting action if no formats are set
Browse files Browse the repository at this point in the history
  • Loading branch information
levinmr committed Jan 3, 2025
1 parent 9cec046 commit 90b7603
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/actions/format_processed_analytics_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/actions/format_processed_analytics_data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 90b7603

Please sign in to comment.