-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] Fix team validation bug where you are apart of a team (#10092)
When consolidating the deployment team validation, a bug was introduced where the command would error if the user was currently using a team. The logic was meant to copy the logic in `getDeploymentByIdOrURL()`: https://github.com/vercel/vercel/blob/main/packages/cli/src/util/deploy/get-deployment-by-id-or-url.ts#L80.
- Loading branch information
Chris Barber
committed
Jun 12, 2023
1 parent
c438bbb
commit d61a1a7
Showing
3 changed files
with
110 additions
and
3 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,5 @@ | ||
--- | ||
'vercel': patch | ||
--- | ||
|
||
[cli] Fix team validation bug where you are apart of a team |
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
104 changes: 104 additions & 0 deletions
104
packages/cli/test/unit/util/projects/get-project-by-deployment.test.ts
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,104 @@ | ||
import { client } from '../../../mocks/client'; | ||
import getProjectByDeployment from '../../../../src/util/projects/get-project-by-deployment'; | ||
import { useTeams } from '../../../mocks/team'; | ||
import { useUser } from '../../../mocks/user'; | ||
import { useDeployment } from '../../../mocks/deployment'; | ||
import { defaultProject, useProject } from '../../../mocks/project'; | ||
|
||
describe('getProjectByDeployment', () => { | ||
it('should get project and deployment', async () => { | ||
const user = useUser(); | ||
const { project: p } = useProject({ | ||
...defaultProject, | ||
id: 'foo', | ||
name: 'foo', | ||
}); | ||
const d = useDeployment({ | ||
creator: user, | ||
createdAt: Date.now(), | ||
project: p, | ||
}); | ||
|
||
const { deployment, project } = await getProjectByDeployment({ | ||
client, | ||
deployId: d.id, | ||
output: client.output, | ||
}); | ||
|
||
expect(project.id).toBe(p.id); | ||
expect(deployment.id).toBe(d.id); | ||
}); | ||
|
||
it('should get project and deployment associated to a team', async () => { | ||
const [team] = useTeams('team_dummy'); | ||
const user = useUser(); | ||
const { project: p } = useProject({ | ||
...defaultProject, | ||
id: 'foo', | ||
name: 'foo', | ||
}); | ||
const d = useDeployment({ | ||
creator: { | ||
id: team.id, | ||
name: team.name, | ||
email: user.email, | ||
username: team.slug, | ||
}, | ||
createdAt: Date.now(), | ||
project: p, | ||
}); | ||
|
||
client.config.currentTeam = team.id; | ||
d.team = team; | ||
|
||
const { deployment, project } = await getProjectByDeployment({ | ||
client, | ||
deployId: d.id, | ||
output: client.output, | ||
}); | ||
|
||
expect(project.id).toBe(p.id); | ||
expect(deployment.id).toBe(d.id); | ||
}); | ||
|
||
it("should error if deployment team doesn't match current user's team", async () => { | ||
const [team] = useTeams('team_dummy'); | ||
const user = useUser(); | ||
const { project: p } = useProject({ | ||
...defaultProject, | ||
id: 'foo', | ||
name: 'foo', | ||
}); | ||
const d = useDeployment({ | ||
creator: { | ||
id: team.id, | ||
name: team.name, | ||
email: user.email, | ||
username: team.slug, | ||
}, | ||
createdAt: Date.now(), | ||
project: p, | ||
}); | ||
|
||
client.config.currentTeam = team.id; | ||
|
||
await expect( | ||
getProjectByDeployment({ | ||
client, | ||
deployId: d.id, | ||
output: client.output, | ||
}) | ||
).rejects.toThrowError("Deployment doesn't belong to current team"); | ||
|
||
client.config.currentTeam = undefined; | ||
d.team = team; | ||
|
||
await expect( | ||
getProjectByDeployment({ | ||
client, | ||
deployId: d.id, | ||
output: client.output, | ||
}) | ||
).rejects.toThrowError('Deployment belongs to a different team'); | ||
}); | ||
}); |