Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make cancel action actually cancel even when there are validation errors #541

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

rossiam
Copy link
Collaborator

@rossiam rossiam commented Aug 23, 2023

  • Fixed cancel action to actually cancel even when validation errors exist.

Checklist

  • I have read the CONTRIBUTING document
  • Any required documentation has been added
  • My code follows the code style of this project (npm run lint produces no warnings/errors)
  • I have added tests to cover my changes

@changeset-bot
Copy link

changeset-bot bot commented Aug 23, 2023

🦋 Changeset detected

Latest commit: 6cfaaea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@smartthings/cli-lib Patch
@smartthings/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -11,7 +12,6 @@ import {
previewJSONAction,
previewYAMLAction,
} from './defs'
import { red } from 'chalk'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using our colors proxy module makes unit testing easier.

@@ -76,7 +77,7 @@ export const updateFromUserInput = async <T extends object>(command: SmartThings
name: 'action',
message: 'Choose an action.',
choices,
default: validationResult === true ? finishAction : editAction,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When working on unit tests (still in progress), I noticed there is no way to get to this point if validationResult is not true.

const propertyInputDefinition = inputDefsByProperty[propertyName]
if (!propertyInputDefinition) {
continue
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this code wasn't doing anything while I was working on unit tests.

const propertyInputDefinition = inputDefsByProperty[propertyName]
if (!propertyInputDefinition) {
continue
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this code wasn't doing anything while I was working on unit tests.

@@ -218,7 +214,7 @@ export function objectDef<T extends object>(name: string, inputDefsByProperty: I
const laterPropertyInputDefinition = inputDefsByProperty[propertyName]
const updateIfNeeded = laterPropertyInputDefinition.updateIfNeeded
if (updateIfNeeded) {
const laterPropertyValue = await updateIfNeeded(updated[propertyName], updatedPropertyName, [{ ...updated }, ...context])
const laterPropertyValue = await updateIfNeeded(updated[propertyName], action, [{ ...updated }, ...context])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing I noticed while working on the unit tests. The updatedPropertyName is fine for top-level properties (line 105) but for nested properties, it only tells us which object the nested property is in and not property name inside that object that is actually being edited.

A real-world example of this is the clientName definition on line 58 of the apps:create command (packages/cli/src/commands/apps/create.ts). Before this fix, it would pass just oauth but after this it will pass oauth.clientName.

(There is currently no code that uses this so the difference doesn't matter ATM but we should be passing on everything.)

input3: 'Item Value 3',
}])
})
it('calls `updateIfNeeded` on subsequent definitions after rolled-up property has been updated', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a line break before the beginning of this test

@rossiam rossiam merged commit b865ad8 into SmartThingsCommunity:main Aug 29, 2023
4 checks passed
@rossiam rossiam deleted the cancel-fix branch August 29, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants