Skip to content

Commit

Permalink
handle case where scriptingSource is an empty string (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid committed Jan 27, 2022
1 parent 183dd04 commit 8a4f334
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

- At runtime, a developer's `perform` function is invoked with the following signature: `perform(z, bundle)`.
- The `z` object is a collection of functions used commonly by developers and is defined in `core/src/tools/create-lambda-handler.js`
- Its functions are either Zapier-specific (such as `z.cursor` and `z.dehyrate`) or wrappers around common JS functionality (such as `z.JSON.parse` and `z.console.log`) with better error handling or extra logging
- Its functions are either Zapier-specific (such as `z.cursor` and `z.dehydrate`) or wrappers around common JS functionality (such as `z.JSON.parse` and `z.console.log`) with better error handling or extra logging
- Each of those functions has its own file in `core/src/tools`
- The most important method is probably `z.request` (from `core/src/tools/create-app-request-client.js`), which devs use to make external requests. This is different from normal http requests in a number of ways:
- there are `beforeRequest` and `afterResponse` functions that run before and after the request. They can be declared by the developer or inserted automatically based on the authentication type.
Expand Down
11 changes: 7 additions & 4 deletions packages/core/src/tools/create-legacy-scripting-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const semver = require('semver');
const createLegacyScriptingRunner = (z, input) => {
const app = _.get(input, '_zapier.app');

let source =
_.get(app, 'legacy.scriptingSource') || app.legacyScriptingSource;
// once we have node 14 everywhere, this can be:
// let source = _.get(app, 'legacy.scriptingSource') ?? app.legacyScriptingSource;
let source = _.get(app, 'legacy.scriptingSource');
source = source === undefined ? app.legacyScriptingSource : source;

if (source === undefined) {
// Don't initialize z.legacyScripting for a pure CLI app
return null;
Expand All @@ -26,8 +29,8 @@ const createLegacyScriptingRunner = (z, input) => {
let LegacyScriptingRunner, version;
try {
LegacyScriptingRunner = require('zapier-platform-legacy-scripting-runner');
version = require('zapier-platform-legacy-scripting-runner/package.json')
.version;
version =
require('zapier-platform-legacy-scripting-runner/package.json').version;
} catch (e) {
// Find it in cwd, in case we're developing legacy-scripting-runner itself
const cwd = process.cwd();
Expand Down
21 changes: 21 additions & 0 deletions packages/legacy-scripting-runner/test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,27 @@ describe('Integration Test', () => {
});
});

it('scriptingless, empty scripting string should be fine', () => {
if (!nock.isActive()) {
nock.activate();
}
// Mock the response with a string 'null'
nock(AUTH_JSON_SERVER_URL).get('/movies').reply(200, '[]');

const appDef = _.cloneDeep(appDefinition);
appDef.legacy.scriptingSource = ''; // rare case, but it's happened
const _compiledApp = schemaTools.prepareApp(appDef);
const _app = createApp(appDef);

const input = createTestInput(
_compiledApp,
'triggers.movie.operation.perform'
);
return _app(input).then((output) => {
should.deepEqual(output.results, []);
});
});

it('scriptingless, empty auth mapping', () => {
const appDef = _.cloneDeep(appDefinition);
appDef.legacy.scriptingSource = appDef.legacy.scriptingSource.replace(
Expand Down

0 comments on commit 8a4f334

Please sign in to comment.