Skip to content

Commit

Permalink
fix: add helper methods for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
devakone committed Nov 8, 2024
1 parent 9a703d1 commit d221441
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { mockTeamJoinEvent } from './mockTeamJoinEvent';
import { EnvelopedEvent, ReceiverEvent, SlackEventMiddlewareArgs, TeamJoinEvent } from "@slack/bolt";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const noopVoid = (..._args: any[]) => Promise.resolve();
// biome-ignore lint/suspicious/noExplicitAny: module overrides can be anything
export type Override = Record<string, Record<string, any>>;

Check warning on line 7 in src/test/helpers.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

Unexpected any. Specify a different type


interface DummyTeamJoinOverrides {
event?: TeamJoinEvent;
Expand Down Expand Up @@ -55,4 +59,28 @@ export function createDummyTeamJoinEventMiddlewareArgs(
},
ack: () => Promise.resolve(),
};
}

export function mergeOverrides(...overrides: Override[]): Override {
let currentOverrides: Override = {};
for (const override of overrides) {
currentOverrides = mergeObjProperties(currentOverrides, override);
}
return currentOverrides;
}

function mergeObjProperties(first: Override, second: Override): Override {
const merged: Override = {};
const props = Object.keys(first).concat(Object.keys(second));
for (const prop of props) {
if (second[prop] === undefined && first[prop] !== undefined) {
merged[prop] = first[prop];
} else if (first[prop] === undefined && second[prop] !== undefined) {
merged[prop] = second[prop];
} else {
// second always overwrites the first
merged[prop] = { ...first[prop], ...second[prop] };
}
}
return merged;
}

0 comments on commit d221441

Please sign in to comment.