mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-18 11:32:15 -05:00
test(organization): fix flaky tests (#7560)
This commit is contained in:
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user