fix: Prefer non-deleted teams in teamProvisioner (#10298)

This commit is contained in:
Tom Moor
2025-10-04 20:28:09 +02:00
committed by GitHub
parent 72c9091b7e
commit 0df42cb4c7
3 changed files with 36 additions and 3 deletions
+30
View File
@@ -93,6 +93,36 @@ describe("teamProvisioner", () => {
expect(isNewTeam).toEqual(false);
});
it("should return non-deleted team if multiple matches", async () => {
const subdomain = faker.internet.domainWord();
const authenticationProvider = {
name: "google",
providerId: `${subdomain}.com`,
};
await buildTeam({
subdomain: undefined,
deletedAt: new Date(),
authenticationProviders: [authenticationProvider],
});
const notDeleted = await buildTeam({
subdomain: undefined,
authenticationProviders: [authenticationProvider],
});
await buildTeam({
subdomain: undefined,
deletedAt: new Date(),
authenticationProviders: [authenticationProvider],
});
const result = await teamProvisioner(ctx, {
name: faker.company.name(),
subdomain,
authenticationProvider,
});
const { team, isNewTeam } = result;
expect(team.id).toEqual(notDeleted.id);
expect(isNewTeam).toEqual(false);
});
it("should error on mismatched team and authentication provider", async () => {
const subdomain = faker.internet.domainWord();
+4 -1
View File
@@ -57,7 +57,10 @@ async function teamProvisioner(
paranoid: false,
},
],
order: [["enabled", "DESC"]],
order: [
[Team, "deletedAt", "DESC"],
["enabled", "DESC"],
],
});
// This authentication provider already exists which means we have a team and
+2 -2
View File
@@ -186,7 +186,7 @@ describe("userProvisioner", () => {
expect(isNewUser).toEqual(true);
});
it("should prefer isAdmin argument over defaultUserRole", async () => {
it("should prefer role argument over defaultUserRole", async () => {
const team = await buildTeam({
defaultUserRole: UserRole.Viewer,
});
@@ -208,7 +208,7 @@ describe("userProvisioner", () => {
expect(user.role).toEqual(UserRole.Admin);
});
it("should prefer defaultUserRole when isAdmin is undefined or false", async () => {
it("should prefer defaultUserRole when role is undefined or false", async () => {
const team = await buildTeam({
defaultUserRole: UserRole.Viewer,
});