Skip to content

test(browser): Add integration tests for setUser #4344

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 4 commits into from
Dec 22, 2021
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
7 changes: 7 additions & 0 deletions packages/integration-tests/suites/public-api/setUser/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
});
11 changes: 11 additions & 0 deletions packages/integration-tests/suites/public-api/setUser/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
</head>
<body>
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Sentry.captureMessage('no_user');

Sentry.setUser({
id: 'foo',
ip_address: 'bar',
other_key: 'baz',
});

Sentry.captureMessage('user');

Sentry.setUser(null);

Sentry.captureMessage('unset_user');
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { getMultipleSentryRequests } from '../../../../utils/helpers';

sentryTest('should unset user', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getMultipleSentryRequests(page, 3, url);

expect(eventData[0].message).toBe('no_user');
expect(eventData[0].user).toBeUndefined();

expect(eventData[1].message).toBe('user');
expect(eventData[1].user).toMatchObject({
id: 'foo',
ip_address: 'bar',
other_key: 'baz',
});

expect(eventData[2].message).toBe('unset_user');
expect(eventData[2].user).toBeUndefined();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Sentry.setUser({
id: 'foo',
ip_address: 'bar',
});

Sentry.captureMessage('first_user');

Sentry.setUser({
id: 'baz',
});

Sentry.captureMessage('second_user');
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../../utils/fixtures';
import { getMultipleSentryRequests } from '../../../../utils/helpers';

sentryTest('should update user', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getMultipleSentryRequests(page, 2, url);

expect(eventData[0].message).toBe('first_user');
expect(eventData[0].user).toMatchObject({
id: 'foo',
ip_address: 'bar',
});

expect(eventData[1].message).toBe('second_user');
expect(eventData[1].user).toMatchObject({
id: 'baz',
});
});