Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-zimerman committed Jul 6, 2023
1 parent 63c8eac commit 3415528
Showing 1 changed file with 72 additions and 12 deletions.
84 changes: 72 additions & 12 deletions test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,66 @@ describe('Tests Native Wrapper', () => {
expect(logger.warn).toHaveBeenLastCalledWith('Note: Native Sentry SDK is disabled.');
});

test('filter beforeSend when initializing Native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
beforeSend: jest.fn()
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSend');
expect(NATIVE.enableNative).toBe(true);
});

test('filter beforeSend when initializing Native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
beforeSend: jest.fn()
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSend');
expect(NATIVE.enableNative).toBe(true);
});

test('filter beforeSend when initializing Native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
beforeSend: jest.fn()
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSend');
expect(NATIVE.enableNative).toBe(true);
});

test('filter beforeBreadcrumb when initializing Native SDK', async () => {
await NATIVE.initNativeSdk({
dsn: 'test',
enableNative: true,
autoInitializeNativeSdk: true,
beforeBreadcrumb: jest.fn()
});

expect(RNSentry.initNativeSdk).toBeCalled();
// @ts-ignore mock value
const initParameter = RNSentry.initNativeSdk.mock.calls[0][0];
expect(initParameter).not.toHaveProperty('beforeSendTransaction');
expect(NATIVE.enableNative).toBe(true);
});

test('does not initialize with autoInitializeNativeSdk: false', async () => {
NATIVE.enableNative = false;
logger.warn = jest.fn();
Expand Down Expand Up @@ -215,8 +275,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":87}\n' +
'{"event_id":"event0","message":"test","sdk":{"name":"test-sdk-name","version":"2.1.3"}}\n',
'{"type":"event","content_type":"application/json","length":87}\n' +
'{"event_id":"event0","message":"test","sdk":{"name":"test-sdk-name","version":"2.1.3"}}\n',
),
{ store: false },
);
Expand Down Expand Up @@ -245,8 +305,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":93}\n' +
'{"event_id":"event0","sdk":{"name":"test-sdk-name","version":"2.1.3"},"instance":{"value":0}}\n',
'{"type":"event","content_type":"application/json","length":93}\n' +
'{"event_id":"event0","sdk":{"name":"test-sdk-name","version":"2.1.3"},"instance":{"value":0}}\n',
),
{ store: false },
);
Expand Down Expand Up @@ -280,8 +340,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":50}\n' +
'{"event_id":"event0","message":{"message":"test"}}\n',
'{"type":"event","content_type":"application/json","length":50}\n' +
'{"event_id":"event0","message":{"message":"test"}}\n',
),
{ store: false },
);
Expand Down Expand Up @@ -317,8 +377,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":104}\n' +
'{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":true,"type":""}}]},"breadcrumbs":[]}\n',
'{"type":"event","content_type":"application/json","length":104}\n' +
'{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":true,"type":""}}]},"breadcrumbs":[]}\n',
),
{ store: false },
);
Expand All @@ -344,8 +404,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":38}\n' +
'{"event_id":"event0","breadcrumbs":[]}\n',
'{"type":"event","content_type":"application/json","length":38}\n' +
'{"event_id":"event0","breadcrumbs":[]}\n',
),
{ store: false },
);
Expand Down Expand Up @@ -381,8 +441,8 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.captureEnvelope).toBeCalledWith(
utf8ToBytes(
'{"event_id":"event0","sent_at":"123"}\n' +
'{"type":"event","content_type":"application/json","length":125}\n' +
'{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":false,"type":""}}]},"breadcrumbs":[{"message":"crumb!"}]}\n',
'{"type":"event","content_type":"application/json","length":125}\n' +
'{"event_id":"event0","exception":{"values":[{"mechanism":{"handled":false,"type":""}}]},"breadcrumbs":[{"message":"crumb!"}]}\n',
),
{ store: true },
);
Expand Down

0 comments on commit 3415528

Please sign in to comment.