@@ -74,6 +74,58 @@ describe('Iterable', () => {
7474 } ) ;
7575 } ) ;
7676
77+ describe ( 'logout' , ( ) => {
78+ it ( 'should call setEmail with null' , ( ) => {
79+ // GIVEN no parameters
80+ // WHEN Iterable.logout is called
81+ const setEmailSpy = jest . spyOn ( Iterable , 'setEmail' ) ;
82+ Iterable . logout ( ) ;
83+ // THEN Iterable.setEmail is called with null
84+ expect ( setEmailSpy ) . toBeCalledWith ( null ) ;
85+ setEmailSpy . mockRestore ( ) ;
86+ } ) ;
87+
88+ it ( 'should call setUserId with null' , ( ) => {
89+ // GIVEN no parameters
90+ // WHEN Iterable.logout is called
91+ const setUserIdSpy = jest . spyOn ( Iterable , 'setUserId' ) ;
92+ Iterable . logout ( ) ;
93+ // THEN Iterable.setUserId is called with null
94+ expect ( setUserIdSpy ) . toBeCalledWith ( null ) ;
95+ setUserIdSpy . mockRestore ( ) ;
96+ } ) ;
97+
98+ it ( 'should clear email and userId' , async ( ) => {
99+ // GIVEN a user is logged in
100+
101+ // This is just for testing purposed.
102+ // Usually you'd either call `setEmail` or `setUserId`, but not both.
103+ Iterable . setEmail ( 'user@example.com' ) ;
104+ Iterable . setUserId ( 'user123' ) ;
105+ // WHEN Iterable.logout is called
106+ Iterable . logout ( ) ;
107+ // THEN email and userId are set to null
108+ const email = await Iterable . getEmail ( ) ;
109+ const userId = await Iterable . getUserId ( ) ;
110+ expect ( email ) . toBeNull ( ) ;
111+ expect ( userId ) . toBeNull ( ) ;
112+ } ) ;
113+
114+ it ( 'should call setEmail and setUserId with null' , ( ) => {
115+ // GIVEN no parameters
116+ const setEmailSpy = jest . spyOn ( Iterable , 'setEmail' ) ;
117+ const setUserIdSpy = jest . spyOn ( Iterable , 'setUserId' ) ;
118+ // WHEN Iterable.logout is called
119+ Iterable . logout ( ) ;
120+ // THEN both methods are called with null
121+ expect ( setEmailSpy ) . toBeCalledWith ( null ) ;
122+ expect ( setUserIdSpy ) . toBeCalledWith ( null ) ;
123+ // Clean up
124+ setEmailSpy . mockRestore ( ) ;
125+ setUserIdSpy . mockRestore ( ) ;
126+ } ) ;
127+ } ) ;
128+
77129 describe ( 'disableDeviceForCurrentUser' , ( ) => {
78130 it ( 'should disable the device for the current user' , ( ) => {
79131 // GIVEN no parameters
0 commit comments