Skip to content
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

fix: Serialize the default user keys in setUser #926

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fix: Serialize the default user keys in setUser #926

## 1.4.5

- fix: Fix Native Wrapper not checking enableNative setting #919
Expand Down
4 changes: 2 additions & 2 deletions src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ export const NATIVE = {
let otherUserKeys = null;
if (user) {
const { id, ip_address, email, username, ...otherKeys } = user;
defaultUserKeys = {
defaultUserKeys = this._serializeObject({
email,
id,
ip_address,
username,
};
});
otherUserKeys = this._serializeObject(otherKeys);
}

Expand Down
26 changes: 26 additions & 0 deletions test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jest.mock(
nativeClientAvailable: true,
nativeTransport: true,
sendEvent: jest.fn(() => Promise.resolve()),
setUser: jest.fn(() => {
return;
}),
startWithOptions: jest.fn((options) => Promise.resolve(options))
}
},
Expand Down Expand Up @@ -177,6 +180,29 @@ describe("Tests Native Wrapper", () => {
});
});

describe("setUser", () => {
test("serializes all user object keys", async () => {
const RN = require("react-native");

NATIVE.setUser({
email: "hello@sentry.io",
// @ts-ignore
id: 3.14159265359,
unique: 123,
});
// tslint:disable-next-line: no-unsafe-any
expect(RN.NativeModules.RNSentry.setUser).toBeCalledWith(
{
email: "hello@sentry.io",
id: "3.14159265359",
},
{
unique: "123",
}
);
});
});

describe("isNativeClientAvailable", () => {
test("checks if native client is available", () => {
expect(NATIVE.isNativeClientAvailable()).toBe(true);
Expand Down