|
1 | | -import { APP_ID } from '__test__/support/constants'; |
| 1 | +import { APP_ID, DUMMY_ONESIGNAL_ID } from '__test__/support/constants'; |
2 | 2 | import { TestEnvironment } from '__test__/support/environment/TestEnvironment'; |
3 | 3 | import { mockServerConfig } from '__test__/support/helpers/configHelper'; |
4 | 4 | import { server } from '__test__/support/mocks/server'; |
@@ -31,7 +31,6 @@ describe('pageSdkInit', () => { |
31 | 31 | afterEach(async () => { |
32 | 32 | vi.resetModules(); |
33 | 33 | localStorage.clear(); |
34 | | - sessionStorage.clear(); |
35 | 34 | OneSignal._initCalled = false; |
36 | 35 | }); |
37 | 36 |
|
@@ -70,4 +69,41 @@ describe('pageSdkInit', () => { |
70 | 69 | await vi.runOnlyPendingTimersAsync(); |
71 | 70 | expect(initSpy).toHaveBeenCalled(); |
72 | 71 | }); |
| 72 | + |
| 73 | + test('multiple addEmail/addSms calls should not create duplicate subscriptions', async () => { |
| 74 | + server.use( |
| 75 | + http.post('**/apps/*/users', () => |
| 76 | + HttpResponse.json({ |
| 77 | + identity: { |
| 78 | + onesignal_id: DUMMY_ONESIGNAL_ID, |
| 79 | + }, |
| 80 | + }), |
| 81 | + ), |
| 82 | + http.post('**/apps/*/users/by/onesignal_id/*/subscriptions', () => |
| 83 | + HttpResponse.json({ |
| 84 | + identity: { |
| 85 | + onesignal_id: DUMMY_ONESIGNAL_ID, |
| 86 | + }, |
| 87 | + }), |
| 88 | + ), |
| 89 | + ); |
| 90 | + |
| 91 | + window.OneSignalDeferred = window.OneSignalDeferred || []; |
| 92 | + window.OneSignalDeferred.push(async function (OneSignal) { |
| 93 | + await OneSignal.init({ appId: APP_ID }); |
| 94 | + await OneSignal.User.addEmail('jd@mail.com'); |
| 95 | + await OneSignal.User.addEmail('jd@mail.com'); |
| 96 | + await OneSignal.User.addSms('1234567890'); |
| 97 | + await OneSignal.User.addSms('1234567890'); |
| 98 | + }); |
| 99 | + await import('./pageSdkInit'); |
| 100 | + |
| 101 | + await vi.advanceTimersByTimeAsync(30000); |
| 102 | + const emailSubscriptions = |
| 103 | + OneSignal.coreDirector.getEmailSubscriptionModels(); |
| 104 | + expect(Object.keys(emailSubscriptions).length).toBe(1); |
| 105 | + |
| 106 | + const smsSubscriptions = OneSignal.coreDirector.getSmsSubscriptionModels(); |
| 107 | + expect(Object.keys(smsSubscriptions).length).toBe(1); |
| 108 | + }); |
73 | 109 | }); |
0 commit comments