[feat] add variations create#152
Conversation
| } else if (variable.type === 'Number') { | ||
| variablePrompts.push(variableValueNumberPrompt(variable.key)) | ||
| } else { | ||
| variablePrompts.push(variableValueStringPrompt(variable.key)) |
There was a problem hiding this comment.
How are JSON variables going to be handled here? Is the idea that they will be treated as strings?
There was a problem hiding this comment.
oh yeah I assumed that they were stringified and sent to the api that way? let me test it out
There was a problem hiding this comment.
I added a prompt for JSON variables. It looks like inquirer only returns string/numbers and not JSON objects? So it validates the input by doing JSON.parse, but the command that calls the prompt has to call JSON.parse on the returned string "answer" again.
There was a problem hiding this comment.
oh, so if the user passes in an invalid json object the inquirer prompt will catch that?
There was a problem hiding this comment.
I was going to say that we may need to wrap the JSON.parse in a try/catch to handle for that, but if we can be sure that whatever comes back from the prompt is JSON parsable, then this should be fine
There was a problem hiding this comment.
yup there's a validate function that checks if the input from the prompt is parsable: https://github.com/DevCycleHQ/cli/pull/152/files#diff-7d50853832a5eeba42906784297b6eb9dd035d5aa8d3352161add7053b6d58ecR87-R101
da1b347 to
80db5ad
Compare
| import { Variation } from './schemas' | ||
| import { Feature, Variation } from './schemas' | ||
|
|
||
| export class CreateVariationParams { |
There was a problem hiding this comment.
I believe this class is no longer required given some work @emmawillis has been doing - zodios is supposed to auto-pickup all these validation decorators. But might need to check with her, or possibly she can update this on her ticket.
There was a problem hiding this comment.
ah yeah i haven't gotten to that yet unfortunately, so we're still using plainToClass to parse the input and the create params classes are still temporarily needed. whenever we get to this ticket https://taplytics.atlassian.net/browse/DVC-7720 we'll switch the input validation to zod and then we'll be able to scrap all the Create___Params classes
80db5ad to
4cad95e
Compare
TODO: add some tests! -- tested manually, will create ticket for tests
refactor cleanup command to use updated variable values prompt, which returns the correct types nowvariableValueStringPrompt, as the types are handled insrc/utils/refactor/RefactorEngine.tsJSON variable: