Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(versions): fix ability to set main version #872

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions __tests__/cmds/versions/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ describe('rdme versions:create', () => {
mockRequest.done();
});

it('should create successfully a main version', async () => {
const newVersion = '1.0.1';

const mockRequest = getAPIMock()
.post('/api/v1/version', {
version: newVersion,
from: '1.0.0',
is_beta: false,
is_stable: true,
})
.basicAuth({ user: key })
.reply(201, { version: newVersion });

await expect(
createVersion.run({
key,
version: newVersion,
fork: version,
beta: 'false',
main: 'true',
isPublic: 'false',
deprecated: 'true',
}),
).resolves.toBe(`Version ${newVersion} created successfully.`);

mockRequest.done();
});

it('should catch any post request errors', async () => {
const errorResponse = {
error: 'VERSION_EMPTY',
Expand Down
38 changes: 37 additions & 1 deletion __tests__/cmds/versions/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,41 @@ describe('rdme versions:update', () => {
mockRequest.done();
});

it('should update a version to be the main one', async () => {
const versionToChange = '1.1.0';
const renamedVersion = '1.1.0-update';

const updatedVersionObject = {
version: renamedVersion,
is_beta: false,
is_stable: true,
};

const mockRequest = getAPIMock()
.get(`/api/v1/version/${versionToChange}`)
.basicAuth({ user: key })
.reply(200, { version: versionToChange })
.get(`/api/v1/version/${versionToChange}`)
.basicAuth({ user: key })
.reply(200, { version: versionToChange })
.put(`/api/v1/version/${versionToChange}`, updatedVersionObject)
.basicAuth({ user: key })
.reply(201, updatedVersionObject);

await expect(
updateVersion.run({
key,
version: versionToChange,
newVersion: renamedVersion,
deprecated: 'true',
beta: 'false',
main: 'true',
isPublic: 'false',
}),
).resolves.toBe(`Version ${versionToChange} updated successfully.`);
mockRequest.done();
});

// Note: this test is a bit bizarre since the flag management
// in our version commands is really confusing to follow.
// I'm not sure if it's technically possible to demote a stable version
Expand All @@ -222,11 +257,12 @@ describe('rdme versions:update', () => {
const updatedVersionObject = {
version: renamedVersion,
is_beta: true,
is_deprecated: true,
is_hidden: true,
is_stable: false,
};

prompts.inject([renamedVersion, true]);
prompts.inject([renamedVersion, true, false, true]);

const errorResponse = {
error: 'VERSION_CANT_DEMOTE_STABLE',
Expand Down
3 changes: 2 additions & 1 deletion src/cmds/versions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export default class CreateVersionCommand extends Command {
from: promptResponse.from,
is_beta: promptResponse.is_beta,
is_deprecated: promptResponse.is_deprecated,
is_hidden: !promptResponse.is_public,
// if the "is public" question was never asked, we should omit that from the payload
is_hidden: typeof promptResponse.is_public === 'undefined' ? undefined : !promptResponse.is_public,
is_stable: promptResponse.is_stable,
};

Expand Down
3 changes: 2 additions & 1 deletion src/cmds/versions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export default class UpdateVersionCommand extends Command {
version: promptResponse.newVersion || version,
is_beta: promptResponse.is_beta,
is_deprecated: promptResponse.is_deprecated,
is_hidden: !promptResponse.is_public,
// if the "is public" question was never asked, we should omit that from the payload
is_hidden: typeof promptResponse.is_public === 'undefined' ? undefined : !promptResponse.is_public,
is_stable: promptResponse.is_stable,
};

Expand Down
4 changes: 2 additions & 2 deletions src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function versionPrompt(
},
{
type: (prev, values) => {
// if user previously wanted this version to be the main version
// if user wants this version to be the main version
// it can't also be hidden.
return values.is_stable ? null : 'confirm';
},
Expand All @@ -188,7 +188,7 @@ export function versionPrompt(
},
{
type: (prev, values) => {
// if user previously wanted this version to be the main version
// if user wants this version to be the main version
// it can't also be deprecated.
return values.is_stable ? null : 'confirm';
},
Expand Down