Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppRoleHumanMapper, AppRoles } from "common/roles.js";
import { FastifyZodOpenApiSchema } from "fastify-zod-openapi";
import * as z from "zod/v4";
import { CoreOrganizationList } from "@acm-uiuc/js-shared";
import { AllOrganizationList } from "@acm-uiuc/js-shared";
export {
illinoisSemesterId as semesterId,
illinoisNetId,
Expand All @@ -21,7 +21,7 @@
});

export const acmCoreOrganization = z
.enum(CoreOrganizationList as [string, ...string[]])
.enum(AllOrganizationList as [string, ...string[]])
.meta({
description: "ACM Organization",
id: "AcmOrganization",
Expand Down Expand Up @@ -195,7 +195,7 @@
schema: T,
{ disableApiKeyAuth }: RolesConfig = { disableApiKeyAuth: false },
): T & RoleSchema {
const security = [{ httpBearer: [] }] as any;

Check warning on line 198 in src/api/components/index.ts

View workflow job for this annotation

GitHub Actions / Run Unit Tests

Unexpected any. Specify a different type
if (!disableApiKeyAuth) {
security.push({ apiKeyHeader: [] });
}
Expand Down
8 changes: 6 additions & 2 deletions src/api/routes/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FastifyPluginAsync, FastifyRequest } from "fastify";
import { FastifyPluginAsync } from "fastify";
import { AppRoles } from "../../common/roles.js";
import * as z from "zod/v4";
import {
Expand Down Expand Up @@ -141,7 +141,7 @@ const baseSchema = z.object({
}),
host: acmCoreOrganization,
featured: z.boolean().default(false).meta({
ref: "acmOrganizationList",
ref: "featuredEventBool",
description:
"Whether or not the event should be shown on the ACM @ UIUC website home page (and added to Discord, as available).",
}),
Expand All @@ -159,12 +159,16 @@ const requestSchema = baseSchema.extend({
});

const postRequestSchema = requestSchema
.extend({
description: z.string().min(1).max(250),
})
.refine((data) => (data.repeatEnds ? data.repeats !== undefined : true), {
message: "repeats is required when repeatEnds is defined",
})
.refine((data) => (data.repeatExcludes ? data.repeats !== undefined : true), {
message: "repeats is required when repeatExcludes is defined",
});

export type EventPostRequest = z.infer<typeof postRequestSchema>;

const getEventSchema = requestSchema.extend({
Expand Down
2 changes: 2 additions & 0 deletions src/ui/pages/events/ManageEvent.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const requestBodySchema = baseBodySchema
.extend({
start: z.coerce.date(),
end: z.coerce.date(),
description: z.string().min(1).max(250),
repeats: z.optional(z.enum(repeatOptions)).nullable(),
repeatEnds: z.coerce.date().optional(),
repeatExcludes: z.array(z.coerce.date()).max(100).optional(),
Expand Down Expand Up @@ -370,6 +371,7 @@ export const ManageEventPage: React.FC = () => {
label="Event Description"
withAsterisk
placeholder="Event description"
description="Maximum 250 characters - be concise!"
{...form.getInputProps("description")}
/>

Expand Down
28 changes: 28 additions & 0 deletions tests/unit/eventPost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,34 @@ test("Sad path: Prevent specifying repeatEnds on non-repeating events", async ()
});
});

test("Sad path: Description is too long", async () => {
ddbMock.on(PutItemCommand).resolves({});
const testJwt = createJwt();
await app.ready();
const response = await supertest(app.server)
.post("/api/v1/events")
.set("authorization", `Bearer ${testJwt}`)
.send({
description: "a".repeat(260),
end: "2024-09-25T19:00:00",
featured: false,
host: "Social Committee",
location: "Illini Union",
start: "2024-09-25T18:00:00",
title: "Fall Semiformal",
repeats: "weekly",
paidEventId: "sp24_semiformal",
});

expect(response.statusCode).toBe(400);
expect(response.body).toStrictEqual({
error: true,
name: "ValidationError",
id: 104,
message: `body/description Too big: expected string to have <=250 characters`,
});
});

test("Sad path: Prevent specifying unknown repeat frequencies", async () => {
ddbMock.on(PutItemCommand).resolves({});
const testJwt = createJwt();
Expand Down
Loading