-
-
Notifications
You must be signed in to change notification settings - Fork 354
fix: Set user geo to the native layer. #5302
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
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e9aa963
set geo from android (OK) ios (WIP)
lucas-zimerman 9e1b9bf
project cleanup/changelog
lucas-zimerman 1303421
Merge branch 'main' into lz/user.geo
lucas-zimerman 07087c5
lint
lucas-zimerman e10a4bc
use other method to set geo on ios
lucas-zimerman f51c987
lint
lucas-zimerman 20c6dc6
remove init
lucas-zimerman 742513b
fix header
lucas-zimerman f49a04e
Merge branch 'main' into lz/user.geo
lucas-zimerman 19759ce
test fix?
lucas-zimerman bf9efc0
removal of init
lucas-zimerman bd1b9b5
remove another init
lucas-zimerman 19a4a5b
missing [
lucas-zimerman 8652281
missing ;
lucas-zimerman 5a3086d
merge main
lucas-zimerman 6940157
Merge branch 'lz/user.geo' of https://github.com/getsentry/sentry-rea…
lucas-zimerman 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,4 +272,90 @@ class RNSentryModuleImplTest { | |
| val regex = Regex(options.ignoredErrors!![0].filterString) | ||
| assertTrue(regex.matches("Error*WithStar")) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setUser with geo data creates user with correct geo properties`() { | ||
| val userKeys = | ||
| JavaOnlyMap.of( | ||
| "id", | ||
| "123", | ||
| "email", | ||
| "[email protected]", | ||
| "username", | ||
| "testuser", | ||
| "geo", | ||
| JavaOnlyMap.of( | ||
| "city", | ||
| "San Francisco", | ||
| "country_code", | ||
| "US", | ||
| "region", | ||
| "California", | ||
| ), | ||
| ) | ||
| val userDataKeys = JavaOnlyMap.of("customField", "customValue") | ||
|
|
||
| module.setUser(userKeys, userDataKeys) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setUser with partial geo data creates user with available geo properties`() { | ||
| val userKeys = | ||
| JavaOnlyMap.of( | ||
| "id", | ||
| "123", | ||
| "geo", | ||
| JavaOnlyMap.of( | ||
| "city", | ||
| "New York", | ||
| "country_code", | ||
| "US", | ||
| ), | ||
| ) | ||
| val userDataKeys = JavaOnlyMap.of() | ||
|
|
||
| module.setUser(userKeys, userDataKeys) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setUser with empty geo data handles empty geo object`() { | ||
| val userKeys = | ||
| JavaOnlyMap.of( | ||
| "id", | ||
| "123", | ||
| "geo", | ||
| JavaOnlyMap.of(), | ||
| ) | ||
| val userDataKeys = JavaOnlyMap.of() | ||
|
|
||
| module.setUser(userKeys, userDataKeys) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setUser with null geo data handles null geo gracefully`() { | ||
| val userKeys = | ||
| JavaOnlyMap.of( | ||
| "id", | ||
| "123", | ||
| "geo", | ||
| null, | ||
| ) | ||
| val userDataKeys = JavaOnlyMap.of() | ||
|
|
||
| module.setUser(userKeys, userDataKeys) | ||
| } | ||
|
|
||
| @Test | ||
| fun `setUser with invalid geo data handles non-map geo gracefully`() { | ||
| val userKeys = | ||
| JavaOnlyMap.of( | ||
| "id", | ||
| "123", | ||
| "geo", | ||
| "invalid_geo_data", | ||
| ) | ||
| val userDataKeys = JavaOnlyMap.of() | ||
|
|
||
| module.setUser(userKeys, userDataKeys) | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -102,4 +102,63 @@ - (void)testNullValuesUser | |
| XCTAssertTrue([actual isEqualToUser:expected]); | ||
| } | ||
|
|
||
| - (void)testUserWithGeo | ||
| { | ||
| SentryUser *expected = [[SentryUser alloc] init]; | ||
| [expected setUserId:@"123"]; | ||
| [expected setEmail:@"[email protected]"]; | ||
| [expected setUsername:@"testuser"]; | ||
| [expected setData:@{ | ||
| @"geo" : | ||
| @ { @"city" : @"San Francisco", @"country_code" : @"US", @"region" : @"California" } | ||
| }]; | ||
|
|
||
| SentryUser *actual = [RNSentry userFrom:@{ | ||
| @"id" : @"123", | ||
| @"email" : @"[email protected]", | ||
| @"username" : @"testuser", | ||
| @"geo" : | ||
| @ { @"city" : @"San Francisco", @"country_code" : @"US", @"region" : @"California" } | ||
| } | ||
| otherUserKeys:nil]; | ||
|
|
||
| XCTAssertTrue([actual isEqualToUser:expected]); | ||
| } | ||
|
|
||
| - (void)testUserWithPartialGeo | ||
| { | ||
| SentryUser *expected = [[SentryUser alloc] init]; | ||
| [expected setUserId:@"123"]; | ||
| [expected setData:@{ @"geo" : @ { @"city" : @"New York", @"country_code" : @"US" } }]; | ||
|
|
||
| SentryUser *actual = [RNSentry userFrom:@{ | ||
| @"id" : @"123", | ||
| @"geo" : @ { @"city" : @"New York", @"country_code" : @"US" } | ||
| } | ||
| otherUserKeys:nil]; | ||
|
|
||
| XCTAssertTrue([actual isEqualToUser:expected]); | ||
| } | ||
|
|
||
| - (void)testUserWithEmptyGeo | ||
| { | ||
| SentryUser *expected = [[SentryUser alloc] init]; | ||
| [expected setUserId:@"123"]; | ||
|
|
||
| SentryUser *actual = [RNSentry userFrom:@{ @"id" : @"123", @"geo" : @ {} } otherUserKeys:nil]; | ||
|
|
||
| XCTAssertTrue([actual isEqualToUser:expected]); | ||
| } | ||
|
|
||
| - (void)testUserWithInvalidGeo | ||
| { | ||
| SentryUser *expected = [[SentryUser alloc] init]; | ||
| [expected setUserId:@"123"]; | ||
|
|
||
| SentryUser *actual = [RNSentry userFrom:@{ @"id" : @"123", @"geo" : @"invalid_geo_data" } | ||
| otherUserKeys:nil]; | ||
|
|
||
| XCTAssertTrue([actual isEqualToUser:expected]); | ||
| } | ||
|
|
||
| @end | ||
|
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. nit: I think we don't need to change the stub. |
Binary file not shown.
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 |
|---|---|---|
|
|
@@ -141,6 +141,22 @@ describe('ScopeSync', () => { | |
| expect(setUserScopeSpy).toHaveBeenCalledExactlyOnceWith({ id: '123' }); | ||
| }); | ||
|
|
||
| it('setUser with geo data', () => { | ||
| expect(SentryCore.getIsolationScope().setUser).not.toBe(setUserScopeSpy); | ||
| const user = { | ||
| id: '123', | ||
| email: '[email protected]', | ||
| geo: { | ||
| city: 'San Francisco', | ||
| country_code: 'US', | ||
| region: 'California', | ||
| }, | ||
| }; | ||
| SentryCore.setUser(user); | ||
| expect(NATIVE.setUser).toHaveBeenCalledExactlyOnceWith(user); | ||
| expect(setUserScopeSpy).toHaveBeenCalledExactlyOnceWith(user); | ||
| }); | ||
|
|
||
| it('setTag', () => { | ||
| jest.spyOn(NATIVE, 'primitiveProcessor').mockImplementation((value: SentryCore.Primitive) => value as string); | ||
| expect(SentryCore.getIsolationScope().setTag).not.toBe(setTagScopeSpy); | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -618,6 +618,87 @@ describe('Tests Native Wrapper', () => { | |
| {}, | ||
| ); | ||
| }); | ||
|
|
||
| test('serializes user with geo data', async () => { | ||
| NATIVE.setUser({ | ||
| id: '123', | ||
| email: '[email protected]', | ||
| username: 'testuser', | ||
| geo: { | ||
| city: 'San Francisco', | ||
| country_code: 'US', | ||
| region: 'California', | ||
| }, | ||
| customField: 'customValue', | ||
| }); | ||
|
|
||
| expect(RNSentry.setUser).toBeCalledWith( | ||
| { | ||
| id: '123', | ||
| email: '[email protected]', | ||
| username: 'testuser', | ||
| geo: JSON.stringify({ | ||
| city: 'San Francisco', | ||
| country_code: 'US', | ||
| region: 'California', | ||
| }), | ||
| }, | ||
| { | ||
| customField: 'customValue', | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('serializes user with partial geo data', async () => { | ||
| NATIVE.setUser({ | ||
| id: '123', | ||
| geo: { | ||
| city: 'New York', | ||
| country_code: 'US', | ||
| }, | ||
| }); | ||
|
|
||
| expect(RNSentry.setUser).toBeCalledWith( | ||
| { | ||
| id: '123', | ||
| geo: JSON.stringify({ | ||
| city: 'New York', | ||
| country_code: 'US', | ||
| }), | ||
| }, | ||
| {}, | ||
| ); | ||
| }); | ||
|
|
||
| test('serializes user with empty geo data', async () => { | ||
| NATIVE.setUser({ | ||
| id: '123', | ||
| geo: {}, | ||
| }); | ||
|
|
||
| expect(RNSentry.setUser).toBeCalledWith( | ||
| { | ||
| id: '123', | ||
| geo: '{}', | ||
| }, | ||
| {}, | ||
| ); | ||
| }); | ||
|
|
||
| test('serializes user with undefined geo', async () => { | ||
| NATIVE.setUser({ | ||
| id: '123', | ||
| geo: undefined, | ||
| }); | ||
|
|
||
| expect(RNSentry.setUser).toBeCalledWith( | ||
| { | ||
| id: '123', | ||
| geo: undefined, | ||
| }, | ||
| {}, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('_processLevel', () => { | ||
|
|
||
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.