Skip to content

Commit

Permalink
fix: don't prompt for version if only one exists (#675)
Browse files Browse the repository at this point in the history
* fix: don't prompt if only one version exists

* test: fix tests

* test: small test change to address coverage
  • Loading branch information
kanadgupta authored Nov 17, 2022
1 parent c2677f7 commit 0180883
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe('rdme docs', () => {
const versionsMock = getAPIMock()
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [{ version: altVersion }]);
.reply(200, [{ version }, { version: altVersion }]);

const getMock = getAPIMockWithVersionHeader(altVersion)
.get(`/api/v1/docs/${slug}`)
Expand Down
5 changes: 4 additions & 1 deletion __tests__/cmds/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe('rdme open', () => {
version,
};

const mockRequest = getAPIMock().get('/api/v1/version').basicAuth({ user: key }).reply(200, [versionPayload]);
const mockRequest = getAPIMock()
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [versionPayload, { version: '1.0.1' }]);

const dashUrl = 'https://dash.readme.com/project/subdomain/v1.0/overview';

Expand Down
3 changes: 1 addition & 2 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ describe('rdme openapi', () => {
});

it('should create a new spec via `--create` flag and ignore `--id`', async () => {
prompts.inject([version]);
const registryUUID = getRandomRegistryId();

const mock = getAPIMock()
Expand Down Expand Up @@ -1297,7 +1296,7 @@ describe('rdme openapi', () => {
const mock = getAPIMock()
.get('/api/v1/version')
.basicAuth({ user: key })
.reply(200, [{ version }])
.reply(200, [{ version }, { version: '1.1.0' }])
.post('/api/v1/api-registry', body => body.match('form-data; name="spec"'))
.reply(201, { registryUUID, spec: { openapi: '3.0.0' } });

Expand Down
4 changes: 4 additions & 0 deletions src/lib/versionSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export async function getProjectVersion(versionFlag: string, key: string, return
headers: cleanHeaders(key),
}).then(res => handleRes(res));

if (versionList.length === 1) {
return versionList[0].version;
}

if (returnStable) {
const stableVersion = versionList.find(v => v.is_stable === true);
return stableVersion.version;
Expand Down

0 comments on commit 0180883

Please sign in to comment.