Skip to content

Commit

Permalink
fix: Fix metadata template update when adding multiple options to enum (
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski authored Dec 20, 2022
1 parent d94ab35 commit 8779eec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/commands/metadata-templates/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const FLAG_HANDLERS = Object.freeze({
fieldKey: value.input,
};
},
option(value, currentOp/* , ops*/) {
option(value, currentOp, ops) {

if (!currentOp) {
throw new BoxCLIError('Unexpected --option flag outside of option-related operation');
Expand All @@ -89,6 +89,13 @@ const FLAG_HANDLERS = Object.freeze({
let fieldType;
switch (currentOp.op) {
case 'addEnumOption':
if (currentOp.data.key) {
ops.push({...currentOp});
currentOp.data = {};
}

currentOp.data.key = value.input;
break;
case 'editEnumOption':
case 'addMultiSelectOption':
currentOp.data.key = value.input;
Expand Down
8 changes: 8 additions & 0 deletions test/commands/metadata-templates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ describe('Metadata Templates', () => {
key: 'optionKey1',
},
},
{
op: 'addEnumOption',
fieldKey: 'key1',
data: {
key: 'optionKey2',
},
},
{
op: 'addField',
data: {
Expand Down Expand Up @@ -480,6 +487,7 @@ describe('Metadata Templates', () => {
'--no-copy-instance-on-item-copy',
'--add-enum-option=key1',
'--option=optionKey1',
'--option=optionKey2',
'--enum=Field Display Name',
'--description=My New Field',
'--field-key=key2',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
{
"key": "optionKey1"
},
{
"key": "optionKey2"
}
]
},
Expand Down

0 comments on commit 8779eec

Please sign in to comment.