Skip to content
Draft
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
3 changes: 3 additions & 0 deletions packages/api/src/router/event-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ describe("Event Type Router", () => {
});

it("should update an existing event type", async () => {
const f3Nation = await getOrCreateF3NationOrg();
const session = await createAdminSession();
await mockAuthWithSession(session);

Expand All @@ -398,6 +399,7 @@ describe("Event Type Router", () => {
.values({
name: `Original Event Type ${uniqueId()}`,
eventCategory: "first_f",
specificOrgId: f3Nation.id,
isActive: true,
})
.returning();
Expand All @@ -413,6 +415,7 @@ describe("Event Type Router", () => {
id: testEventType.id,
name: updatedName,
eventCategory: "third_f",
specificOrgId: f3Nation.id,
isActive: true,
});

Expand Down
162 changes: 162 additions & 0 deletions packages/api/src/router/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,80 @@ describe("Event Router", () => {
expect(hasThirdF).toBe(true);
});
});

it("should return endDate field for events", async () => {
const session = await createAdminSession();
await mockAuthWithSession(session);

const region = await createTestRegion();
if (!region) return;

const ao = await createTestAO(region.id);
if (!ao) return;

const location = await createTestLocation(region.id);
if (!location) return;

// Create an event with endDate
const [eventWithEndDate] = await db
.insert(schema.events)
.values({
name: `Event With EndDate ${uniqueId()}`,
orgId: ao.id,
locationId: location.id,
dayOfWeek: "monday",
startTime: "0530",
isActive: true,
highlight: false,
startDate: "2026-01-01",
endDate: "2026-12-31",
isPrivate: false,
})
.returning();

if (eventWithEndDate) {
createdEventIds.push(eventWithEndDate.id);
}

// Create an event without endDate (null)
const [eventWithoutEndDate] = await db
.insert(schema.events)
.values({
name: `Event Without EndDate ${uniqueId()}`,
orgId: ao.id,
locationId: location.id,
dayOfWeek: "tuesday",
startTime: "0600",
isActive: true,
highlight: false,
startDate: "2026-01-01",
endDate: null,
isPrivate: false,
})
.returning();

if (eventWithoutEndDate) {
createdEventIds.push(eventWithoutEndDate.id);
}

const client = createTestClient();
const result = await client.map.event.all({
pageIndex: 0,
pageSize: 100,
});

// Find our events in the results
const foundWithEndDate = result.events?.find(
(e) => e.id === eventWithEndDate?.id,
);
const foundWithoutEndDate = result.events?.find(
(e) => e.id === eventWithoutEndDate?.id,
);

// Both events should be present in the response
expect(foundWithEndDate).toBeDefined();
expect(foundWithoutEndDate).toBeDefined();
});
});

describe("count", () => {
Expand Down Expand Up @@ -796,6 +870,94 @@ describe("Event Router", () => {
expect(result.event?.id).toBe(privateEvent.id);
expect(result.event?.isPrivate).toBe(true);
});

it("should return endDate field for an event", async () => {
const session = await createAdminSession();
await mockAuthWithSession(session);

const region = await createTestRegion();
if (!region) return;

const ao = await createTestAO(region.id);
if (!ao) return;

const location = await createTestLocation(region.id);
if (!location) return;

// Create an event with endDate
const [eventWithEndDate] = await db
.insert(schema.events)
.values({
name: `Event With EndDate ById ${uniqueId()}`,
orgId: ao.id,
locationId: location.id,
dayOfWeek: "thursday",
startTime: "0700",
isActive: true,
highlight: false,
startDate: "2026-02-01",
endDate: "2026-11-30",
isPrivate: false,
})
.returning();

if (!eventWithEndDate) return;
createdEventIds.push(eventWithEndDate.id);

const client = createTestClient();
const result = await client.event.byId({
id: eventWithEndDate.id,
});

expect(result.event).not.toBeNull();
expect(result.event?.id).toBe(eventWithEndDate.id);
expect(result.event).toHaveProperty("endDate");
expect(result.event?.endDate).toBe("2026-11-30");
});

it("should return null endDate when event has no endDate", async () => {
const session = await createAdminSession();
await mockAuthWithSession(session);

const region = await createTestRegion();
if (!region) return;

const ao = await createTestAO(region.id);
if (!ao) return;

const location = await createTestLocation(region.id);
if (!location) return;

// Create an event without endDate
const [eventWithoutEndDate] = await db
.insert(schema.events)
.values({
name: `Event Without EndDate ById ${uniqueId()}`,
orgId: ao.id,
locationId: location.id,
dayOfWeek: "friday",
startTime: "0600",
isActive: true,
highlight: false,
startDate: "2026-03-01",
endDate: null,
isPrivate: false,
})
.returning();

if (!eventWithoutEndDate) return;
createdEventIds.push(eventWithoutEndDate.id);

const client = createTestClient();
const result = await client.event.byId({
id: eventWithoutEndDate.id,
});

expect(result.event).not.toBeNull();
expect(result.event?.id).toBe(eventWithoutEndDate.id);
expect(result.event).toHaveProperty("endDate");
expect(result.event?.endDate).toBeNull();
});
});

describe("crupdate", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/router/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const eventRouter = {
parent: parentOrg.name,
locationId: schema.events.locationId,
startDate: schema.events.startDate,
endDate: schema.events.endDate,
dayOfWeek: schema.events.dayOfWeek,
startTime: schema.events.startTime,
endTime: schema.events.endTime,
Expand Down Expand Up @@ -467,6 +468,7 @@ export const eventRouter = {
location: aoOrg.name,
locationId: schema.events.locationId,
startDate: schema.events.startDate,
endDate: schema.events.endDate,
dayOfWeek: schema.events.dayOfWeek,
startTime: schema.events.startTime,
endTime: schema.events.endTime,
Expand Down
Loading