-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: Param decorator to parse our app user agent strings #16472
Conversation
WalkthroughThe changes introduce a new decorator for parsing user agent strings in a NestJS application. This involves adding the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant Decorator
Client->>Server: HTTP Request
Server->>Decorator: Apply ParsedUserAgent
Decorator->>Server: Parse User Agent
Server->>Client: Response with Parsed User Agent Info
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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
🧹 Outside diff range and nitpick comments (5)
libs/nest/core/src/index.ts (1)
2-2
: LGTM! Consider named exports for better tree-shaking.The new export for
ParsedUserAgent.decorator
is correctly added and aligns with the PR objectives. It follows the existing pattern and promotes reusability across NestJS apps.For even better tree-shaking, consider using named exports instead of
export *
. This allows bundlers to more easily eliminate unused code. For example:export { ParsedUserAgent } from './lib/decorators/ParsedUserAgent.decorator';Apply this change to all exports in the file for consistency.
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.spec.ts (3)
3-78
: LGTM: Well-structured test suite with comprehensive coverage.The test suite is well-organized using Jest's
describe
andit
functions, and follows the Arrange-Act-Assert pattern. It covers a good range of scenarios for both iOS and Android, including new and old user agent formats, as well as an unknown user agent.Consider adding a test case for an empty user agent string to ensure robustness.
34-47
: LGTM: Test case for old iOS app user agent.This test case checks the parsing of an old iOS app user agent string, verifying the extraction of app name and OS name.
Consider adding a comment explaining why version and build number are not expected in the result for old user agent strings, to improve clarity for future developers.
49-62
: LGTM: Test case for old Android app user agent.This test case checks the parsing of an old Android app user agent string, verifying the extraction of app name and OS name.
Consider the following improvements:
- Add a comment explaining why version and build number are not expected in the result for old user agent strings.
- Clarify how the parser determines that this user agent string corresponds to Android and IslandIsApp, as it's not immediately obvious from the input string.
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.ts (1)
75-77
: Consider logging unrecognized user agent stringsWhen none of the patterns match, the function returns a default
userAgent
object with empty fields. Logging these unrecognized user agent strings can aid in monitoring and identifying new or unexpected user agents for future support.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
- libs/nest/core/src/index.ts (1 hunks)
- libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.spec.ts (1 hunks)
- libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/nest/core/src/index.ts (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.spec.ts (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.ts (1)
Pattern
libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (7)
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.spec.ts (5)
1-1
: LGTM: Import statement is correct.The import statement is properly structured and imports the necessary function for testing.
4-17
: LGTM: Comprehensive test for new iOS app user agent.This test case thoroughly checks the parsing of a new iOS app user agent string, verifying all expected fields including app name, version, build number, and OS details.
19-32
: LGTM: Comprehensive test for new Android app user agent.This test case thoroughly checks the parsing of a new Android app user agent string, verifying all expected fields including app name, version, build number, and OS details.
64-77
: LGTM: Test case for unknown user agent.This test case effectively checks the parsing of an unknown user agent string, verifying that the result contains empty objects for app and os as expected.
1-78
: Adherence to coding guidelines forlibs/**/*
This test file adheres to the TypeScript usage guideline. The reusability and tree-shaking guidelines are not directly applicable to test files.
libs/nest/core/src/lib/decorators/ParsedUserAgent.decorator.ts (2)
15-26
: Well-definedUserAgent
interface using TypeScriptThe
UserAgent
interface is clearly defined, utilizing optional properties effectively, which promotes type safety and clarity in the codebase.
85-92
:ParsedUserAgent
decorator correctly injects parsed user agent informationThe decorator effectively parses the user agent string from request headers and provides the parsed information in the request context, enhancing reusability across different parts of the application.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16472 +/- ##
==========================================
+ Coverage 36.77% 36.79% +0.01%
==========================================
Files 6844 6842 -2
Lines 141684 141626 -58
Branches 40358 40317 -41
==========================================
- Hits 52107 52106 -1
+ Misses 89577 89520 -57
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 36 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 8 Total Test Services: 0 Failed, 8 Passed Test Services
🔻 Code Coverage Decreases vs Default Branch (3) |
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.
LGTM
Summary by CodeRabbit
New Features
Tests