diff --git a/lib/shared/thread-utils.test.js b/lib/shared/thread-utils.test.js --- a/lib/shared/thread-utils.test.js +++ b/lib/shared/thread-utils.test.js @@ -1,7 +1,13 @@ // @flow -import { parsePendingThreadID } from './thread-utils.js'; +import { + parsePendingThreadID, + threadInfoFromRawThreadInfo, +} from './thread-utils.js'; +import { threadInfoValidator } from '../permissions/minimally-encoded-thread-permissions-validators.js'; +import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; +import type { UserInfos } from '../types/user-types.js'; describe('parsePendingThreadID(pendingThreadID: string)', () => { it('should return correct data for real pending sidebar ID', () => { @@ -65,3 +71,131 @@ ); }); }); + +const rawThreadInfo: RawThreadInfo = { + id: '1', + type: 12, + name: 'GENESIS', + description: + 'This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.', + color: 'c85000', + creationTime: 1702415956354, + parentThreadID: null, + repliesCount: 0, + containingThreadID: null, + community: null, + pinnedCount: 0, + minimallyEncoded: true, + members: [ + { + id: '256', + role: '83796', + permissions: '3f73ff', + isSender: false, + minimallyEncoded: true, + }, + { + id: '83809', + role: '83795', + permissions: '3', + isSender: false, + minimallyEncoded: true, + }, + ], + roles: { + '83795': { + id: '83795', + name: 'Members', + permissions: ['000', '010', '005', '015', '0a7'], + isDefault: true, + minimallyEncoded: true, + }, + '83796': { + id: '83796', + name: 'Admins', + permissions: [ + '000', + '010', + '020', + '100', + '110', + '030', + '040', + '060', + '050', + '120', + '080', + '090', + '0c0', + '070', + '0d0', + '0e0', + '130', + '140', + '150', + '004', + '014', + '0a6', + '0a8', + '024', + '034', + '044', + '064', + '054', + '124', + '086', + '096', + '0c4', + '074', + '0b4', + '0d4', + '0e4', + '134', + '156', + ], + isDefault: false, + minimallyEncoded: true, + }, + }, + currentUser: { + role: '83795', + permissions: '3', + subscription: { + home: true, + pushNotifs: true, + }, + unread: false, + minimallyEncoded: true, + }, +}; +const userInfos: UserInfos = { + '5': { + id: '5', + username: 'commbot', + }, + '256': { + id: '256', + username: 'ashoat', + }, + '83809': { + id: '83809', + username: 'atul', + avatar: { + type: 'emoji', + emoji: 'đŸ˜²', + color: '4b87aa', + }, + }, +}; + +describe('threadInfoFromRawThreadInfo', () => { + it('should return correctly formed ThreadInfo from RawThreadInfo', () => { + const threadInfo = threadInfoFromRawThreadInfo( + rawThreadInfo, + null, + userInfos, + ); + + expect(threadInfoValidator.is(threadInfo)).toBe(true); + }); +});