From e854e2c9fe6df2915bcd50faae46752f39198f7c Mon Sep 17 00:00:00 2001 From: Elliot Campbell Date: Fri, 30 Jun 2023 16:01:12 -0400 Subject: [PATCH 1/2] variations update should now properly accept feature keys as an arg --- src/commands/variations/update.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/commands/variations/update.ts b/src/commands/variations/update.ts index 03c54cda5..492a9f775 100644 --- a/src/commands/variations/update.ts +++ b/src/commands/variations/update.ts @@ -10,6 +10,7 @@ import { variationPrompt, } from '../../ui/prompts/variationPrompts' import { Args, Flags } from '@oclif/core' +import { fetchFeatureByKey } from '../../api/features' export default class UpdateVariation extends UpdateCommand { static hidden = false @@ -65,11 +66,14 @@ export default class UpdateVariation extends UpdateCommand { } else { selectedVariation = await fetchVariationByKey(this.authToken, this.projectKey, featureKey, args.key) } - + const feature = await fetchFeatureByKey(this.authToken, this.projectKey, featureKey) + if (!feature) { + throw new Error(`Unable to find feature for key: ${featureKey}`) + } this.prompts.push(await getVariationVariablePrompt( this.authToken, this.projectKey, - featureKey, + feature._id, )) this.writer.blankLine() From 20bcb5ed5174a5b13b3b37a4ee5ce53b46e69f53 Mon Sep 17 00:00:00 2001 From: Elliot Campbell Date: Tue, 4 Jul 2023 10:00:09 -0400 Subject: [PATCH 2/2] fix tests --- src/commands/variations/update.test.ts | 19 ++++++++++++++++--- src/commands/variations/update.ts | 7 ++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/commands/variations/update.test.ts b/src/commands/variations/update.test.ts index 7835e2250..6b608cf5e 100644 --- a/src/commands/variations/update.test.ts +++ b/src/commands/variations/update.test.ts @@ -125,7 +125,11 @@ describe('variations update', () => { .reply(200, mockVariation) ) .nock(BASE_URL, (api) => api - .get(`/v1/projects/${projectKey}/variables?feature=${featureKey}`) + .get(`/v1/projects/${projectKey}/features/${featureKey}`) + .reply(200, mockFeature) + ) + .nock(BASE_URL, (api) => api + .get(`/v1/projects/${projectKey}/variables?feature=63b5eea3e6e91987bae47f3a`) .reply(200, mockVariables) ) .nock(BASE_URL, (api) => api @@ -153,7 +157,11 @@ describe('variations update', () => { .reply(200, mockVariation) ) .nock(BASE_URL, (api) => api - .get(`/v1/projects/${projectKey}/variables?feature=${featureKey}`) + .get(`/v1/projects/${projectKey}/features/${featureKey}`) + .reply(200, mockFeature) + ) + .nock(BASE_URL, (api) => api + .get(`/v1/projects/${projectKey}/variables?feature=63b5eea3e6e91987bae47f3a`) .reply(200, mockVariables) ) .nock(BASE_URL, (api) => api @@ -180,13 +188,18 @@ describe('variations update', () => { .reply(200, mockVariation) ) .nock(BASE_URL, (api) => api - .get(`/v1/projects/${projectKey}/variables?feature=${featureKey}`) + .get(`/v1/projects/${projectKey}/features/${featureKey}`) + .reply(200, mockFeature) + ) + .nock(BASE_URL, (api) => api + .get(`/v1/projects/${projectKey}/variables?feature=63b5eea3e6e91987bae47f3a`) .reply(200, mockVariables) ) .nock(BASE_URL, (api) => api .patch(`/v1/projects/${projectKey}/features/${featureKey}/variations/${variationKey}`, requestBody) .reply(200, mockFeature) ) + .stub(inquirer, 'registerPrompt', () => { return }) .stub(inquirer, 'prompt', () => { return { diff --git a/src/commands/variations/update.ts b/src/commands/variations/update.ts index 492a9f775..2378a9279 100644 --- a/src/commands/variations/update.ts +++ b/src/commands/variations/update.ts @@ -2,7 +2,7 @@ import inquirer from 'inquirer' import UpdateCommand from '../updateCommand' import { fetchVariationByKey, updateVariation, UpdateVariationParams } from '../../api/variations' import { featurePrompt, keyPrompt, namePrompt } from '../../ui/prompts' -import { Variable } from '../../api/schemas' +import { Feature, Variable } from '../../api/schemas' import { getVariationVariablePrompt, @@ -66,10 +66,7 @@ export default class UpdateVariation extends UpdateCommand { } else { selectedVariation = await fetchVariationByKey(this.authToken, this.projectKey, featureKey, args.key) } - const feature = await fetchFeatureByKey(this.authToken, this.projectKey, featureKey) - if (!feature) { - throw new Error(`Unable to find feature for key: ${featureKey}`) - } + const feature = await fetchFeatureByKey(this.authToken, this.projectKey, featureKey) as Feature this.prompts.push(await getVariationVariablePrompt( this.authToken, this.projectKey,