Skip to content

Commit 9d144c1

Browse files
committed
more pr feedback
1 parent b493c1d commit 9d144c1

File tree

7 files changed

+88
-55
lines changed

7 files changed

+88
-55
lines changed

mocks/deepmerge.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,39 @@ export type DeepPartial<T> = T extends Function
88
? { [K in keyof T]?: DeepPartial<T[K]> }
99
: T;
1010

11+
/**
12+
* Recursively merges a patch object into a target object.
13+
*
14+
* Behavior:
15+
* - Primitive values, nulls, and functions from patch replace target values
16+
* - Arrays from patch replace target arrays entirely
17+
* - Plain objects are recursively merged
18+
* - Undefined values in patch are skipped (target values are preserved)
19+
*
20+
* @template T - The type of the target object
21+
* @param target - The base object to merge into
22+
* @param patch - The partial object with values to merge; undefined/null values are ignored
23+
* @returns A new merged object of type T
24+
*
25+
* @example
26+
* const base = {
27+
* name: "John",
28+
* tags: ["a", "b"],
29+
* address: { city: "NYC", zip: "10001" }
30+
* };
31+
* const patch = {
32+
* tags: ["x", "y", "z"], // array replaced entirely
33+
* address: { city: "LA" }, // merged (zip kept from base)
34+
* email: "[email protected]" // new property added
35+
* };
36+
* const result = deepMerge(base, patch);
37+
* // Result: {
38+
* // name: "John",
39+
* // tags: ["x", "y", "z"],
40+
* // address: { city: "LA", zip: "10001" },
41+
* // email: "[email protected]"
42+
* // }
43+
*/
1144
export function deepMerge<T>(target: T, patch: DeepPartial<T>): T {
1245
if (patch === undefined || patch === null) return target;
1346

@@ -38,5 +71,3 @@ export function deepMerge<T>(target: T, patch: DeepPartial<T>): T {
3871

3972
return out as T;
4073
}
41-
42-
export const asDeepPartial = <T>(v: DeepPartial<T>) => v;

www/DebugNamespace.test.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,48 @@ describe('Debug', () => {
1414
});
1515

1616
test.each([
17-
[LogLevel.None],
18-
[LogLevel.Fatal],
19-
[LogLevel.Error],
20-
[LogLevel.Warn],
21-
[LogLevel.Info],
22-
[LogLevel.Debug],
23-
[LogLevel.Verbose],
24-
])('should call cordova.exec for setLogLevel with %s', (logLevel) => {
25-
debug.setLogLevel(logLevel);
17+
[LogLevel.None, 0],
18+
[LogLevel.Fatal, 1],
19+
[LogLevel.Error, 2],
20+
[LogLevel.Warn, 3],
21+
[LogLevel.Info, 4],
22+
[LogLevel.Debug, 5],
23+
[LogLevel.Verbose, 6],
24+
])(
25+
'should call cordova.exec for setLogLevel with %s',
26+
(logLevel, logLevelValue) => {
27+
debug.setLogLevel(logLevel);
2628

27-
expect(window.cordova.exec).toHaveBeenCalledWith(
28-
expect.any(Function),
29-
expect.any(Function),
30-
'OneSignalPush',
31-
'setLogLevel',
32-
[logLevel],
33-
);
34-
});
29+
expect(window.cordova.exec).toHaveBeenCalledWith(
30+
expect.any(Function),
31+
expect.any(Function),
32+
'OneSignalPush',
33+
'setLogLevel',
34+
[logLevelValue],
35+
);
36+
},
37+
);
3538

3639
test.each([
37-
[LogLevel.None],
38-
[LogLevel.Fatal],
39-
[LogLevel.Error],
40-
[LogLevel.Warn],
41-
[LogLevel.Info],
42-
[LogLevel.Debug],
43-
[LogLevel.Verbose],
44-
])('should call cordova.exec for setAlertLevel with %s', (logLevel) => {
45-
debug.setAlertLevel(logLevel);
40+
[LogLevel.None, 0],
41+
[LogLevel.Fatal, 1],
42+
[LogLevel.Error, 2],
43+
[LogLevel.Warn, 3],
44+
[LogLevel.Info, 4],
45+
[LogLevel.Debug, 5],
46+
[LogLevel.Verbose, 6],
47+
])(
48+
'should call cordova.exec for setAlertLevel with %s',
49+
(logLevel, logLevelValue) => {
50+
debug.setAlertLevel(logLevel);
4651

47-
expect(window.cordova.exec).toHaveBeenCalledWith(
48-
expect.any(Function),
49-
expect.any(Function),
50-
'OneSignalPush',
51-
'setAlertLevel',
52-
[logLevel],
53-
);
54-
});
52+
expect(window.cordova.exec).toHaveBeenCalledWith(
53+
expect.any(Function),
54+
expect.any(Function),
55+
'OneSignalPush',
56+
'setAlertLevel',
57+
[logLevelValue],
58+
);
59+
},
60+
);
5561
});

