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

93 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-03-04 19:48:44 +00:00
// Copyright 2020-2022 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 type { ConversationType } from '../../state/ducks/conversations';
2021-10-26 22:59:08 +00:00
import { UUID } from '../../types/UUID';
import type { UUIDStringType } from '../../types/UUID';
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,
2022-03-04 21:14:52 +00:00
avatarPath: 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,
2022-07-20 21:29:09 +00:00
id: UUID.generate().toString(),
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}`,
2021-10-26 22:59:08 +00:00
uuid: UUID.generate().toString(),
...overrideProps,
type: 'direct' as const,
acknowledgedGroupNameCollisions: undefined,
storySendMode: undefined,
};
}
2021-10-26 22:59:08 +00:00
2022-08-10 18:37:19 +00:00
export function getDefaultGroup(
overrideProps: Partial<ConversationType> = {}
): ConversationType {
const memberships = Array.from(Array(casual.integer(1, 20)), () => ({
uuid: UUID.generate().toString(),
isAdmin: Boolean(casual.coin_flip),
}));
return {
acceptedMessageRequest: true,
announcementsOnly: false,
avatarPath: getAvatarPath(),
badges: [],
color: getRandomColor(),
conversationColor: ConversationColors[0],
groupDescription: casual.sentence,
groupId: UUID.generate().toString(),
groupLink: casual.url,
groupVersion: 2,
id: UUID.generate().toString(),
isMe: false,
lastUpdated: casual.unix_time,
markedUnread: Boolean(overrideProps.markedUnread),
membersCount: memberships.length,
memberships,
sharedGroupNames: [],
title: casual.title,
uuid: UUID.generate().toString(),
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
};
}
2021-10-26 22:59:08 +00:00
export function getDefaultConversationWithUuid(
overrideProps: Partial<ConversationType> = {},
uuid: UUIDStringType = UUID.generate().toString()
): ConversationType & { uuid: UUIDStringType } {
return {
...getDefaultConversation(overrideProps),
uuid,
};
}