Skip to content

Commit

Permalink
fix: [ACNA-1269] Added a more friendly message when action name is in…
Browse files Browse the repository at this point in the history
…valid. (#171)
  • Loading branch information
florind-ens authored Oct 6, 2021
1 parent 2f7f538 commit a781e59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ActionGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ class ActionGenerator extends Generator {
if (valid.test(input)) {
return true
}
return `'${input}' is not a valid action name, please use a name that matches "^[a-zA-Z0-9][a-zA-Z0-9-]{2,31}$"`
return `'${input}' is not a valid action name, please make sure that:
The name has at least 3 characters or less than 33 characters.
The first character is an alphanumeric character.
The subsequent characters are alphanumeric.
The last character isn't a space.
Note: characters can only be split by '-'.
`
}
}
])
Expand Down
16 changes: 16 additions & 0 deletions test/lib/ActionGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ describe('implementation', () => {
expect(validate('abc123456789012345678901234567890')).not.toEqual(true)
})

test('rejects invalid name with a message`', async () => {
const invalidName = 'a'
const invalidNameMessage = `'${invalidName}' is not a valid action name, please make sure that:
The name has at least 3 characters or less than 33 characters.
The first character is an alphanumeric character.
The subsequent characters are alphanumeric.
The last character isn't a space.
Note: characters can only be split by '-'.
`
promptSpy.mockReturnValue({ actionName: 'fake' })
await actionGenerator.promptForActionName()
expect(promptSpy.mock.calls[0][0][0].validate).toBeInstanceOf(Function)
const validate = promptSpy.mock.calls[0][0][0].validate
expect(validate(invalidName)).toEqual(invalidNameMessage)
})

test('returns new default name in case of conflict', async () => {
utils.readYAMLConfig.mockReturnValue({
runtimeManifest: {
Expand Down

0 comments on commit a781e59

Please sign in to comment.