diff --git a/src/api/routes/events.ts b/src/api/routes/events.ts index cc874a43..c2914238 100644 --- a/src/api/routes/events.ts +++ b/src/api/routes/events.ts @@ -56,6 +56,8 @@ const createProjectionParams = (includeMetadata: boolean = false) => { host: "#host", featured: "#featured", id: "#id", + repeats: "#repeats", + repeatEnds: "#repeatEnds", ...(includeMetadata ? { metadata: "#metadata" } : {}), }; @@ -179,7 +181,7 @@ const eventsPlugin: FastifyPluginAsyncZodOpenApi = async ( async (request, reply) => { const upcomingOnly = request.query?.upcomingOnly || false; const featuredOnly = request.query?.featuredOnly || false; - const includeMetadata = request.query.includeMetadata || true; + const includeMetadata = request.query.includeMetadata || false; const host = request.query?.host; const ts = request.query?.ts; // we only use this to disable cache control const projection = createProjectionParams(includeMetadata); diff --git a/src/common/policies/definition.ts b/src/common/policies/definition.ts index 6f662534..d858e595 100644 --- a/src/common/policies/definition.ts +++ b/src/common/policies/definition.ts @@ -2,6 +2,7 @@ import { FastifyRequest } from "fastify"; import { hostRestrictionPolicy } from "./events.js"; import { z } from "zod"; import { AuthorizationPolicyResult } from "./evaluator.js"; + type Policy> = { name: string; paramsSchema: TParamsSchema; @@ -11,10 +12,8 @@ type Policy> = { ) => AuthorizationPolicyResult; }; -// Type to get parameters type from a policy type PolicyParams = T extends Policy ? z.infer : never; -// Type for a registry of policies type PolicyRegistry = { [key: string]: Policy; }; @@ -27,16 +26,15 @@ type TypedPolicyRegistry = { }; }; +export const AuthorizationPoliciesRegistry: PolicyRegistry = { + EventsHostRestrictionPolicy: hostRestrictionPolicy, +} as const; + export type AvailableAuthorizationPolicies = TypedPolicyRegistry< typeof AuthorizationPoliciesRegistry >; -export const AuthorizationPoliciesRegistry = { - EventsHostRestrictionPolicy: hostRestrictionPolicy, -} as const; export type AvailableAuthorizationPolicy = { - [K in keyof typeof AuthorizationPoliciesRegistry]: { - name: K; - params: PolicyParams<(typeof AuthorizationPoliciesRegistry)[K]>; - }; -}[keyof typeof AuthorizationPoliciesRegistry]; + name: keyof typeof AuthorizationPoliciesRegistry; + params: PolicyParams; +}; diff --git a/tests/live/events.test.ts b/tests/live/events.test.ts index 86ca1cf7..c1d019cb 100644 --- a/tests/live/events.test.ts +++ b/tests/live/events.test.ts @@ -24,7 +24,7 @@ test("getting events for a given host", async () => { }); describe("Event lifecycle tests", async () => { - let createdEventUuid; + let createdEventUuid: string; test("creating an event", { timeout: 30000 }, async () => { const token = await createJwt(); const response = await fetch(`${baseEndpoint}/api/v1/events`, { @@ -34,13 +34,14 @@ describe("Event lifecycle tests", async () => { "Content-Type": "application/json", }, body: JSON.stringify({ - title: "Testing Event", + title: "Live Testing Event", description: "An event of all time", start: "2024-12-31T02:00:00", end: "2024-12-31T03:30:00", location: "ACM Room (Siebel 1104)", host: "ACM", featured: true, + repeats: "weekly", }), }); const responseJson = await response.json(); @@ -49,6 +50,26 @@ describe("Event lifecycle tests", async () => { expect(responseJson).toHaveProperty("resource"); createdEventUuid = responseJson.id; }); + test("getting a created event", { timeout: 30000 }, async () => { + if (!createdEventUuid) { + throw new Error("Event UUID not found"); + } + const response = await fetch( + `${baseEndpoint}/api/v1/events/${createdEventUuid}?ts=${Date.now()}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }, + ); + const responseJson = await response.json(); + expect(response.status).toBe(200); + expect(responseJson).toHaveProperty("id"); + expect(responseJson).toHaveProperty("repeats"); + expect(responseJson["repeatEnds"]).toBeUndefined(); + createdEventUuid = responseJson.id; + }); test("deleting a previously-created event", { timeout: 30000 }, async () => { if (!createdEventUuid) { @@ -72,7 +93,7 @@ describe("Event lifecycle tests", async () => { throw new Error("Event UUID not found"); } const response = await fetch( - `${baseEndpoint}/api/v1/events/${createdEventUuid}`, + `${baseEndpoint}/api/v1/events/${createdEventUuid}?ts=${Date.now()}`, { method: "GET", },