-
Notifications
You must be signed in to change notification settings - Fork 0
Add test coverage for notification system #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: acarlson33 <216757359+acarlson33@users.noreply.github.com>
There was a problem hiding this 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 |
| 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"]); | ||
| }); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| it("should return undefined for 'forever' duration", async () => { | ||
| const { calculateMuteExpiration } = await import("../lib/notification-settings"); | ||
| const result = calculateMuteExpiration("forever"); | ||
| expect(result).toBeUndefined(); | ||
| }); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable after.
There was a problem hiding this comment.
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(); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable currentMin.
There was a problem hiding this comment.
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.
acarlson33
left a comment
There was a problem hiding this 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>
All code review comments have been addressed in commit 647272f:
All 53 tests continue to pass. The changes reduced code by 85 lines and improved consistency with standard testing practices. |
Testing Plan for Notification System ✅ Complete
Summary
Successfully added comprehensive test coverage for the notification system with 53 passing tests across 2 test files.
Code Review Fixes Applied
await import()with static imports at module levelafterin notification-settings.test.tscurrentMinin notification-settings.test.ts📄 notification-settings.test.ts (26 tests)
Tests core notification settings management including:
📄 notification-triggers.test.ts (27 tests)
Tests notification trigger logic including:
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
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.