-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add agent override for react and react-native SDKs #32
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
Merged
calthejuggler
merged 3 commits into
main
from
feature/agent-override-for-react-and-react-native
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,8 +78,8 @@ describe("SDKProvider", () => { | |
| apiKey: "salkjdhclkjsdbca", | ||
| application: "www", | ||
| environment: "Environment 5", | ||
| retries: 5, | ||
| timeout: 3000, | ||
| retries: 10, | ||
| timeout: 5000, | ||
| overrides: overrides, | ||
| attributes: attrs, | ||
| data: mockContextData, | ||
|
|
@@ -101,12 +101,40 @@ describe("SDKProvider", () => { | |
| ); | ||
|
|
||
| expect(SDK).toHaveBeenCalledTimes(1); | ||
| expect(SDK).toHaveBeenLastCalledWith(sdkOptions); | ||
| expect(SDK).toHaveBeenLastCalledWith({ | ||
| agent: "absmartly-react-sdk", | ||
| retries: 10, | ||
| timeout: 5000, | ||
| ...sdkOptions, | ||
| }); | ||
|
|
||
| expect(mockCreateContext).toHaveBeenCalledTimes(1); | ||
| expect(mockCreateContext).toHaveBeenLastCalledWith(contextOptions); | ||
| }); | ||
|
|
||
| it("should allow the user to override the agent", async () => { | ||
| const customSdkOptions = { | ||
| ...sdkOptions, | ||
| agent: "custom-agent", | ||
| }; | ||
|
|
||
| render( | ||
| <SDKProvider | ||
| sdkOptions={customSdkOptions} | ||
| contextOptions={contextOptions} | ||
| > | ||
| <TestComponent /> | ||
| </SDKProvider>, | ||
| ); | ||
|
|
||
| expect(SDK).toHaveBeenCalledTimes(1); | ||
| expect(SDK).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ | ||
| agent: "custom-agent", | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("Whether it will create an SDK instance with a context that has prefetched context data", async () => { | ||
| render( | ||
| <SDKProvider context={mockContext}> | ||
|
|
@@ -177,3 +205,47 @@ describe("SDKProvider", () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("SDKProvider React Native agent", () => { | ||
| const originalProduct = navigator.product; | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(navigator, "product", { | ||
| value: originalProduct, | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("should use absmartly-react-native-sdk agent when navigator.product is ReactNative", async () => { | ||
| Object.defineProperty(navigator, "product", { | ||
| value: "ReactNative", | ||
| configurable: true, | ||
| }); | ||
|
|
||
| vi.resetModules(); | ||
|
|
||
| const { SDKProvider: RNSDKProvider } = await import( | ||
| "../src/components/SDKProvider" | ||
| ); | ||
|
Comment on lines
+227
to
+229
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
|
|
||
| render( | ||
| <RNSDKProvider | ||
| sdkOptions={{ | ||
| endpoint: "https://sandbox.absmartly.io/v1", | ||
| apiKey: "test", | ||
| application: "www", | ||
| environment: "test", | ||
| }} | ||
| contextOptions={{ units: { user_id: "test" } }} | ||
| > | ||
| <div /> | ||
| </RNSDKProvider>, | ||
| ); | ||
|
|
||
| expect(SDK).toHaveBeenLastCalledWith( | ||
| expect.objectContaining({ | ||
| agent: "absmartly-react-native-sdk", | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Version bump should reflect a feature release.
This change introduces new SDK behaviour, so a minor SemVer bump is more appropriate than a patch bump.
Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents
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.
Technically, this was a bug. It should have been like this already. I don't see a need to bump a minor version for this small change
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.
@calthejuggler, that's a fair point! If the agent identifier was simply incorrect from the start and this is correcting the expected behaviour, a patch bump is perfectly appropriate under SemVer. Happy to defer to your judgement here.