Skip to content

fix(calendar): tighten createEvent validation for event types#308

Merged
allenhutchison merged 3 commits intomainfrom
fix/calendar-event-type-validation
Mar 31, 2026
Merged

fix(calendar): tighten createEvent validation for event types#308
allenhutchison merged 3 commits intomainfrom
fix/calendar-event-type-validation

Conversation

@allenhutchison
Copy link
Copy Markdown
Contributor

Summary

Follow-up to #290 — tightens validation in createEvent to catch edge cases that could produce confusing API behavior:

  • Reject ambiguous start/end: If both dateTime and date are provided, reject instead of letting the Google API pick one
  • Require summary for regular events: summary was made optional in feat(calendar): introduce eventType (Out of Office, Focus Time, Working Location) in Calendar Service #290 to support status event defaults, but regular events (no eventType or eventType: "default") should still require it
  • Validate working location sub-properties: officeLocation details are now required when type is "officeLocation", and customLocation details when type is "customLocation"
  • Fix updateEvent for all-day events: updateEvent was unconditionally validating start.dateTime even for date-only updates

Test plan

  • 7 new test cases covering all validation scenarios
  • All 74 calendar service tests pass
  • Lint and format checks pass

- Reject start/end with both dateTime and date (must be exactly one)
- Require summary for regular events (default/unset eventType)
- Validate officeLocation/customLocation sub-properties are present
  for their respective workingLocationProperties.type values
- Fix updateEvent datetime validation for all-day events
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request strengthens the validation logic for event creation in the CalendarService by ensuring exactly one of dateTime or date is provided, requiring summaries for regular events, and mandating location details for working location types. Corresponding unit tests were added to verify these constraints. The review feedback recommends splitting combined validation checks for more granular error messages, moving location validation earlier to fail fast, and replacing truthiness checks with undefined checks to ensure empty strings are correctly validated.

- Split combined start/end validation into separate checks with
  field-specific error paths
- Move working location sub-property validation earlier to fail fast
  before calendar ID resolution and logging
- Use !== undefined instead of truthiness for dateTime checks in
  updateEvent to catch empty strings
@allenhutchison
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances validation logic for calendar events in CalendarService.ts, specifically ensuring that event start and end times contain exactly one of dateTime or date. It also adds requirements for summaries on regular events and validates sub-properties for workingLocation event types. Corresponding unit tests have been added to verify these new constraints. One piece of feedback suggests extending the ambiguity check for dateTime and date to the updateEvent method to maintain consistency with the new createEvent validation.

Extend the same exactly-one-of check from createEvent to updateEvent,
so providing both dateTime and date (or neither) in an update is
rejected early with a clear error.

// Validate start/end: at least one of dateTime or date must be provided
if ((!start.dateTime && !start.date) || (!end.dateTime && !end.date)) {
// Validate start: exactly one of dateTime or date must be provided
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validations here make sense. At some point it may make sense to have a validation layer to separate all this logic to make it easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point filed #313 to cover this work.

Copy link
Copy Markdown
Contributor

@abhipatel12 abhipatel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@allenhutchison allenhutchison merged commit fb6930c into main Mar 31, 2026
14 checks passed
@allenhutchison allenhutchison deleted the fix/calendar-event-type-validation branch March 31, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants