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

[cli] Fix team validation bug where you are apart of a team #10092

Merged
merged 5 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-carrots-provide.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export default async function getProjectByDeployment({
err.code = 'ERR_INVALID_TEAM';
throw err;
}
}

if (team) {
} else if (team) {
const err: NodeJS.ErrnoException = new Error(
`Deployment doesn't belong to current team ${chalk.bold(contextName)}`
);
Expand Down
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 project and deployment', async () => {
cb1kenobi marked this conversation as resolved.
Show resolved Hide resolved
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 project and deployment associated to a team', async () => {
cb1kenobi marked this conversation as resolved.
Show resolved Hide resolved
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');
});
});