signal-desktop/ts/test-both/helpers/getDefaultConversation.ts

108 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-07-20 21:29:09 +00:00
import casual from 'casual';
2021-03-11 21:29:31 +00:00
import { sample } from 'lodash';
import { v4 as generateUuid } from 'uuid';
import type { ConversationType } from '../../state/ducks/conversations';
import type { ServiceIdString } from '../../types/ServiceId';
import { generateAci } from '../../types/ServiceId';
import type { GroupListItemConversationType } from '../../components/conversationList/GroupListItem';
2021-08-06 00:17:05 +00:00
import { getRandomColor } from './getRandomColor';
2022-03-16 17:30:14 +00:00
import { ConversationColors } from '../../types/Colors';
import { StorySendMode } from '../../types/Stories';
2022-03-04 21:14:52 +00:00
export const getAvatarPath = (): string =>
sample([
'/fixtures/kitten-1-64-64.jpg',
'/fixtures/kitten-2-64-64.jpg',
'/fixtures/kitten-3-64-64.jpg',
]) || '';
export function getDefaultConversation(
2021-03-11 21:29:31 +00:00
overrideProps: Partial<ConversationType> = {}
): ConversationType {
2022-07-20 21:29:09 +00:00
const firstName = casual.first_name;
const lastName = casual.last_name;
2021-03-11 21:29:31 +00:00
return {
2021-05-07 22:21:10 +00:00
acceptedMessageRequest: true,
2024-07-11 19:44:09 +00:00
avatarUrl: getAvatarPath(),
2021-11-02 23:01:13 +00:00
badges: [],
2022-07-20 21:29:09 +00:00
e164: `+${casual.phone.replace(/-/g, '')}`,
2022-03-16 17:30:14 +00:00
conversationColor: ConversationColors[0],
2021-08-06 00:17:05 +00:00
color: getRandomColor(),
2021-05-07 22:21:10 +00:00
firstName,
id: generateUuid(),
2021-05-07 22:21:10 +00:00
isMe: false,
2022-07-20 21:29:09 +00:00
lastUpdated: casual.unix_time,
markedUnread: Boolean(overrideProps.markedUnread),
2021-05-07 22:21:10 +00:00
sharedGroupNames: [],
2021-03-11 21:29:31 +00:00
title: `${firstName} ${lastName}`,
titleNoDefault: `${firstName} ${lastName}`,
2023-08-16 20:54:39 +00:00
serviceId: generateAci(),
...overrideProps,
type: 'direct' as const,
acknowledgedGroupNameCollisions: undefined,
storySendMode: undefined,
};
}
2021-10-26 22:59:08 +00:00
export function getDefaultGroupListItem(
overrideProps: Partial<GroupListItemConversationType> = {}
): GroupListItemConversationType {
return {
...getDefaultGroup(),
disabledReason: undefined,
membersCount: 24,
memberships: [],
...overrideProps,
};
}
2022-08-10 18:37:19 +00:00
export function getDefaultGroup(
overrideProps: Partial<ConversationType> = {}
): ConversationType {
const memberships = Array.from(Array(casual.integer(1, 20)), () => ({
2023-08-16 20:54:39 +00:00
aci: generateAci(),
2022-08-10 18:37:19 +00:00
isAdmin: Boolean(casual.coin_flip),
}));
return {
acceptedMessageRequest: true,
announcementsOnly: false,
2024-07-11 19:44:09 +00:00
avatarUrl: getAvatarPath(),
2022-08-10 18:37:19 +00:00
badges: [],
color: getRandomColor(),
conversationColor: ConversationColors[0],
groupDescription: casual.sentence,
groupId: generateUuid(),
2022-08-10 18:37:19 +00:00
groupLink: casual.url,
groupVersion: 2,
id: generateUuid(),
2022-08-10 18:37:19 +00:00
isMe: false,
lastUpdated: casual.unix_time,
markedUnread: Boolean(overrideProps.markedUnread),
membersCount: memberships.length,
memberships,
sharedGroupNames: [],
title: casual.title,
2023-08-16 20:54:39 +00:00
serviceId: generateAci(),
acknowledgedGroupNameCollisions: {},
storySendMode: StorySendMode.IfActive,
2022-08-10 18:37:19 +00:00
...overrideProps,
type: 'group' as const,
2022-08-10 18:37:19 +00:00
};
}
2023-08-16 20:54:39 +00:00
export function getDefaultConversationWithServiceId(
2021-10-26 22:59:08 +00:00
overrideProps: Partial<ConversationType> = {},
2023-08-16 20:54:39 +00:00
serviceId: ServiceIdString = generateAci()
): ConversationType & { serviceId: ServiceIdString } {
2021-10-26 22:59:08 +00:00
return {
...getDefaultConversation(overrideProps),
2023-08-16 20:54:39 +00:00
serviceId,
2021-10-26 22:59:08 +00:00
};
}