Skip to content

Commit

Permalink
Use constant for max description length for register command
Browse files Browse the repository at this point in the history
  • Loading branch information
gregilo committed Feb 14, 2023
1 parent 4610f36 commit bd15abb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/cli/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const IS_TESTING =
argvStr.includes('jest') ||
(process.env.NODE_ENV || '').toLowerCase().startsWith('test');

const MAX_DESCRIPTION_LENGTH = 140;

module.exports = {
ANALYTICS_KEY,
ANALYTICS_MODES,
Expand All @@ -76,6 +78,7 @@ module.exports = {
ISSUES_URL,
LAMBDA_VERSION,
LEGACY_RUNNER_PACKAGE,
MAX_DESCRIPTION_LENGTH,
NODE_VERSION,
NODE_VERSION_CLI_REQUIRES,
PACKAGE_NAME,
Expand Down
13 changes: 8 additions & 5 deletions packages/cli/src/oclif/commands/register.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ZapierBaseCommand = require('../ZapierBaseCommand');
const { CURRENT_APP_FILE } = require('../../constants');
const { CURRENT_APP_FILE, MAX_DESCRIPTION_LENGTH } = require('../../constants');
const { buildFlags } = require('../buildFlags');
const { callAPI, writeLinkedAppConfig } = require('../../utils/api');

Expand All @@ -9,9 +9,12 @@ class RegisterCommand extends ZapierBaseCommand {
async perform() {
// Flag validation
this._validateEnumFlags();
if ('desc' in this.flags && this.flags.desc.length >= 140) {
if (
'desc' in this.flags &&
this.flags.desc.length >= MAX_DESCRIPTION_LENGTH
) {
throw new Error(
'Please provide a description that is 140 characters or less.'
`Please provide a description that is ${MAX_DESCRIPTION_LENGTH} characters or less.`
);
}

Expand Down Expand Up @@ -75,8 +78,8 @@ class RegisterCommand extends ZapierBaseCommand {
appMeta.description = this.flags.desc?.trim();
if (!appMeta.description) {
appMeta.description = await this.prompt(
'Please provide a sentence describing your app in 140 characters or less.',
{ required: true, charLimit: 140 }
`Please provide a sentence describing your app in ${MAX_DESCRIPTION_LENGTH} characters or less.`,
{ required: true, charLimit: MAX_DESCRIPTION_LENGTH }
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/tests/register.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const oclif = require('@oclif/test');
const constants = require('../constants');
const { BASE_ENDPOINT, MAX_DESCRIPTION_LENGTH } = require('../constants');
const registerFieldChoices = require('./fixtures/registerFieldChoices');

describe('RegisterCommand', () => {
Expand All @@ -14,15 +14,15 @@ describe('RegisterCommand', () => {
oclif
.expect(ctx.message)
.to.contain(
'Please provide a description that is 140 characters or less.'
`Please provide a description that is ${MAX_DESCRIPTION_LENGTH} characters or less.`
);
})
.it('zapier register should enforce character limit on desc flag');
});

describe('zapier register should validate enum fields that are passed in as flags', function () {
function getTestObj() {
return oclif.test.nock(constants.BASE_ENDPOINT, (mockApi) =>
return oclif.test.nock(BASE_ENDPOINT, (mockApi) =>
mockApi
.get('/api/platform/cli/apps/fields-choices')
.reply(200, registerFieldChoices)
Expand Down

0 comments on commit bd15abb

Please sign in to comment.