Skip to content

Commit

Permalink
update logic to remove extra property
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid committed Jun 8, 2021
1 parent 5a53c4c commit 67b48f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
5 changes: 1 addition & 4 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export const createAppTester: (
options?: { customStoreKey?: string }
) => <T, B extends Bundle>(
func: (z: ZObject, bundle: B) => T | Promise<T>,
bundle?: Partial<B>, // partial so we don't have to make a full bundle in tests
opts?: {
adHoc?: boolean;
}
bundle?: Partial<B> // partial so we don't have to make a full bundle in tests
) => Promise<T>; // appTester always returns a promise

// internal only
Expand Down
23 changes: 15 additions & 8 deletions packages/core/src/tools/create-app-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const createLambdaHandler = require('./create-lambda-handler');
const resolveMethodPath = require('./resolve-method-path');
const ZapierPromise = require('./promise');
const { get } = require('lodash');
const { get, isFunction } = require('lodash');
const { genId } = require('./data');

// this is (annoyingly) mirrored in cli/api_base, so that test functions only
Expand Down Expand Up @@ -52,15 +52,22 @@ const createAppTester = (appRaw, { customStoreKey } = {}) => {

const randomSeed = genId();

return (methodOrFunc, bundle, { adHoc } = {}) => {
return (methodOrFunc, bundle) => {
bundle = bundle || {};

let method;
if (adHoc) {
appRaw._testRequest = (z, bundle) => methodOrFunc(z, bundle);
method = resolveMethodPath(appRaw, appRaw._testRequest);
} else {
method = resolveMethodPath(appRaw, methodOrFunc);
let method = resolveMethodPath(appRaw, methodOrFunc, false);
if (!method) {
if (isFunction(methodOrFunc)) {
// definitely have a function but didn't find it on the app; it's an adhoc
appRaw._testRequest = (z, bundle) => methodOrFunc(z, bundle);
method = resolveMethodPath(appRaw, appRaw._testRequest);
} else {
throw new Error(
`Unable to find the following on your App instance: ${JSON.stringify(
methodOrFunc
)}`
);
}
}

const storeKey = shouldPaginate(appRaw, method)
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tools/resolve-method-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const isRequestMethod = (needle) =>
resolveMethodPath(app, app.resources.contact.get.operation.perform)
*/
const resolveMethodPath = (app, needle) => {
const resolveMethodPath = (app, needle, explodeIfMissing = true) => {
// temporary warning for all those with old code
if (typeof needle === 'string') {
console.log(
Expand All @@ -39,7 +39,7 @@ const resolveMethodPath = (app, needle) => {
const path =
dataTools.memoizedFindMapDeep(app, needle) ||
dataTools.memoizedFindMapDeep(app, needle, _.isEqual);
if (!path) {
if (!path && explodeIfMissing) {
throw new Error(
'We could not find your function/array/object anywhere on your App definition.'
);
Expand Down

0 comments on commit 67b48f6

Please sign in to comment.