Skip to content

refactor: update user-query functions to use new inquirer#760

Merged
rossiam merged 1 commit intoSmartThingsCommunity:yargsfrom
rossiam:inquirer-update-pt1
Jun 9, 2025
Merged

refactor: update user-query functions to use new inquirer#760
rossiam merged 1 commit intoSmartThingsCommunity:yargsfrom
rossiam:inquirer-update-pt1

Conversation

@rossiam
Copy link
Copy Markdown
Collaborator

@rossiam rossiam commented Jun 5, 2025

  • added new inquirer dependency
  • updated user-query module
    • use new inquirer
    • gave functions better names
    • made their APIs more consistent with each other
    • custom validators for number and integer functions now take number | undefined instead of string and the query function does the number validation before passing the input on to custom validator as a number
  • fixed issue that urlValidateFn was allowing URLs missing a / like https:/invalid-url.com

The old inquirer is still included. A second PR will update the rest of the code and remove it entirely.

@rossiam rossiam requested a review from a team June 5, 2025 21:14
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 5, 2025

⚠️ No Changeset found

Latest commit: eb82ffd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@rossiam rossiam force-pushed the inquirer-update-pt1 branch from ec5fc1b to 8fb6b29 Compare June 6, 2025 14:15
Comment thread src/__tests__/lib/validate-util.test.ts Outdated
})

it.each([5, 10, -5, 3.141592653])('rejects %s', input => {
expect(numberValidateFn()(input)).toBe(true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test could use another look--seems like it was meant to be an update of the previous test but didn't quite get finished.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops, both of these tests were from when this function validated strings rather than numbers. I've removed them.

const minLength = await optionalIntegerInput('Optional minimum length.', { validate: numberValidateFn({ min: 0 }) })
const maxLength = await optionalIntegerInput(
'Optional maximum length.',
{ validate: numberValidateFn({ min: minLength || 1 }) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is an optional integer, should the alternate minLength be 0 rather than 1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a bit complicated but I did deliberately use 1. It seems sensible to me that a user might want a string attribute that has a fixed length (minLength and maxLength are the same value) if it's 1 or more which is why we use minLength if one is set but having a string with a min and max length both set to zero seems wrong.

Comment thread src/__tests__/lib/user-query.test.ts Outdated

it.each(['input value', '7'])('returns input value unchanged when not empty', value => {
expect(numberTransformer(value, { value }, { isFinal: true })).toBe(value)
it.each(['input value', '7'])('returns input value %s unchanged when', value => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"unchanged when"....? 'not empty' was removed here, perhaps by mistake?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops, fixed. It was correct to remove not empty but it was not correct to include final instead. 😄 My excuse is that I must have been interrupted.

@rossiam rossiam force-pushed the inquirer-update-pt1 branch from 8fb6b29 to eb82ffd Compare June 9, 2025 15:17
@rossiam rossiam merged commit 6f4b34d into SmartThingsCommunity:yargs Jun 9, 2025
4 checks passed
@rossiam rossiam deleted the inquirer-update-pt1 branch June 9, 2025 15:30
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