Skip to content

Conversation

@volnei
Copy link
Contributor

@volnei volnei commented Sep 17, 2025

What does this PR do?

This PR adds comprehensive test coverage for the calendar cache and sync functionality implemented in PR #23876. It provides extensive test suites for all major components of the calendar caching system including:

  • CalendarCacheRepository - Tests for cache retrieval, storage, watching/unwatching calendars
  • CalendarCacheEventService & Repository - Tests for event handling, filtering, and batch operations
  • API v2 CalendarsCacheService - Tests for Redis-based caching operations with TTL
  • Cron job functionality - Tests for automated cache cleanup and calendar synchronization
  • Provider-specific implementations - Tests for Google Calendar and Office365 webhook integrations
  • Utility functions - Tests for cache serving logic and feature flag handling

The test suite follows Cal.com's established patterns using Vitest and Prismock, ensuring consistent timezone handling with TZ=UTC.

Link to Devin run: https://app.devin.ai/sessions/d4c8af423e9a47efa4d61a60b2577653
Requested by: @volnei

Visual Demo (For contributors especially)

N/A - This PR focuses on test coverage and does not introduce user-facing changes.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Environment Setup

  • No additional environment variables required for tests
  • Tests use mocked dependencies (Redis, Prisma, calendar providers)

Running Tests

# Run all calendar cache tests
TZ=UTC yarn test packages/features/calendar-cache
TZ=UTC yarn test packages/features/calendar-subscription/lib/cache
TZ=UTC yarn test apps/api/v2/src/ee/calendars/services
TZ=UTC yarn test apps/web/app/api/cron/calendar-cache-cleanup

# Run enhanced CalendarService tests
TZ=UTC yarn test packages/app-store/googlecalendar/lib/__tests__/CalendarService.test.ts

# Run type checking
yarn type-check:ci --force

# Run linting
yarn lint:report

Test Coverage Areas

  • Cache Operations: Hit/miss scenarios, TTL behavior, Redis operations
  • Event Processing: Filtering, batch operations, status handling
  • Delegation Credentials: In-memory vs database credential scenarios
  • Cron Jobs: Calendar watching/unwatching, cleanup operations
  • Error Handling: Database errors, network failures, invalid data
  • Feature Flags: Enabled/disabled behavior across components

Expected Results

  • All 124+ tests should pass consistently
  • Type checking should complete without errors
  • Linting should pass with no warnings
  • Tests should complete in reasonable time (<30 seconds total)

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

Key Areas for Review

⚠️ Important Review Points:

  1. Test Coverage Completeness - Verify tests cover all critical paths in the calendar cache implementation
  2. Mock Accuracy - Ensure mocks properly simulate real service behavior without hiding bugs
  3. Error Scenarios - Review error handling tests for realistic failure modes
  4. Integration Points - Check tests properly validate interactions between cache layers
  5. Performance Considerations - Verify tests don't introduce performance regressions
  6. Type Safety - Confirm all type assertions are safe and necessary

Files Added/Modified

New Test Files (13 files)

  • packages/features/calendar-cache/calendar-cache.repository.test.ts
  • packages/features/calendar-cache/calendar-cache.test.ts
  • packages/features/calendar-cache/api/cron.test.ts
  • packages/features/calendar-cache/lib/getShouldServeCache.test.ts
  • packages/features/calendar-subscription/lib/cache/CalendarCacheEventService.test.ts
  • packages/features/calendar-subscription/lib/cache/CalendarCacheEventRepository.test.ts
  • apps/api/v2/src/ee/calendars/services/calendars-cache.service.test.ts
  • apps/web/app/api/cron/calendar-cache-cleanup/route.test.ts
  • packages/app-store/googlecalendar/lib/__tests__/webhook-cache-integration.test.ts
  • packages/app-store/office365calendar/lib/__tests__/webhook-cache-integration.test.ts

Mock Infrastructure (3 files)

  • packages/features/calendar-cache/__mocks__/CalendarCacheEventRepository.mock.ts
  • packages/features/calendar-cache/__mocks__/CalendarProvider.mock.ts
  • packages/features/calendar-cache/__mocks__/RedisService.mock.ts

Enhanced Existing Tests (1 file)

  • packages/app-store/googlecalendar/lib/__tests__/CalendarService.test.ts - Re-enabled cache tests, added delegation credential scenarios

This comprehensive test suite ensures the calendar cache system is reliable, maintainable, and follows Cal.com's quality standards.

volnei and others added 12 commits September 16, 2025 14:38
- Add tests for CalendarCacheRepository covering regular and delegation credentials
- Add tests for CalendarCacheEventService and CalendarCacheEventRepository
- Add tests for API v2 CalendarsCacheService Redis operations
- Add integration tests for cron jobs and cleanup functionality
- Add provider-specific calendar cache tests for Google Calendar and Office365
- Re-enable and enhance existing CalendarService cache tests
- Add comprehensive mocking infrastructure for calendar cache testing
- Add tests for utility functions like getShouldServeCache
- Ensure all tests follow Cal.com patterns using vitest and prismock
- Use TZ=UTC environment variable for consistent timezone handling

This provides complete test coverage for the calendar cache implementation
from PR #23876, ensuring reliability and maintainability of the caching
system across all supported calendar providers and use cases.

Co-Authored-By: Volnei Munhoz <[email protected]>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/calendar_sync_cache_tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added ❗️ .env changes contains changes to env variables and removed size/XXL labels Sep 17, 2025
@keithwillcode keithwillcode added core area: core, team members only foundation labels Sep 17, 2025
- Add missing AppFlags properties for calendar-subscription-cache and calendar-subscription-sync
- Fix SelectedCalendarRepository interface to match actual implementation return types
- Handle nullable credential relationships in repository interface
- Fix null/undefined handling in CalendarCacheEventService and CalendarCacheEventRepository
- Update Office365CalendarSubscription adapter to use proper URL parsing instead of request.query
- Fix isAllDay type compatibility in GoogleCalendarSubscription adapter
- Improve error handling in cron route to handle unknown error types
- Update CalendarService test to use proper type casting for private method access
- Replace non-null assertions with nullish coalescing to satisfy ESLint rules
- Use proper type definitions instead of 'any' type

All TypeScript type checks now pass and test suite runs successfully.

Co-Authored-By: Volnei Munhoz <[email protected]>
@vercel
Copy link

vercel bot commented Sep 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 18, 2025 9:50pm
cal-eu Ignored Ignored Sep 18, 2025 9:50pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only ❗️ .env changes contains changes to env variables foundation size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants