fix(organization): prevent empty name and slug in create/update (#5100)

This commit is contained in:
kira-1011
2025-10-06 21:53:14 +03:00
committed by GitHub
parent daa0469350
commit ba766a33e5
2 changed files with 57 additions and 2 deletions

View File

@@ -101,6 +101,31 @@ describe("organization", async (it) => {
expect(existingSlug.error?.status).toBe(400);
expect(existingSlug.error?.message).toBe("slug is taken");
});
it("should prevent creating organization with empty slug", async () => {
const { headers } = await signInWithTestUser();
const organization = await client.organization.create({
name: "test-empty-slug",
slug: "",
fetchOptions: {
headers,
},
});
expect(organization.error?.status).toBe(400);
});
it("should prevent creating organization with empty name", async () => {
const { headers } = await signInWithTestUser();
const organization = await client.organization.create({
name: "",
slug: "test-empty-name",
fetchOptions: {
headers,
},
});
expect(organization.error?.status).toBe(400);
});
it("should create organization directly in the server without cookie", async () => {
const session = await client.getSession({
fetchOptions: {
@@ -160,6 +185,34 @@ describe("organization", async (it) => {
expect(organization.data?.metadata?.test).toBe("test2");
});
it("should prevent updating organization to empty slug", async () => {
const { headers } = await signInWithTestUser();
const organization = await client.organization.update({
organizationId,
data: {
slug: "",
},
fetchOptions: {
headers,
},
});
expect(organization.error?.status).toBe(400);
});
it("should prevent updating organization to empty name", async () => {
const { headers } = await signInWithTestUser();
const organization = await client.organization.update({
organizationId,
data: {
name: "",
},
fetchOptions: {
headers,
},
});
expect(organization.error?.status).toBe(400);
});
it("should allow activating organization and set session", async () => {
const organization = await client.organization.setActive({
organizationId,

View File

@@ -29,10 +29,10 @@ export const createOrganization = <O extends OrganizationOptions>(
isClientSide: true,
});
const baseSchema = z.object({
name: z.string().meta({
name: z.string().min(1).meta({
description: "The name of the organization",
}),
slug: z.string().meta({
slug: z.string().min(1).meta({
description: "The slug of the organization",
}),
userId: z.coerce
@@ -386,12 +386,14 @@ export const updateOrganization = <O extends OrganizationOptions>(
...additionalFieldsSchema.shape,
name: z
.string()
.min(1)
.meta({
description: "The name of the organization",
})
.optional(),
slug: z
.string()
.min(1)
.meta({
description: "The slug of the organization",
})