Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
zapier convert: Add test for renderPackageJson and fix escaping packa…
Browse files Browse the repository at this point in the history
…ge description
  • Loading branch information
eliangcs committed Feb 20, 2018
1 parent d452dd6 commit 6d8014e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/tests/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,21 @@ const getSessionKey = (z, bundle) => {
});
});
});

describe('render package.json', () => {
it('should render track info', () => {
const wbDef = {
general: {
title: 'Example App',
description: 'It\'s an "example" app.',
app_id: 1234
}
};
return convert.renderPackageJson(wbDef).then(content => {
const pkg = JSON.parse(content);
pkg.zapier.convertedFromAppID.should.eql(1234);
pkg.zapier.convertedByCLIVersion.should.be.ok();
});
});
});
});
18 changes: 11 additions & 7 deletions src/utils/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const stripComments = require('strip-comments');
const { camelCase, snakeCase } = require('./misc');
const { copyFile, readFile, writeFile, ensureDir } = require('./files');
const { printStarting, printDone } = require('./display');
const CLI_VERSION = require('../../package.json').version;
const { PACKAGE_VERSION } = require('../constants');

const TEMPLATE_DIR = path.join(__dirname, '../../scaffold/convert');
const ZAPIER_LEGACY_SCRIPTING_RUNNER_VERSION = '1.0.0';
Expand Down Expand Up @@ -935,18 +935,21 @@ const writeIndex = (legacyApp, newAppDir) => {
const renderPackageJson = legacyApp => {
const { needsLegacyScriptingRunner } = getMetaData(legacyApp);

// Not using escapeSpecialChars because we don't want to escape single quotes (not allowed in JSON)
const description = legacyApp.general.description
.replace(/\n/g, '\\n')
.replace(/"/g, '\\"');

const templateContext = {
NAME: _.kebabCase(legacyApp.general.title),
DESCRIPTION: escapeSpecialChars(legacyApp.general.description),
DESCRIPTION: description,
APP_ID: legacyApp.general.app_id,
CLI_VERSION: CLI_VERSION
CLI_VERSION: PACKAGE_VERSION
};

const zapierCoreVersion = require('../../package.json').version;

const dependencies = [];

dependencies.push(`"zapier-platform-core": "${zapierCoreVersion}"`);
dependencies.push(`"zapier-platform-core": "${PACKAGE_VERSION}"`);

if (needsLegacyScriptingRunner) {
// TODO: Make conditional
Expand Down Expand Up @@ -1071,5 +1074,6 @@ module.exports = {
getHeader,
getBeforeRequests,
getAfterResponses,
hasAuth
hasAuth,
renderPackageJson
};

0 comments on commit 6d8014e

Please sign in to comment.