Skip to content

Commit

Permalink
Test Reverb usage in local, test and live environments
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-magana committed Jan 21, 2025
1 parent cbe2490 commit ef38bd5
Showing 1 changed file with 65 additions and 13 deletions.
78 changes: 65 additions & 13 deletions src/app/lib/analyticsUtils/sendBeacon/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('sendBeacon', () => {
});

afterEach(() => {
fetch.resetMocks();
jest.clearAllMocks();
});

it(`should fetch`, () => {
Expand Down Expand Up @@ -61,20 +61,76 @@ describe('sendBeacon', () => {
},
};

it('should call Reverb viewEvent if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;
const originalProcessEnv = process.env;

await sendBeacon('https://foobar.com', reverbConfig);
afterEach(() => {
process.env = originalProcessEnv;
});

describe('LOCAL', () => {
beforeEach(() => {
process.env.SIMORGH_APP_ENV = 'local';
});

Check failure on line 74 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `······`
it('should call Reverb viewEvent if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

Check failure on line 77 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
await sendBeacon('https://foobar.com', reverbConfig);

Check failure on line 79 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
expect(reverbMock.viewEvent).toHaveBeenCalledTimes(1);
});

expect(reverbMock.viewEvent).toHaveBeenCalledTimes(1);
it('should not call "fetch" if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

Check failure on line 85 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
await sendBeacon('https://foobar.com', reverbConfig);

Check failure on line 87 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
expect(fetch).not.toHaveBeenCalled();
});
});

it('should not call "fetch" if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;
describe('TEST', () => {
beforeEach(() => {
process.env.SIMORGH_APP_ENV = 'test';
});

Check failure on line 96 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `······`
it('should call Reverb viewEvent if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

Check failure on line 99 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
await sendBeacon('https://foobar.com', reverbConfig);

Check failure on line 101 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
expect(reverbMock.viewEvent).toHaveBeenCalledTimes(1);
});

await sendBeacon('https://foobar.com', reverbConfig);
it('should not call "fetch" if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

Check failure on line 107 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
await sendBeacon('https://foobar.com', reverbConfig);

Check failure on line 109 in src/app/lib/analyticsUtils/sendBeacon/index.test.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `··`
expect(fetch).not.toHaveBeenCalled();
});
});

describe('LIVE', () => {
beforeEach(() => {
process.env.SIMORGH_APP_ENV = 'live';
});

it('should not call Reverb viewEvent if Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

await sendBeacon('https://foobar.com', reverbConfig);

expect(reverbMock.viewEvent).not.toHaveBeenCalled();
});

expect(fetch).not.toHaveBeenCalled();
it('should call "fetch" when Reverb config is passed', async () => {
const sendBeacon = require('./index').default;

await sendBeacon('https://foobar.com', reverbConfig);

expect(fetch).toHaveBeenCalledTimes(1);
});
});
});

Expand All @@ -86,10 +142,6 @@ describe('sendBeacon', () => {
fetchResponse = Promise.reject(error);
});

afterEach(() => {
jest.resetAllMocks();
});

it(`should send error to logger`, async () => {
const sendBeacon = require('./index').default;

Expand Down

0 comments on commit ef38bd5

Please sign in to comment.