Skip to content

Commit 32667fc

Browse files
committed
fix tests
1 parent fef750d commit 32667fc

6 files changed

Lines changed: 33 additions & 55 deletions

File tree

__test__/setupTests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ vi.mock('src/core/operationRepo/constants', () => ({
2424
OP_REPO_EXECUTION_INTERVAL: 5,
2525
OP_REPO_POST_CREATE_RETRY_UP_TO: 10,
2626
}));
27+
28+
Object.defineProperty(navigator, 'userAgent', {
29+
value:
30+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.0.0 Safari/537.36',
31+
writable: true,
32+
});

__test__/unit/core/coreModuleDirector.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('CoreModuleDirector tests', () => {
3838
'getPushSubscriptionModelByLastKnownToken',
3939
// @ts-expect-error - private method
4040
).mockResolvedValue(pushModelLastKnown);
41-
expect(await getPushSubscriptionModel()).toBe(pushModelLastKnown);
41+
expect(await getPushSubscriptionModel()).toEqual(pushModelLastKnown);
4242
});
4343

4444
test('returns current subscription over last known', async () => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@
7272
},
7373
{
7474
"path": "./build/releases/OneSignalSDK.page.es6.js",
75-
"limit": "63.75 kB",
75+
"limit": "61.2 kB",
7676
"gzip": true
7777
},
7878
{
7979
"path": "./build/releases/OneSignalSDK.sw.js",
80-
"limit": "34 kB",
80+
"limit": "31.3 kB",
8181
"gzip": true
8282
},
8383
{

src/entries/pageSdkInit.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ import { server } from '__test__/support/mocks/server';
55
import { http, HttpResponse } from 'msw';
66
import Log from 'src/shared/libraries/Log';
77

8-
// need to mock browsercastle since we resetting modules after each test
9-
vi.mock('src/shared/utils/bowserCastle', () => ({
10-
bowserCastle: () => ({
11-
mobile: false,
12-
tablet: false,
13-
name: 'Chrome',
14-
version: '100',
15-
}),
16-
}));
17-
188
// need to wait for full OperationRepo rework
199
describe('pageSdkInit', () => {
2010
beforeEach(async () => {

src/sw/serviceWorker/ServiceWorker.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ describe('ServiceWorker', () => {
198198
});
199199

200200
test('should confirm delivery', async () => {
201-
mockBowser.mockReturnValue({
202-
name: 'Chrome',
203-
version: '130',
204-
});
205-
206201
const payload = mockOSMinifiedNotificationPayload({
207202
custom: {
208203
rr: 'y',
@@ -731,15 +726,6 @@ vi.mock('../helpers/ModelCacheDirectAccess', () => ({
731726
},
732727
}));
733728

734-
// -- browser info mock
735-
const mockBowser = vi.fn().mockReturnValue({
736-
name: 'Safari',
737-
version: '18',
738-
});
739-
vi.mock('../../../src/shared/utils/bowserCastle', () => ({
740-
bowserCastle: () => mockBowser(),
741-
}));
742-
743729
// -- awaitable timeout mock
744730
vi.mock('../../../src/shared/utils/AwaitableTimeout', () => ({
745731
awaitableTimeout: vi.fn().mockResolvedValue(undefined),

src/sw/serviceWorker/ServiceWorker.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
1-
import OneSignalApiBase from '../../../src/shared/api/OneSignalApiBase';
2-
import OneSignalApiSW from '../../../src/shared/api/OneSignalApiSW';
1+
import {
2+
NotificationType,
3+
type NotificationTypeValue,
4+
} from 'src/core/types/subscription';
5+
import FuturePushSubscriptionRecord from 'src/page/userModel/FuturePushSubscriptionRecord';
6+
import OneSignalApiBase from 'src/shared/api/OneSignalApiBase';
7+
import OneSignalApiSW from 'src/shared/api/OneSignalApiSW';
8+
import { type AppConfig, getServerAppConfig } from 'src/shared/config';
9+
import { Utils } from 'src/shared/context/Utils';
10+
import ServiceWorkerHelper from 'src/shared/helpers/ServiceWorkerHelper';
311
import {
412
WorkerMessenger,
513
WorkerMessengerCommand,
614
type WorkerMessengerMessage,
7-
} from '../../../src/shared/libraries/WorkerMessenger';
8-
import { RawPushSubscription } from '../../../src/shared/models/RawPushSubscription';
9-
import FuturePushSubscriptionRecord from '../../page/userModel/FuturePushSubscriptionRecord';
10-
import { Utils } from '../../shared/context/Utils';
11-
import ServiceWorkerHelper from '../../shared/helpers/ServiceWorkerHelper';
12-
import ContextSW from '../../shared/models/ContextSW';
15+
} from 'src/shared/libraries/WorkerMessenger';
16+
import ContextSW from 'src/shared/models/ContextSW';
17+
import type { DeliveryPlatformKindValue } from 'src/shared/models/DeliveryPlatformKind';
1318
import {
1419
type NotificationClickEventInternal,
1520
type NotificationForegroundWillDisplayEventSerializable,
16-
} from '../../shared/models/NotificationEvent';
21+
} from 'src/shared/models/NotificationEvent';
1722
import {
1823
type IMutableOSNotification,
1924
type IOSNotification,
20-
} from '../../shared/models/OSNotification';
25+
} from 'src/shared/models/OSNotification';
26+
import { RawPushSubscription } from 'src/shared/models/RawPushSubscription';
2127
import {
2228
type PageVisibilityRequest,
2329
type PageVisibilityResponse,
2430
SessionStatus,
2531
type UpsertOrDeactivateSessionPayload,
26-
} from '../../shared/models/Session';
27-
import { SubscriptionStrategyKind } from '../../shared/models/SubscriptionStrategyKind';
28-
import Database from '../../shared/services/Database';
29-
import { awaitableTimeout } from '../../shared/utils/AwaitableTimeout';
32+
} from 'src/shared/models/Session';
33+
import { SubscriptionStrategyKind } from 'src/shared/models/SubscriptionStrategyKind';
34+
import Database from 'src/shared/services/Database';
35+
import { Browser, getBrowserName } from 'src/shared/useragent';
36+
import { awaitableTimeout } from 'src/shared/utils/AwaitableTimeout';
37+
import { VERSION } from 'src/shared/utils/EnvVariables';
3038
import { cancelableTimeout } from '../helpers/CancelableTimeout';
39+
import { ModelCacheDirectAccess } from '../helpers/ModelCacheDirectAccess';
3140
import Log from '../libraries/Log';
3241
import {
3342
type OSMinifiedNotificationPayload,
3443
OSMinifiedNotificationPayloadHelper,
3544
} from '../models/OSMinifiedNotificationPayload';
36-
import {
37-
type OSServiceWorkerFields,
38-
type SubscriptionChangeEvent,
39-
} from './types';
40-
41-
import {
42-
NotificationType,
43-
type NotificationTypeValue,
44-
} from 'src/core/types/subscription';
45-
import { type AppConfig, getServerAppConfig } from 'src/shared/config';
46-
import type { DeliveryPlatformKindValue } from 'src/shared/models/DeliveryPlatformKind';
47-
import { Browser, getBrowserName } from 'src/shared/useragent';
48-
import { VERSION } from 'src/shared/utils/EnvVariables';
49-
import { ModelCacheDirectAccess } from '../helpers/ModelCacheDirectAccess';
5045
import { OSNotificationButtonsConverter } from '../models/OSNotificationButtonsConverter';
5146
import { OSWebhookNotificationEventSender } from '../webhooks/notifications/OSWebhookNotificationEventSender';
47+
import type { OSServiceWorkerFields, SubscriptionChangeEvent } from './types';
5248

5349
declare const self: ServiceWorkerGlobalScope & OSServiceWorkerFields;
5450

0 commit comments

Comments
 (0)