-
Notifications
You must be signed in to change notification settings - Fork 42
[SDK-149] add-logout-functionality #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
03d7967
954df65
900ee9c
f72f578
b9401df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,58 @@ describe('Iterable', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('logout', () => { | ||
| it('should call setEmail with null', () => { | ||
| // GIVEN no parameters | ||
| // WHEN Iterable.logout is called | ||
| const setEmailSpy = jest.spyOn(Iterable, 'setEmail'); | ||
| Iterable.logout(); | ||
| // THEN Iterable.setEmail is called with null | ||
| expect(setEmailSpy).toBeCalledWith(null); | ||
| setEmailSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should call setUserId with null', () => { | ||
| // GIVEN no parameters | ||
| // WHEN Iterable.logout is called | ||
| const setUserIdSpy = jest.spyOn(Iterable, 'setUserId'); | ||
| Iterable.logout(); | ||
| // THEN Iterable.setUserId is called with null | ||
| expect(setUserIdSpy).toBeCalledWith(null); | ||
| setUserIdSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('should clear email and userId', async () => { | ||
| // GIVEN a user is logged in | ||
|
|
||
| // This is just for testing purposed. | ||
| // Usually you'd either call `setEmail` or `setUserId`, but not both. | ||
| Iterable.setEmail('[email protected]'); | ||
| Iterable.setUserId('user123'); | ||
| // WHEN Iterable.logout is called | ||
| Iterable.logout(); | ||
| // THEN email and userId are set to null | ||
| const email = await Iterable.getEmail(); | ||
| const userId = await Iterable.getUserId(); | ||
| expect(email).toBeNull(); | ||
| expect(userId).toBeNull(); | ||
| }); | ||
|
|
||
| it('should call setEmail and setUserId with null', () => { | ||
| // GIVEN no parameters | ||
| const setEmailSpy = jest.spyOn(Iterable, 'setEmail'); | ||
| const setUserIdSpy = jest.spyOn(Iterable, 'setUserId'); | ||
| // WHEN Iterable.logout is called | ||
| Iterable.logout(); | ||
| // THEN both methods are called with null | ||
| expect(setEmailSpy).toBeCalledWith(null); | ||
| expect(setUserIdSpy).toBeCalledWith(null); | ||
| // Clean up | ||
| setEmailSpy.mockRestore(); | ||
| setUserIdSpy.mockRestore(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('disableDeviceForCurrentUser', () => { | ||
| it('should disable the device for the current user', () => { | ||
| // GIVEN no parameters | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -890,6 +890,34 @@ export class Iterable { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Logs out the current user from the Iterable SDK. | ||
| * | ||
| * This method will remove all event listeners for the Iterable SDK and set the email and user ID to null. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * Iterable.logout(); | ||
| * ``` | ||
| */ | ||
| static logout() { | ||
| Iterable.removeAllEventListeners(); | ||
| Iterable.setEmail(null); | ||
| Iterable.setUserId(null); | ||
| } | ||
|
|
||
| /** | ||
| * Removes all event listeners for the Iterable SDK. | ||
| */ | ||
| private static removeAllEventListeners() { | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleCustomActionCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthSuccessCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthFailureCalled); | ||
| } | ||
|
Comment on lines
+903
to
+919
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good |
||
|
|
||
| /** | ||
| * Sets up event handlers for various Iterable events. | ||
| * | ||
|
|
@@ -912,12 +940,7 @@ export class Iterable { | |
| */ | ||
| private static setupEventHandlers() { | ||
| // Remove all listeners to avoid duplicate listeners | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleUrlCalled); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleInAppCalled); | ||
| RNEventEmitter.removeAllListeners( | ||
| IterableEventName.handleCustomActionCalled | ||
| ); | ||
| RNEventEmitter.removeAllListeners(IterableEventName.handleAuthCalled); | ||
| Iterable.removeAllEventListeners(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catching all in one
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
|
||
| if (Iterable.savedConfig.urlHandler) { | ||
| RNEventEmitter.addListener(IterableEventName.handleUrlCalled, (dict) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email and userId usually dont go together.
When email is set and we call setUserId, it goes through logging out user with email id and then tries to log in.
So it should ideally be setEmail > logout > assernull for email
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know.. this doesn't call the internal functionality for setting user id
and email, so I'm just doing this as a test to make sure that both are cleared
later. I'll add a comment to address this.