-
Notifications
You must be signed in to change notification settings - Fork 13k
fix: push notifications not delivered when message length is too large #37852
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
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: 371cc37 The changes in this PR will be included in the next version bump. This PR includes changesets to release 44 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds a truncateString utility and re-exports it; enforces push notification truncation for titles (65 chars) and message bodies (240 chars); integrates truncation into Push.send and adds unit tests; includes a changeset recording patch bumps for related packages. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #37852 +/- ##
===========================================
- Coverage 67.70% 67.69% -0.01%
===========================================
Files 3476 3476
Lines 113895 113895
Branches 20956 20956
===========================================
- Hits 77107 77099 -8
- Misses 34598 34610 +12
+ Partials 2190 2186 -4
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/meteor/tests/unit/app/push/push.spec.ts (1)
62-78: Strengthen the truncation test assertions.The test only verifies
length === 150but doesn't confirm that the ellipsis "..." is appended or that the first 147 characters are preserved. Consider adding assertions to verify the actual content.🔎 Apply this diff to improve test coverage:
it('should truncate text longer than 150 chars', async () => { const longText = 'a'.repeat(4000); const options: IPushNotificationConfig = { from: 'test', title: 'title', text: longText, userId: 'user1', apn: { category: 'MESSAGE' }, gcm: { style: 'inbox', image: 'url' }, }; await Push.send(options); const notification = sendNotificationStub.firstCall.args[0]; expect(notification.text.length).to.equal(150); + expect(notification.text).to.match(/\.\.\.$/); + expect(notification.text.startsWith('a'.repeat(147))).to.be.true; });
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
.changeset/rotten-pugs-trade.md(1 hunks)apps/meteor/app/push/server/push.ts(2 hunks)apps/meteor/tests/unit/app/push/push.spec.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/tests/unit/app/push/push.spec.tsapps/meteor/app/push/server/push.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use.spec.tsextension for test files (e.g.,login.spec.ts)
Files:
apps/meteor/tests/unit/app/push/push.spec.ts
🧠 Learnings (11)
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Group related tests in the same file
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : All test files must be created in `apps/meteor/tests/e2e/` directory
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases in Playwright tests
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) instead of `assert` statements in Playwright tests
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `test.step()` for complex test scenarios to improve organization in Playwright tests
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-12-10T21:00:54.909Z
Learnt from: KevLehman
Repo: RocketChat/Rocket.Chat PR: 37091
File: ee/packages/abac/jest.config.ts:4-7
Timestamp: 2025-12-10T21:00:54.909Z
Learning: Rocket.Chat monorepo: Jest testMatch pattern '<rootDir>/src/**/*.spec.(ts|js|mjs)' is valid in this repo and used across multiple packages (e.g., packages/tools, ee/packages/omnichannel-services). Do not flag it as invalid in future reviews.
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/page-objects/**/*.ts : Utilize existing page objects pattern from `apps/meteor/tests/e2e/page-objects/`
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure clean state for each test execution in Playwright tests
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
📚 Learning: 2025-10-06T20:30:45.540Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 37152
File: packages/apps-engine/tests/test-data/storage/storage.ts:101-122
Timestamp: 2025-10-06T20:30:45.540Z
Learning: In `packages/apps-engine/tests/test-data/storage/storage.ts`, the stub methods (updatePartialAndReturnDocument, updateStatus, updateSetting, updateAppInfo, updateMarketplaceInfo) intentionally throw "Method not implemented." Tests using these methods must stub them using `SpyOn` from the test library rather than relying on actual implementations.
Applied to files:
apps/meteor/tests/unit/app/push/push.spec.ts
🧬 Code graph analysis (1)
apps/meteor/tests/unit/app/push/push.spec.ts (1)
apps/meteor/app/push/server/push.ts (1)
Push(500-500)
🔇 Additional comments (7)
.changeset/rotten-pugs-trade.md (1)
1-5: LGTM!The changeset accurately documents the patch-level changes for push notification validation.
apps/meteor/app/push/server/push.ts (2)
18-19: LGTM!The constant is well-named and appropriately scoped at the module level.
486-489: LGTM!The truncation logic correctly limits notification text to 150 characters by slicing to position 147 and appending "...". The null-check guard prevents errors when text is undefined, and the placement after validation ensures data integrity checks pass first.
apps/meteor/tests/unit/app/push/push.spec.ts (4)
1-28: LGTM!The mock setup correctly isolates the Push class for unit testing using proxyquire. Dependencies are appropriately stubbed, and the actual
pickutility is passed through to maintain correct behavior.
30-39: LGTM!Test setup follows best practices with proper cleanup in
afterEachand isolated test fixtures inbeforeEach.
41-60: LGTM!Test correctly verifies that required fields are propagated to
sendNotification.
80-92: LGTM!Test correctly verifies that missing
userIdprevents notification sending and throws the expected error.
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.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
apps/meteor/app/push/server/push.ts(3 hunks)apps/meteor/tests/unit/app/push/push.spec.ts(1 hunks)packages/tools/src/index.ts(1 hunks)packages/tools/src/truncateString.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/meteor/tests/unit/app/push/push.spec.ts
- apps/meteor/app/push/server/push.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/tools/src/truncateString.tspackages/tools/src/index.ts
🔇 Additional comments (1)
packages/tools/src/index.ts (1)
16-16: LGTM!The re-export follows the established pattern and correctly extends the public API.
Proposed changes (including videos or screenshots)
This PR adds a new validation for sending push notifications.
Push libs like
apnandgcmhave a payload maximum size of4096 bytes, they won't accept payloads larger than that. The error described in the task is because larger messages would hit or surpass this limit.To fix this issue, this new validation checks the message size, and if it's bigger than
240, it truncates the message and adds...at the end.The reason why I picked this number is because most devices automatically truncates messages at approximately
170characters, depending on screen size.Also added the same rule to
titlesince it's also possible to go over the limit through it. Devices will auto truncate the title at approximately80chars, so I used the same reasoning and defined a lower limit for safety;65Issue(s)
SUP-951
Steps to test or reproduce
Further comments
Added a new helper function;
truncateStringin the@rocket.chat/toolspackage to keep it reusable.Summary by CodeRabbit
Bug Fixes
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.