@@ -18,6 +18,7 @@ import OneSignalUtils from '../../../../src/utils/OneSignalUtils';
1818import { setupFakePlayerId } from '../../../support/tester/utils' ;
1919import * as awaitableTimeout from '../../../../src/utils/AwaitableTimeout' ;
2020import { NockOneSignalHelper } from '../../../../test/support/tester/NockOneSignalHelper' ;
21+ import { ConfigIntegrationKind } from '../../../../src/models/AppConfig' ;
2122
2223declare var self : MockServiceWorkerGlobalScope ;
2324
@@ -260,6 +261,38 @@ test('onNotificationClicked - notification PUT Before openWindow', async t => {
260261 t . deepEqual ( callOrder , [ "notificationPut" , "openWindow" ] ) ;
261262} ) ;
262263
264+ test ( 'onNotificationClicked - get web config before open if empty in database' , async t => {
265+ await Database . remove ( "Options" , "defaultUrl" ) ;
266+
267+ // Assert the URL is empty in the database
268+ const urlBefore = await Database . get ( "Options" , "defaultUrl" ) ;
269+ t . true ( urlBefore === undefined || urlBefore === null ) ;
270+
271+ const serverConfig = TestEnvironment . getFakeServerAppConfig ( ConfigIntegrationKind . Custom , false , null , appConfig . appId ) ;
272+ t . is ( serverConfig . config . origin , "http://localhost:3000" ) ;
273+ const webConfigNock = NockOneSignalHelper . nockGetConfig ( appConfig . appId , serverConfig ) ;
274+
275+ const notificationId = Random . getRandomUuid ( ) ;
276+
277+ const callOrder : string [ ] = [ ] ;
278+ sandbox . stub ( self . clients , "openWindow" , function ( ) {
279+ callOrder . push ( "openWindow" ) ;
280+ } ) ;
281+
282+ const notificationPutCall = NockOneSignalHelper . nockNotificationPut ( notificationId ) ;
283+
284+ const notificationEvent = mockNotificationNotificationEventInit ( notificationId ) ;
285+ await OSServiceWorker . onNotificationClicked ( notificationEvent ) ;
286+
287+ t . true ( webConfigNock . nockScope . isDone ( ) ) ;
288+ t . true ( notificationPutCall . nockScope . isDone ( ) ) ;
289+ t . deepEqual ( callOrder , [ "notificationPut" , "openWindow" ] ) ;
290+
291+ // Assert the URL is set after the handler runs
292+ const urlAfter = await Database . get ( "Options" , "defaultUrl" ) ;
293+ t . is ( urlAfter , "http://localhost:3000" ) ;
294+ } ) ;
295+
263296/***************************************************
264297 * sendConfirmedDelivery()
265298 ****************************************************/
0 commit comments