diff --git a/CHANGELOG.md b/CHANGELOG.md index e19efb172c..280df46ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/js/wrapper.ts b/src/js/wrapper.ts index 16a3d9cbc1..208745368c 100644 --- a/src/js/wrapper.ts +++ b/src/js/wrapper.ts @@ -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); } diff --git a/test/wrapper.test.ts b/test/wrapper.test.ts index b912645581..ef67cd4b5f 100644 --- a/test/wrapper.test.ts +++ b/test/wrapper.test.ts @@ -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)) } }, @@ -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);