Skip to content

Commit

Permalink
Minor fixes:
Browse files Browse the repository at this point in the history
1. Copy edit
2. QOL with main version interaction
3. Test case update
  • Loading branch information
gratcliff committed Jul 16, 2019
1 parent b17af48 commit 7a969e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 12 additions & 2 deletions lib/versions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion test/versions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 });
Expand All @@ -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);
Expand Down

0 comments on commit 7a969e8

Please sign in to comment.