www/InAppMessagesNamespace.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
InAppMessageDidDisplayEvent,
88
InAppMessageWillDisplayEvent,
99
} from './types/InAppMessage';
10+
1011
describe('InAppMessages', () => {
1112
let inAppMessages: InAppMessages;
1213

www/NotificationsNamespace.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Notifications, {
55
OSNotificationPermission,
66
} from './NotificationsNamespace';
77
import * as helpers from './helpers';
8+
89
describe('Notifications', () => {
910
let notifications: Notifications;
1011

@@ -176,6 +177,9 @@ describe('Notifications', () => {
176177
mockExec.mockImplementation((resolve, reject) => {
177178
reject(mockError);
178179
});
180+
await expect(notifications.canRequestPermission()).rejects.toThrow(
181+
mockError.message,
182+
);
179183
});
180184
});
181185

@@ -348,18 +352,6 @@ describe('Notifications', () => {
348352
[notificationId],
349353
);
350354
});
351-
352-
test('should call cordova.exec for removeNotification with different IDs', () => {
353-
notifications.removeNotification(456);
354-
355-
expect(window.cordova.exec).toHaveBeenCalledWith(
356-
expect.any(Function),
357-
expect.any(Function),
358-
'OneSignalPush',
359-
'removeNotification',
360-
[456],
361-
);
362-
});
363355
});
364356

365357
describe('removeGroupedNotifications', () => {
@@ -391,7 +383,7 @@ describe('Notifications', () => {
391383
expect(result).toBe(true);
392384
});
393385

394-
test('should return test when permission is set via permission listener', () => {
386+
test('should return true when permission is set via permission listener', () => {
395387
notifications._setPropertyAndObserver();
396388
const callback = mockExec.mock.calls.find(
397389
(call) => call[3] === 'addPermissionObserver',

www/OSNotification.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { mockCordova } from '../mocks/cordova';
2-
import { OSNotification } from './OSNotification';
2+
import { OSNotification, type ReceivedEvent } from './OSNotification';
33

4-
type RequireOptional<T> = Required<T>;
5-
type AllProperties = RequireOptional<Omit<OSNotification, 'display'>>;
4+
type AllProperties = Required<Omit<ReceivedEvent, 'display'>>;
65

76
describe('OSNotification', () => {
87
beforeEach(() => {

www/OSNotification.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { noop } from './helpers';
22

3+
export type ReceivedEvent = Omit<OSNotification, 'display' | 'rawPayload'> & {
4+
rawPayload: string | object;
5+
};
6+
37
export class OSNotification {
48
body: string;
59
sound?: string;
610
title?: string;
711
launchURL?: string;
8-
rawPayload: string | object;
12+
rawPayload: object;
913
actionButtons?: object[];
1014
additionalData: object;
1115
notificationId: string;
@@ -37,7 +41,7 @@ export class OSNotification {
3741
relevanceScore?: number;
3842
interruptionLevel?: string;
3943

40-
constructor(receivedEvent: Omit<OSNotification, 'display'>) {
44+
constructor(receivedEvent: ReceivedEvent) {
4145
/// The OneSignal notification ID for this notification
4246
this.notificationId = receivedEvent.notificationId;
4347

www/PushSubscriptionNamespace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('PushSubscription', () => {
217217
});
218218

219219
describe('addEventListener', () => {
220-
test('should add listener to observer list and call cordova.exec', () => {
220+
test('add listener should call cordova.exec', () => {
221221
const mockListener = vi.fn();
222222

223223
pushSubscription.addEventListener('change', mockListener);

0 commit comments

Comments
 (0)