Skip to content

Commit

Permalink
feat(modules): Handle optional global.$activeModuleApps to mock act…
Browse files Browse the repository at this point in the history
…ive apps for modules

May be used in production but better suited to test apps locally [#237]
  • Loading branch information
leomp12 committed Mar 22, 2024
1 parent 235e83b commit a1f5df1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/modules/src/firebase/handle-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ import {
} from './ajv';
import callAppModule from './call-app-module';

declare global {
// eslint-disable-next-line
var $activeModuleApps: undefined | Array<Partial<Applications> & {
_id: Applications['_id'],
state?: 'active',
app_id: Applications['app_id'],
version: Applications['version'],
modules: Exclude<Applications['modules'], undefined>,
data: Applications['data'],
hidden_data: Applications['hidden_data'],
}>;
}

const ajvAppsResponse = addFormats(new Ajv({ ...ajvOptions, allErrors: true }));

// Cache apps list and no params modules results
Expand Down Expand Up @@ -59,7 +72,12 @@ async function runModule(
}

let appsList: Partial<Applications>[];
if (canCache && appsCache[cacheKey]) {
const mockedModApps = global.$activeModuleApps?.filter(({ modules }) => {
return modules[modName as 'list_payments']?.enabled;
});
if (mockedModApps?.length) {
appsList = mockedModApps;
} else if (canCache && appsCache[cacheKey]) {
appsList = appsCache[cacheKey];
} else {
try {
Expand Down

0 comments on commit a1f5df1

Please sign in to comment.