From 7a969e81a05aad16df8e02b8b72d171aadb6d621 Mon Sep 17 00:00:00 2001 From: Gabriel Ratcliff Date: Mon, 15 Jul 2019 18:18:13 -0700 Subject: [PATCH] Minor fixes: 1. Copy edit 2. QOL with main version interaction 3. Test case update --- README.md | 2 +- lib/prompts.js | 4 +++- lib/versions/update.js | 14 ++++++++++++-- test/versions.test.js | 8 +++++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eb21a544e..603f27cf9 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ rdme versions:create --key={api-key} --version={project-version} #### Update a version The command to update a version takes the same flags as creating a new version ```sh -rdme versions:create --key={api-key} --version={project-version} +rdme versions:update --key={api-key} --version={project-version} ``` #### Delete a version diff --git a/lib/prompts.js b/lib/prompts.js index 8a5dc3547..6339c8582 100644 --- a/lib/prompts.js +++ b/lib/prompts.js @@ -53,7 +53,9 @@ exports.createVersionPrompt = (versionList, opts, isUpdate) => [ type: 'confirm', name: 'is_stable', message: 'Would you like to make this version the main version for this project?', - skip: () => opts.main, + skip() { + return opts.main || (isUpdate && isUpdate.is_stable); + }, }, { type: 'confirm', diff --git a/lib/versions/update.js b/lib/versions/update.js index 02e17e876..0b3deee42 100644 --- a/lib/versions/update.js +++ b/lib/versions/update.js @@ -21,12 +21,22 @@ exports.run = async function({ opts }) { ); } - const promptResponse = await prompt(promptOpts.createVersionPrompt([{}], opts, true)); + const foundVersion = await request.get(`${config.host}/api/v1/version/${version}`, { + auth: { user: key }, + }); + + const promptResponse = await prompt( + promptOpts.createVersionPrompt( + [{}], + opts, + foundVersion ? JSON.parse(foundVersion) : foundVersion, + ), + ); const options = { json: { codename: codename || '', version: newVersion || promptResponse.newVersion, - is_stable: main || promptResponse.is_stable, + is_stable: foundVersion.is_stable || main || promptResponse.is_stable, is_beta: beta || promptResponse.is_beta, is_deprecated: deprecated || promptResponse.is_deprecated, is_hidden: promptResponse.is_stable ? false : !(isPublic || promptResponse.is_hidden), diff --git a/test/versions.test.js b/test/versions.test.js index 9ab0779c4..8a3a1485c 100644 --- a/test/versions.test.js +++ b/test/versions.test.js @@ -197,7 +197,7 @@ describe('Versions CLI Commands', () => { }); }); - describe('create new version', () => { + describe('update version', () => { it('should error if no api key provided', () => { updateVersion([], {}).catch(err => { assert.equal(err.message, 'No api key provided. Please use --key'); @@ -221,6 +221,9 @@ describe('Versions CLI Commands', () => { }); const mockRequest = nock(config.host) + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version }) .put(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(201, { version }); @@ -236,6 +239,9 @@ describe('Versions CLI Commands', () => { }); const mockRequest = nock(config.host) + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version }) .put(`/api/v1/version/${version}`) .basicAuth({ user: key }) .reply(400);