Skip to content

Commit 607f51b

Browse files
authored
test: Add tests for duplicated users load (#15037)
1 parent 17ee132 commit 607f51b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/script/user/UserRepository.test.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {RECEIPT_MODE} from '@wireapp/api-client/lib/conversation/data';
2121
import {amplify} from 'amplify';
2222
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
2323

24+
import {Availability} from '@wireapp/protocol-messaging';
2425
import {WebAppEvents} from '@wireapp/webapp-events';
2526

2627
import {entities} from 'test/api/payloads';
@@ -207,7 +208,6 @@ describe('UserRepository', () => {
207208

208209
describe('loadUsers', () => {
209210
const localUsers = [generateAPIUser(), generateAPIUser(), generateAPIUser()];
210-
//const connections = [new ConnectionEntity()];
211211
beforeEach(async () => {
212212
jest.resetAllMocks();
213213
userState.users.removeAll();
@@ -220,7 +220,7 @@ describe('UserRepository', () => {
220220
const userIds = users.map(user => user.qualified_id!);
221221
const fetchUserSpy = jest.spyOn(userRepository['userService'], 'getUsers').mockResolvedValue({found: newUsers});
222222

223-
await userRepository.loadUsers(new User(), [], [], userIds);
223+
await userRepository.loadUsers(new User('self'), [], [], userIds);
224224

225225
expect(userState.users()).toHaveLength(users.length + 1);
226226
expect(fetchUserSpy).toHaveBeenCalledWith(newUsers.map(user => user.qualified_id!));
@@ -230,12 +230,33 @@ describe('UserRepository', () => {
230230
const userIds = localUsers.map(user => user.qualified_id!);
231231
const fetchUserSpy = jest.spyOn(userRepository['userService'], 'getUsers').mockResolvedValue({found: []});
232232

233-
await userRepository.loadUsers(new User(), [], [], userIds);
233+
await userRepository.loadUsers(new User('self'), [], [], userIds);
234234

235235
expect(userState.users()).toHaveLength(localUsers.length + 1);
236236
expect(fetchUserSpy).not.toHaveBeenCalled();
237237
});
238238

239+
it('loads users that are partially stored in the DB and maps availability', async () => {
240+
const userIds = localUsers.map(user => user.qualified_id!);
241+
const partialUsers = [
242+
{id: userIds[0].id, availability: Availability.Type.AVAILABLE},
243+
{id: userIds[1].id, availability: Availability.Type.BUSY},
244+
];
245+
246+
jest.spyOn(userRepository['userService'], 'loadUserFromDb').mockResolvedValue(partialUsers as any);
247+
const fetchUserSpy = jest
248+
.spyOn(userRepository['userService'], 'getUsers')
249+
.mockResolvedValue({found: localUsers});
250+
251+
await userRepository.loadUsers(new User('self'), [], [], userIds);
252+
253+
expect(userState.users()).toHaveLength(localUsers.length + 1);
254+
expect(fetchUserSpy).toHaveBeenCalledWith(userIds);
255+
256+
const userWithAvailability = userState.users().filter(user => user.availability() !== Availability.Type.NONE);
257+
expect(userWithAvailability).toHaveLength(partialUsers.length);
258+
});
259+
239260
it('deletes users that are not needed', async () => {
240261
const newUsers = [generateAPIUser(), generateAPIUser()];
241262
const userIds = newUsers.map(user => user.qualified_id!);

0 commit comments

Comments
 (0)