Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 17, 2025

Testing Plan for Notification System ✅ Complete

  • Create test file for notification-settings module
    • Test parseOverrides function
    • Test documentToSettings conversion
    • Test calculateMuteExpiration for all durations (15m, 1h, 8h, 24h, forever)
    • Test isMuteExpired logic (expired, active, undefined)
    • Test getEffectiveNotificationLevel with different override priorities (channel > server > global)
    • Test isInQuietHours including overnight ranges
    • Mock database operations for CRUD tests with JSON parsing and error handling
  • Create test file for notification-triggers module
    • Test determineEventType for different contexts
    • Test isEventAllowedByLevel for each notification level
    • Test shouldNotifyUser with various scenarios (DM, mentions, replies, quiet hours, etc.)
    • Test buildNotificationPayload for different event types (DM, mention, thread_reply, message)
    • Test extractMentionedUserIds pattern matching
    • Test isReplyToUser logic
  • Run tests to ensure they pass - ✅ All 53 tests passing
  • Code review completed - ✅ No issues found
  • Security scan completed - ✅ No vulnerabilities found
  • Address code review feedback - ✅ Fixed all issues

Summary

Successfully added comprehensive test coverage for the notification system with 53 passing tests across 2 test files.

Code Review Fixes Applied

  • Replaced dynamic await import() with static imports at module level
  • Removed unused variable after in notification-settings.test.ts
  • Removed unused variable currentMin in notification-settings.test.ts
  • Simplified test structure by using static imports throughout

📄 notification-settings.test.ts (26 tests)

Tests core notification settings management including:

  • Mute duration calculations for all time periods
  • Expiration logic for temporary mutes
  • Priority hierarchy for notification level overrides (channel > server > global)
  • Quiet hours detection including overnight ranges
  • Database operations with proper mocking, JSON serialization, and error handling

📄 notification-triggers.test.ts (27 tests)

Tests notification trigger logic including:

  • User mention extraction from message content
  • Reply detection logic
  • Notification payload generation for all event types
  • Comprehensive shouldNotifyUser logic covering:
    • Event type determination (DM, mention, thread_reply, message)
    • Notification level filtering (all, mentions, nothing)
    • Quiet hours suppression
    • User preference application (desktop, push, sound)
    • Edge cases and error scenarios

All tests follow existing patterns in the codebase and use proper mocking for Appwrite dependencies. The test suite passes successfully with no code quality or security issues.

Original prompt

Add some tests for the new notification system.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: acarlson33 <216757359+acarlson33@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for new notification system Add test coverage for notification system Dec 17, 2025
Copilot AI requested a review from acarlson33 December 17, 2025 14:44
@acarlson33 acarlson33 marked this pull request as ready for review December 17, 2025 14:45
Copilot AI review requested due to automatic review settings December 17, 2025 14:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive test coverage for the notification system, addressing a previously untested area of the codebase. The tests validate notification settings management and trigger logic, including edge cases and error handling scenarios.

Key Changes

  • Added 26 tests for notification settings (calculateMuteExpiration, isMuteExpired, getEffectiveNotificationLevel, isInQuietHours, database operations)
  • Added 27 tests for notification triggers (extractMentionedUserIds, isReplyToUser, buildNotificationPayload, shouldNotifyUser)
  • Implemented proper Appwrite dependency mocking consistent with the codebase

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/tests/notification-triggers.test.ts New test file covering notification trigger logic including event classification, filtering, user preferences, payload generation, and edge cases like self-notification prevention
src/tests/notification-settings.test.ts New test file covering notification settings management including mute expiration calculations, notification level hierarchy, quiet hours handling, and database CRUD operations with JSON parsing

Comment on lines 19 to 26
it("should extract user IDs from mentions", async () => {
const { extractMentionedUserIds } = await import("../lib/notification-triggers");

const messageContent = "Hey <@user123> and <@user456>, check this out!";
const result = extractMentionedUserIds(messageContent);

expect(result).toEqual(["user123", "user456"]);
});
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The dynamic import pattern using await import() inside each test is unnecessary and adds complexity. Since the module mocking is already set up at the top of the file with vi.mock(), you can import the functions normally at the module level alongside other imports (e.g., import { extractMentionedUserIds, isReplyToUser, buildNotificationPayload, shouldNotifyUser } from "../lib/notification-triggers"). This pattern is repeated throughout the file and should be refactored to use static imports for better consistency with standard testing practices.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 647272f. Replaced all dynamic imports with static imports at the module level.

Comment on lines 40 to 44
it("should return undefined for 'forever' duration", async () => {
const { calculateMuteExpiration } = await import("../lib/notification-settings");
const result = calculateMuteExpiration("forever");
expect(result).toBeUndefined();
});
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The dynamic import pattern using await import() inside each test is unnecessary and adds complexity. Since the module mocking is already set up at the top of the file with vi.mock(), you can import the functions normally at the module level alongside other imports (e.g., import { calculateMuteExpiration, isMuteExpired, getEffectiveNotificationLevel, isInQuietHours, getNotificationSettings } from "../lib/notification-settings"). This pattern is repeated throughout the file and should be refactored to use static imports for better consistency with standard testing practices.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 647272f. Replaced all dynamic imports with static imports at the module level.

const { calculateMuteExpiration } = await import("../lib/notification-settings");
const before = new Date();
const result = calculateMuteExpiration("15m");
const after = new Date();
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Unused variable after.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 647272f. Removed unused variable after.

// Test at a specific time
const now = new Date();
const currentHour = now.getHours();
const currentMin = now.getMinutes();
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Unused variable currentMin.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 647272f. Removed unused variable currentMin.

Copy link
Owner

@acarlson33 acarlson33 left a comment

Choose a reason for hiding this comment

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

@copilot please fix the copilot code review comments.

Co-authored-by: acarlson33 <216757359+acarlson33@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 17, 2025

@copilot please fix the copilot code review comments.

All code review comments have been addressed in commit 647272f:

  • Replaced dynamic imports with static imports throughout both test files
  • Removed unused variable after in notification-settings.test.ts
  • Removed unused variable currentMin in notification-settings.test.ts

All 53 tests continue to pass. The changes reduced code by 85 lines and improved consistency with standard testing practices.

@acarlson33 acarlson33 merged commit bb2e5d2 into main Dec 17, 2025
1 of 5 checks passed
@acarlson33 acarlson33 deleted the copilot/add-tests-for-notification-system branch December 17, 2025 15:08
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