Fix/accept team invite once signup (#1653)
* Accept team invite once signup * Add expectations for the team invite Co-authored-by: Miguel Nieto A <anietom@uninorte.edu.co>pull/1652/head
parent
2079199bab
commit
9dc45071c5
|
@ -53,7 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
|
|
||||||
const hashedPassword = await hashPassword(password);
|
const hashedPassword = await hashPassword(password);
|
||||||
|
|
||||||
await prisma.user.upsert({
|
const user = await prisma.user.upsert({
|
||||||
where: { email: userEmail },
|
where: { email: userEmail },
|
||||||
update: {
|
update: {
|
||||||
username,
|
username,
|
||||||
|
@ -69,5 +69,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If user has been invitedTo a team, we accept the membership
|
||||||
|
if (user.invitedTo) {
|
||||||
|
await prisma.membership.update({
|
||||||
|
where: {
|
||||||
|
userId_teamId: { userId: user.id, teamId: user.invitedTo },
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
accepted: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res.status(201).json({ message: "Created user" });
|
res.status(201).json({ message: "Created user" });
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,11 +94,25 @@ test.describe("Can signup from a team invite", async () => {
|
||||||
|
|
||||||
const createdUser = await prisma.user.findUnique({
|
const createdUser = await prisma.user.findUnique({
|
||||||
where: { email: testUser.email },
|
where: { email: testUser.email },
|
||||||
|
include: {
|
||||||
|
teams: {
|
||||||
|
include: {
|
||||||
|
team: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
// Check that the user was created
|
||||||
expect(createdUser).not.toBeNull();
|
expect(createdUser).not.toBeNull();
|
||||||
expect(createdUser?.username).toBe(testUser.validUsername);
|
expect(createdUser?.username).toBe(testUser.validUsername);
|
||||||
expect(createdUser?.password).not.toBeNull();
|
expect(createdUser?.password).not.toBeNull();
|
||||||
expect(createdUser?.emailVerified).not.toBeNull();
|
expect(createdUser?.emailVerified).not.toBeNull();
|
||||||
|
// Check that the user accepted the team invite
|
||||||
|
expect(createdUser?.teams).toHaveLength(1);
|
||||||
|
expect(createdUser?.teams[0].team.name).toBe(team.name);
|
||||||
|
expect(createdUser?.teams[0].team.slug).toBe(team.slug);
|
||||||
|
expect(createdUser?.teams[0].role).toBe("MEMBER");
|
||||||
|
expect(createdUser?.teams[0].accepted).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue