test(organization): fix flaky tests (#7560)

This commit is contained in:
Alex Yang
2026-01-22 23:45:37 +00:00
committed by GitHub
parent 2ff9995d59
commit 737c821cc6
@@ -984,7 +984,8 @@ describe("organization", async (it) => {
"user4@email.com",
];
for (const user of users) {
// Create all users in parallel
const userPromises = users.map(async (user) => {
const newUser = await auth.api.signUpEmail({
body: {
email: user,
@@ -992,19 +993,28 @@ describe("organization", async (it) => {
name: user,
},
});
return { user, newUser };
});
const createdUsers = await Promise.all(userPromises);
// Add all members to organization in parallel
const memberPromises = createdUsers.map(async ({ newUser }) => {
const session = await auth.api.getSession({
headers: new Headers({
Authorization: `Bearer ${newUser?.token}`,
}),
});
await auth.api.addMember({
return auth.api.addMember({
body: {
organizationId: org?.id,
userId: session?.user.id!,
role: "admin",
},
});
}
});
await Promise.all(memberPromises);
const userOverLimit = {
email: "shouldthrowerror@email.com",
@@ -1128,14 +1138,25 @@ describe("organization", async (it) => {
headers: headers2,
});
// Create both users in parallel to save time
const [newUser, secondUser] = await Promise.all([
auth.api.signUpEmail({
body: {
email: "user1@email.com",
password: "password",
name: "user1",
},
}),
auth.api.signUpEmail({
body: {
email: "user2@email.com",
password: "password",
name: "user2",
},
}),
]);
// Add 1 member, now count = 2 (creator + 1)
const newUser = await auth.api.signUpEmail({
body: {
email: "user1@email.com",
password: "password",
name: "user1",
},
});
const session = await auth.api.getSession({
headers: new Headers({
Authorization: `Bearer ${newUser?.token}`,
@@ -1150,13 +1171,6 @@ describe("organization", async (it) => {
});
// Try to add a second member, should fail since limit is 2
const secondUser = await auth.api.signUpEmail({
body: {
email: "user2@email.com",
password: "password",
name: "user2",
},
});
const session2 = await auth.api.getSession({
headers: new Headers({
Authorization: `Bearer ${secondUser?.token}`,