Skip to content

Commit

Permalink
fix: Preserve original user data for explicitly updated scopes (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek authored Oct 22, 2020
1 parent d03b406 commit 1c72bf9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class Scope implements ScopeInterface {
this._tags = { ...this._tags, ...captureContext._tags };
this._extra = { ...this._extra, ...captureContext._extra };
this._contexts = { ...this._contexts, ...captureContext._contexts };
if (captureContext._user) {
if (captureContext._user && Object.keys(captureContext._user).length) {
this._user = captureContext._user;
}
if (captureContext._level) {
Expand Down
20 changes: 20 additions & 0 deletions packages/hub/test/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,26 @@ describe('Scope', () => {
expect(updatedScope._fingerprint).toEqual(['bar']);
});

test('given an empty instance of Scope, it should preserve all the original scope data', () => {
const updatedScope = scope.update(new Scope()) as any;

expect(updatedScope._tags).toEqual({
bar: '2',
foo: '1',
});
expect(updatedScope._extra).toEqual({
bar: '2',
foo: '1',
});
expect(updatedScope._contexts).toEqual({
bar: { id: '2' },
foo: { id: '1' },
});
expect(updatedScope._user).toEqual({ id: '1337' });
expect(updatedScope._level).toEqual(Severity.Info);
expect(updatedScope._fingerprint).toEqual(['foo']);
});

test('given a plain object, it should merge two together, with the passed object having priority', () => {
const localAttributes = {
contexts: { bar: { id: '3' }, baz: { id: '4' } },
Expand Down

0 comments on commit 1c72bf9

Please sign in to comment.