Skip to content

Commit 900ee9c

Browse files
committed
test: add unit tests for Iterable.logout method to verify functionality
1 parent 954df65 commit 900ee9c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/core/classes/Iterable.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,55 @@ 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+
Iterable.setEmail('[email protected]');
101+
Iterable.setUserId('user123');
102+
// WHEN Iterable.logout is called
103+
Iterable.logout();
104+
// THEN email and userId are set to null
105+
const email = await Iterable.getEmail();
106+
const userId = await Iterable.getUserId();
107+
expect(email).toBeNull();
108+
expect(userId).toBeNull();
109+
});
110+
111+
it('should call setEmail and setUserId with null', () => {
112+
// GIVEN no parameters
113+
const setEmailSpy = jest.spyOn(Iterable, 'setEmail');
114+
const setUserIdSpy = jest.spyOn(Iterable, 'setUserId');
115+
// WHEN Iterable.logout is called
116+
Iterable.logout();
117+
// THEN both methods are called with null
118+
expect(setEmailSpy).toBeCalledWith(null);
119+
expect(setUserIdSpy).toBeCalledWith(null);
120+
// Clean up
121+
setEmailSpy.mockRestore();
122+
setUserIdSpy.mockRestore();
123+
});
124+
});
125+
77126
describe('disableDeviceForCurrentUser', () => {
78127
it('should disable the device for the current user', () => {
79128
// GIVEN no parameters

0 commit comments

Comments
 (0)