Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Motivation: add coverage for new functionality, update default values for SW params
  • Loading branch information
rgomezp committed Dec 13, 2024
1 parent b9bcf32 commit 3e8261b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
8 changes: 4 additions & 4 deletions __test__/support/environment/TestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ export default class TestContext {
kind: configIntegrationKind,
},
serviceWorker: {
path: undefined,
workerName: undefined,
registrationScope: undefined,
customizationEnabled: true,
customizationEnabled: false,
path: '/',
workerName: 'OneSignalSDKWorker.js',
registrationScope: '/',
},
setupBehavior: {
allowLocalhostAsSecureOrigin: false,
Expand Down
46 changes: 46 additions & 0 deletions __test__/unit/helpers/configHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getFinalAppConfig } from '../../support/helpers/configHelper';
import { ConfigHelper } from '../../../src/shared/helpers/ConfigHelper';
import TestContext from '../../support/environment/TestContext';

const SERVICE_WORKER_PATH = 'push/onesignal/';

describe('ConfigHelper Tests', () => {
beforeEach(async () => {
await TestEnvironment.initialize();
Expand Down Expand Up @@ -200,4 +202,48 @@ describe('ConfigHelper Tests', () => {
);
expect(finalConfig.autoResubscribe).toBe(true);
});

test('service worker config override (true) for typical site works', () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
serviceWorkerOverrideForTypical: true,
}

const fakeServerConfig = TestContext.getFakeServerAppConfig(
ConfigIntegrationKind.TypicalSite,
);

const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind(
ConfigIntegrationKind.TypicalSite,
fakeUserConfig,
fakeServerConfig,
);

expect(finalConfig.serviceWorkerPath).toBe('push/onesignal/OneSignalSDKWorker.js');
expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/push/onesignal/' });
})

test('service worker config override (false) for typical site works', () => {
const fakeUserConfig: AppUserConfig = {
appId: getRandomUuid(),
serviceWorkerParam: { scope: '/' + SERVICE_WORKER_PATH },
serviceWorkerPath: SERVICE_WORKER_PATH + 'OneSignalSDKWorker.js',
serviceWorkerOverrideForTypical: false,
}

const fakeServerConfig = TestContext.getFakeServerAppConfig(
ConfigIntegrationKind.TypicalSite,
);

const finalConfig = ConfigHelper.getUserConfigForConfigIntegrationKind(
ConfigIntegrationKind.TypicalSite,
fakeUserConfig,
fakeServerConfig,
);

expect(finalConfig.serviceWorkerPath).toBe('OneSignalSDKWorker.js');
expect(finalConfig.serviceWorkerParam).toEqual({ scope: '/' });
})
});

0 comments on commit 3e8261b

Please sign in to comment.