forked from vercel/vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tests for remove command (vercel#10304)
Adds some minimal unit testing for the `remove` command. There is currently none.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |