Skip to content

Commit

Permalink
Add basic tests for remove command (vercel#10304)
Browse files Browse the repository at this point in the history
Adds some minimal unit testing for the `remove` command. There is currently none.
  • Loading branch information
trek authored Aug 7, 2023
1 parent c5e0cb4 commit 153ca44
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changeset/lovely-donuts-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
59 changes: 59 additions & 0 deletions packages/cli/test/unit/commands/remove.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { client } from '../../mocks/client';
import {
defaultProject,
useProject,
useUnknownProject,
} from '../../mocks/project';
import remove from '../../../src/commands/remove';
import { useDeployment } from '../../mocks/deployment';
import { useUser } from '../../mocks/user';

describe('remove', () => {
it('should error if missing deployment url', async () => {
client.setArgv('remove');
const exitCodePromise = remove(client);

await expect(client.stderr).toOutput(
'Error: `vercel rm` expects at least one argument'
);
await expect(exitCodePromise).resolves.toEqual(1);
});

it('should error without calling API for invalid names', async () => {
const badDeployName = '/#';
client.setArgv('remove', badDeployName);
const exitCodePromise = remove(client);

await expect(client.stderr).toOutput(
`Error: The provided argument "${badDeployName}" is not a valid deployment or project`
);
await expect(exitCodePromise).resolves.toEqual(1);
});

it('calls API to delete a project ', async () => {
let deleteAPIWasCalled = false;
const user = useUser();

const project = useProject({
...defaultProject,
id: '123',
});

useUnknownProject();

const deployment = useDeployment({
creator: user,
project,
});

client.scenario.delete('/now/deployments/:id', (req, res) => {
deleteAPIWasCalled = true;
res.json({});
});

client.setArgv('remove', deployment.url, '--yes');
await remove(client);

expect(deleteAPIWasCalled);
});
});

0 comments on commit 153ca44

Please sign in to comment.