-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1456 from bugsnag/bengourley/browser-device-id-de…
…fault-user-id [PLAT-5052] feat(plugin-browser-device): Use device id as default user id
- Loading branch information
Showing
7 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import Client, { | |
} from '@bugsnag/core/client' | ||
import { Device, Session } from '@bugsnag/core' | ||
import EventWithInternals from '@bugsnag/core/event' | ||
import { schema } from '@bugsnag/core/config' | ||
|
||
declare class SessionWithDevice extends Session { public device: Device } | ||
|
||
|
@@ -457,5 +458,98 @@ describe('plugin: device', () => { | |
expect(sessions).toHaveLength(1) | ||
expect(sessions[0].device.id).toBe(events[0].device.id) | ||
}) | ||
|
||
it('should not set device.id as user.id when collectUserIp=true', () => { | ||
const client = new Client( | ||
{ apiKey: 'API_KEY_YEAH' }, | ||
{ | ||
...schema, | ||
collectUserIp: { | ||
defaultValue: () => true, | ||
validate: () => true, | ||
message: '' | ||
} | ||
}, | ||
[plugin(navigator)] | ||
) | ||
const events: EventWithInternals[] = [] | ||
const sessions: SessionWithDevice[] = [] | ||
|
||
expect(client._cbs.e).toHaveLength(1) | ||
|
||
mockDelivery(client, events, sessions) | ||
client.notify(new Error('noooo')) | ||
|
||
expect(events).toHaveLength(1) | ||
expect(events[0]._user.id).toBe(undefined) | ||
|
||
client.startSession() | ||
|
||
expect(sessions).toHaveLength(1) | ||
expect(sessions[0].getUser().id).toBe(undefined) | ||
}) | ||
|
||
it('should set device.id as user.id when collectUserIp=false', () => { | ||
const client = new Client( | ||
{ apiKey: 'API_KEY_YEAH', collectUserIp: false }, | ||
{ | ||
...schema, | ||
collectUserIp: { | ||
defaultValue: () => true, | ||
validate: () => true, | ||
message: '' | ||
} | ||
}, | ||
[plugin(navigator)] | ||
) | ||
const events: EventWithInternals[] = [] | ||
const sessions: SessionWithDevice[] = [] | ||
|
||
expect(client._cbs.e).toHaveLength(1) | ||
|
||
mockDelivery(client, events, sessions) | ||
client.notify(new Error('noooo')) | ||
|
||
expect(events).toHaveLength(1) | ||
expect(events[0]._user.id).toBeTruthy() | ||
expect(events[0]._user.id).toBe(events[0].device.id) | ||
|
||
client.startSession() | ||
|
||
expect(sessions).toHaveLength(1) | ||
expect(sessions[0].getUser().id).toBeTruthy() | ||
expect(sessions[0].getUser().id).toBe(events[0].device.id) | ||
}) | ||
|
||
it('should not replace an existing user.id with device.id', () => { | ||
const client = new Client( | ||
{ apiKey: 'API_KEY_YEAH', collectUserIp: false }, | ||
{ | ||
...schema, | ||
collectUserIp: { | ||
defaultValue: () => true, | ||
validate: () => true, | ||
message: '' | ||
} | ||
}, | ||
[plugin(navigator)] | ||
) | ||
const events: EventWithInternals[] = [] | ||
const sessions: SessionWithDevice[] = [] | ||
|
||
expect(client._cbs.e).toHaveLength(1) | ||
|
||
mockDelivery(client, events, sessions) | ||
client.setUser('123', '[email protected]', 'User Email') | ||
client.notify(new Error('noooo')) | ||
|
||
expect(events).toHaveLength(1) | ||
expect(events[0]._user.id).toBe('123') | ||
|
||
client.startSession() | ||
|
||
expect(sessions).toHaveLength(1) | ||
expect(sessions[0].getUser().id).toBe('123') | ||
}) | ||
}) | ||
}) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script src="/node_modules/@bugsnag/browser/dist/bugsnag.min.js"></script> | ||
<script type="text/javascript"> | ||
var NOTIFY = decodeURIComponent(window.location.search.match(/NOTIFY=([^&]+)/)[1]) | ||
var SESSIONS = decodeURIComponent(window.location.search.match(/SESSIONS=([^&]+)/)[1]) | ||
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1]) | ||
Bugsnag.start({ | ||
apiKey: API_KEY, | ||
endpoints: { notify: NOTIFY, sessions: SESSIONS }, | ||
collectUserIp: false | ||
}) | ||
</script> | ||
</head> | ||
<body> | ||
<script> | ||
Bugsnag.notify(new Error('user info does work')) | ||
</script> | ||
</body> | ||
</html> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script src="/node_modules/@bugsnag/browser/dist/bugsnag.min.js"></script> | ||
<script type="text/javascript"> | ||
var NOTIFY = decodeURIComponent(window.location.search.match(/NOTIFY=([^&]+)/)[1]) | ||
var SESSIONS = decodeURIComponent(window.location.search.match(/SESSIONS=([^&]+)/)[1]) | ||
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1]) | ||
Bugsnag.start({ | ||
apiKey: API_KEY, | ||
endpoints: { notify: NOTIFY, sessions: SESSIONS }, | ||
collectUserIp: false | ||
}) | ||
</script> | ||
</head> | ||
<body> | ||
<script> | ||
Bugsnag.setUser('123', '[email protected]', 'User Email') | ||
Bugsnag.notify(new Error('user info does work')) | ||
</script> | ||
</body> | ||
</html> |
This file contains 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 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