File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 8585 },
8686 {
8787 "path" : " ./build/releases/OneSignalSDK.page.es6.js" ,
88- "limit" : " 46.23 kB" ,
88+ "limit" : " 46.24 kB" ,
8989 "gzip" : true
9090 },
9191 {
Original file line number Diff line number Diff line change @@ -63,8 +63,20 @@ describe('LoginManager', () => {
6363 ) ;
6464 } ) ;
6565
66- test ( 'logout: with external id resets models and creates anonymous user' , async ( ) => {
66+ test ( 'logout: with external id and no subscriptions resets models and skips user creation ' , async ( ) => {
6767 await updateIdentityModel ( 'external_id' , 'abc' ) ;
68+ await LoginManager . logout ( ) ;
69+ expect ( createUserOnServerSpy ) . not . toHaveBeenCalled ( ) ;
70+ } ) ;
71+
72+ test ( 'logout: with external id and a subscription resets models and creates anonymous user' , async ( ) => {
73+ await updateIdentityModel ( 'external_id' , 'abc' ) ;
74+ const mockSub = { id : 'sub-id' } as SubscriptionModel ;
75+ vi . spyOn (
76+ OneSignal . _coreDirector . _subscriptionModelStore ,
77+ '_list' ,
78+ ) . mockReturnValue ( [ mockSub ] ) ;
79+
6880 await LoginManager . logout ( ) ;
6981 expect ( createUserOnServerSpy ) . toHaveBeenCalled ( ) ;
7082 } ) ;
Original file line number Diff line number Diff line change @@ -93,9 +93,15 @@ export default class LoginManager {
9393 if ( ! identityModel . _externalId )
9494 return Log . _debug ( 'Logout: User is not logged in, skipping logout' ) ;
9595
96+ const hasAnySubscription =
97+ OneSignal . _coreDirector . _subscriptionModelStore . _list ( ) . length > 0 ;
98+
9699 resetUserModels ( ) ;
97100
98- // create a new anonymous user
99- return createUserOnServer ( ) ;
101+ // Only create an anonymous user if there is a subscription to associate with it.
102+ // Without a subscription, there is nothing meaningful to register on the server.
103+ if ( hasAnySubscription ) {
104+ return createUserOnServer ( ) ;
105+ }
100106 }
101107}
You can’t perform that action at this time.
0 commit comments