Skip to content

Commit 9e4552b

Browse files
authored
Set event description to max length of 250 characters (#279)
1 parent 170d854 commit 9e4552b

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/api/components/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppRoleHumanMapper, AppRoles } from "common/roles.js";
22
import { FastifyZodOpenApiSchema } from "fastify-zod-openapi";
33
import * as z from "zod/v4";
4-
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
4+
import { AllOrganizationList } from "@acm-uiuc/js-shared";
55
export {
66
illinoisSemesterId as semesterId,
77
illinoisNetId,
@@ -21,7 +21,7 @@ export const groupId = z.string().min(1).meta({
2121
});
2222

2323
export const acmCoreOrganization = z
24-
.enum(CoreOrganizationList as [string, ...string[]])
24+
.enum(AllOrganizationList as [string, ...string[]])
2525
.meta({
2626
description: "ACM Organization",
2727
id: "AcmOrganization",

src/api/routes/events.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FastifyPluginAsync, FastifyRequest } from "fastify";
1+
import { FastifyPluginAsync } from "fastify";
22
import { AppRoles } from "../../common/roles.js";
33
import * as z from "zod/v4";
44
import {
@@ -141,7 +141,7 @@ const baseSchema = z.object({
141141
}),
142142
host: acmCoreOrganization,
143143
featured: z.boolean().default(false).meta({
144-
ref: "acmOrganizationList",
144+
ref: "featuredEventBool",
145145
description:
146146
"Whether or not the event should be shown on the ACM @ UIUC website home page (and added to Discord, as available).",
147147
}),
@@ -159,12 +159,16 @@ const requestSchema = baseSchema.extend({
159159
});
160160

161161
const postRequestSchema = requestSchema
162+
.extend({
163+
description: z.string().min(1).max(250),
164+
})
162165
.refine((data) => (data.repeatEnds ? data.repeats !== undefined : true), {
163166
message: "repeats is required when repeatEnds is defined",
164167
})
165168
.refine((data) => (data.repeatExcludes ? data.repeats !== undefined : true), {
166169
message: "repeats is required when repeatExcludes is defined",
167170
});
171+
168172
export type EventPostRequest = z.infer<typeof postRequestSchema>;
169173

170174
const getEventSchema = requestSchema.extend({

src/ui/pages/events/ManageEvent.page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const requestBodySchema = baseBodySchema
8484
.extend({
8585
start: z.coerce.date(),
8686
end: z.coerce.date(),
87+
description: z.string().min(1).max(250),
8788
repeats: z.optional(z.enum(repeatOptions)).nullable(),
8889
repeatEnds: z.coerce.date().optional(),
8990
repeatExcludes: z.array(z.coerce.date()).max(100).optional(),
@@ -370,6 +371,7 @@ export const ManageEventPage: React.FC = () => {
370371
label="Event Description"
371372
withAsterisk
372373
placeholder="Event description"
374+
description="Maximum 250 characters - be concise!"
373375
{...form.getInputProps("description")}
374376
/>
375377

tests/unit/eventPost.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ test("Sad path: Prevent specifying repeatEnds on non-repeating events", async ()
106106
});
107107
});
108108

109+
test("Sad path: Description is too long", async () => {
110+
ddbMock.on(PutItemCommand).resolves({});
111+
const testJwt = createJwt();
112+
await app.ready();
113+
const response = await supertest(app.server)
114+
.post("/api/v1/events")
115+
.set("authorization", `Bearer ${testJwt}`)
116+
.send({
117+
description: "a".repeat(260),
118+
end: "2024-09-25T19:00:00",
119+
featured: false,
120+
host: "Social Committee",
121+
location: "Illini Union",
122+
start: "2024-09-25T18:00:00",
123+
title: "Fall Semiformal",
124+
repeats: "weekly",
125+
paidEventId: "sp24_semiformal",
126+
});
127+
128+
expect(response.statusCode).toBe(400);
129+
expect(response.body).toStrictEqual({
130+
error: true,
131+
name: "ValidationError",
132+
id: 104,
133+
message: `body/description Too big: expected string to have <=250 characters`,
134+
});
135+
});
136+
109137
test("Sad path: Prevent specifying unknown repeat frequencies", async () => {
110138
ddbMock.on(PutItemCommand).resolves({});
111139
const testJwt = createJwt();

0 commit comments

Comments
 (0)