diff --git a/lib/shared/message-utils.test.js b/lib/shared/message-utils.test.js --- a/lib/shared/message-utils.test.js +++ b/lib/shared/message-utils.test.js @@ -26,17 +26,238 @@ import type { RawUpdateRelationshipMessageInfo } from '../types/messages/update-relationship.js'; import { threadTypes } from '../types/thread-types-enum.js'; +const textMessageInfo: RawTextMessageInfo = { + type: messageTypes.TEXT, + localID: 'local1', + threadID: '10001', + creatorID: '123', + time: 10000, + text: 'This is a text message', + id: '1', +}; +const createThreadMessageInfo: RawCreateThreadMessageInfo = { + type: 1, + threadID: '10001', + creatorID: '123', + time: 10000, + initialThreadState: { + type: threadTypes.COMMUNITY_ROOT, + name: 'Random Thread', + parentThreadID: '10000', + color: '#FFFFFF', + memberIDs: ['1', '2', '3'], + }, + id: '1', +}; +const addMembersMessageInfo: RawAddMembersMessageInfo = { + type: messageTypes.ADD_MEMBERS, + threadID: '10001', + creatorID: '123', + time: 10000, + addedUserIDs: ['4', '5'], + id: '1', +}; +const createSubthreadMessageInfo: RawCreateSubthreadMessageInfo = { + type: messageTypes.CREATE_SUB_THREAD, + threadID: '10001', + creatorID: '123', + time: 10000, + childThreadID: '10002', + id: '1', +}; +const changeSettingsMessageInfo: RawChangeSettingsMessageInfo = { + type: messageTypes.CHANGE_SETTINGS, + threadID: '10000', + creatorID: '123', + time: 10000, + field: 'color', + value: '#FFFFFF', + id: '1', +}; +const removeMembersMessageInfo: RawRemoveMembersMessageInfo = { + type: messageTypes.REMOVE_MEMBERS, + threadID: '10000', + creatorID: '123', + time: 10000, + removedUserIDs: ['1', '2', '3'], + id: '1', +}; +const changeRoleMessageinfo: RawChangeRoleMessageInfo = { + type: messageTypes.CHANGE_ROLE, + threadID: '10000', + creatorID: '123', + time: 10000, + userIDs: ['1', '2', '3'], + newRole: '101', + roleName: 'Moderators', + id: '1', +}; +const leaveThreadMessageInfo: RawLeaveThreadMessageInfo = { + type: messageTypes.LEAVE_THREAD, + threadID: '10000', + creatorID: '123', + time: 10000, + id: '1', +}; +const joinThreadMessageInfo: RawJoinThreadMessageInfo = { + type: messageTypes.JOIN_THREAD, + threadID: '10000', + creatorID: '123', + time: 10000, + id: '1', +}; +const createEntryMessageInfo: RawCreateEntryMessageInfo = { + type: messageTypes.CREATE_ENTRY, + threadID: '10000', + creatorID: '123', + time: 10000, + entryID: '001', + date: '2018-01-01', + text: 'This is a calendar entry', + id: '1', +}; +const editEntryMessageInfo: RawEditEntryMessageInfo = { + type: messageTypes.EDIT_ENTRY, + threadID: '10000', + creatorID: '123', + time: 10000, + entryID: '001', + date: '2018-01-01', + text: 'This is an edited calendar entry', + id: '1', +}; +const deleteEntryMessageInfo: RawDeleteEntryMessageInfo = { + type: messageTypes.DELETE_ENTRY, + threadID: '10000', + creatorID: '123', + time: 10000, + entryID: '001', + date: '2018-01-01', + text: 'This is a deleted calendar entry', + id: '1', +}; +const restoreEntryMessageInfo: RawRestoreEntryMessageInfo = { + type: messageTypes.RESTORE_ENTRY, + threadID: '10000', + creatorID: '123', + time: 10000, + entryID: '001', + date: '2018-01-01', + text: 'This is a restored calendar entry', + id: '1', +}; +const updateRelationshipMessageInfo: RawUpdateRelationshipMessageInfo = { + type: messageTypes.UPDATE_RELATIONSHIP, + threadID: '10000', + creatorID: '123', + targetID: '456', + time: 10000, + operation: 'request_sent', + id: '1', +}; +const imageMessageInfo: RawImagesMessageInfo = { + type: messageTypes.IMAGES, + localID: 'local1', + threadID: '10001', + creatorID: '123', + time: 10000, + media: [ + { + id: '1', + uri: 'https://example.com/image1.jpg', + type: 'photo', + dimensions: { + height: 100, + width: 100, + }, + thumbHash: '1234567890', + }, + ], + id: '1', +}; +const mediaMessageInfo: RawMediaMessageInfo = { + type: messageTypes.MULTIMEDIA, + localID: 'local1', + threadID: '10001', + creatorID: '123', + time: 10000, + media: [ + { + id: '1', + uri: 'https://example.com/image1.jpg', + type: 'photo', + dimensions: { + height: 100, + width: 100, + }, + thumbHash: '1234567890', + }, + ], + id: '1', +}; +const sidebarSourceMessageInfo: RawSidebarSourceMessageInfo = { + type: messageTypes.SIDEBAR_SOURCE, + threadID: '10000', + creatorID: '123', + time: 10000, + sourceMessage: { + type: messageTypes.TEXT, + localID: 'local1', + threadID: '10001', + creatorID: '123', + time: 10000, + text: 'This is a text message', + id: '1', + }, + id: '1', +}; +const createSidebarMessageInfo: RawCreateSidebarMessageInfo = { + type: messageTypes.CREATE_SIDEBAR, + threadID: '10000', + creatorID: '123', + time: 10000, + sourceMessageAuthorID: '123', + initialThreadState: { + name: 'Random Thread', + parentThreadID: '10000', + color: '#FFFFFF', + memberIDs: ['1', '2', '3'], + }, + id: '1', +}; +const reactionMessageInfo: RawReactionMessageInfo = { + type: messageTypes.REACTION, + localID: 'local1', + threadID: '10001', + creatorID: '123', + time: 10000, + targetMessageID: '1', + reaction: 'like', + action: 'add_reaction', + id: '1', +}; +const editMessageInfo: RawEditMessageInfo = { + type: messageTypes.EDIT_MESSAGE, + threadID: '10000', + creatorID: '123', + time: 10000, + targetMessageID: '1', + text: 'This is an edited message', + id: '1', +}; +const togglePinMessageInfo: RawTogglePinMessageInfo = { + type: messageTypes.TOGGLE_PIN, + threadID: '10000', + targetMessageID: '1', + action: 'pin', + pinnedContent: 'a message', + creatorID: '123', + time: 10000, + id: '1', +}; + describe('isInvalidSidebarSource & canBeSidebarSource', () => { it('should return false for RawTextMessageInfo', () => { - const textMessageInfo: RawTextMessageInfo = { - type: messageTypes.TEXT, - localID: 'local1', - threadID: '10001', - creatorID: '123', - time: 10000, - text: 'This is a text message', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.TEXT]; const shouldBeInvalidSidebarSource = @@ -48,20 +269,6 @@ }); it('should return false for RawCreateThreadMessageInfo', () => { - const createThreadMessageInfo: RawCreateThreadMessageInfo = { - type: 1, - threadID: '10001', - creatorID: '123', - time: 10000, - initialThreadState: { - type: threadTypes.COMMUNITY_ROOT, - name: 'Random Thread', - parentThreadID: '10000', - color: '#FFFFFF', - memberIDs: ['1', '2', '3'], - }, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CREATE_THREAD]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -74,14 +281,6 @@ }); it('should return false for RawAddMembersMessageInfo', () => { - const addMembersMessageInfo: RawAddMembersMessageInfo = { - type: messageTypes.ADD_MEMBERS, - threadID: '10001', - creatorID: '123', - time: 10000, - addedUserIDs: ['4', '5'], - id: '1', - }; const messageSpec = messageSpecs[messageTypes.ADD_MEMBERS]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -94,14 +293,6 @@ }); it('should return false for RawCreateSubthreadMessageInfo', () => { - const createSubthreadMessageInfo: RawCreateSubthreadMessageInfo = { - type: messageTypes.CREATE_SUB_THREAD, - threadID: '10001', - creatorID: '123', - time: 10000, - childThreadID: '10002', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CREATE_SUB_THREAD]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -114,15 +305,6 @@ }); it('should return false for RawChangeSettingsMessageInfo', () => { - const changeSettingsMessageInfo: RawChangeSettingsMessageInfo = { - type: messageTypes.CHANGE_SETTINGS, - threadID: '10000', - creatorID: '123', - time: 10000, - field: 'color', - value: '#FFFFFF', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CHANGE_SETTINGS]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -135,14 +317,6 @@ }); it('should return false for RawRemoveMembersMessageInfo', () => { - const removeMembersMessageInfo: RawRemoveMembersMessageInfo = { - type: messageTypes.REMOVE_MEMBERS, - threadID: '10000', - creatorID: '123', - time: 10000, - removedUserIDs: ['1', '2', '3'], - id: '1', - }; const messageSpec = messageSpecs[messageTypes.REMOVE_MEMBERS]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -155,16 +329,6 @@ }); it('should return false for RawChangeRoleMessageInfo', () => { - const changeRoleMessageinfo: RawChangeRoleMessageInfo = { - type: messageTypes.CHANGE_ROLE, - threadID: '10000', - creatorID: '123', - time: 10000, - userIDs: ['1', '2', '3'], - newRole: '101', - roleName: 'Moderators', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CHANGE_ROLE]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -177,13 +341,6 @@ }); it('should return false for RawLeaveThreadMessageInfo', () => { - const leaveThreadMessageInfo: RawLeaveThreadMessageInfo = { - type: messageTypes.LEAVE_THREAD, - threadID: '10000', - creatorID: '123', - time: 10000, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.LEAVE_THREAD]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -196,13 +353,6 @@ }); it('should return false for RawJoinThreadMessageInfo', () => { - const joinThreadMessageInfo: RawJoinThreadMessageInfo = { - type: messageTypes.JOIN_THREAD, - threadID: '10000', - creatorID: '123', - time: 10000, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.JOIN_THREAD]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -215,16 +365,6 @@ }); it('should return false for RawCreateEntryMessageInfo', () => { - const createEntryMessageInfo: RawCreateEntryMessageInfo = { - type: messageTypes.CREATE_ENTRY, - threadID: '10000', - creatorID: '123', - time: 10000, - entryID: '001', - date: '2018-01-01', - text: 'This is a calendar entry', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CREATE_ENTRY]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -237,16 +377,6 @@ }); it('should return false for RawEditEntryMessageInfo', () => { - const editEntryMessageInfo: RawEditEntryMessageInfo = { - type: messageTypes.EDIT_ENTRY, - threadID: '10000', - creatorID: '123', - time: 10000, - entryID: '001', - date: '2018-01-01', - text: 'This is an edited calendar entry', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.EDIT_ENTRY]; const shouldBeInvalidSidebarSource = @@ -258,16 +388,6 @@ }); it('should return false for RawDeleteEntryMessageInfo', () => { - const deleteEntryMessageInfo: RawDeleteEntryMessageInfo = { - type: messageTypes.DELETE_ENTRY, - threadID: '10000', - creatorID: '123', - time: 10000, - entryID: '001', - date: '2018-01-01', - text: 'This is a deleted calendar entry', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.DELETE_ENTRY]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -280,16 +400,6 @@ }); it('should return false for RawRestoreEntryMessageInfo', () => { - const restoreEntryMessageInfo: RawRestoreEntryMessageInfo = { - type: messageTypes.RESTORE_ENTRY, - threadID: '10000', - creatorID: '123', - time: 10000, - entryID: '001', - date: '2018-01-01', - text: 'This is a restored calendar entry', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.RESTORE_ENTRY]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -302,15 +412,6 @@ }); it('should return false for RawUpdateRelationshipMessageInfo', () => { - const updateRelationshipMessageInfo: RawUpdateRelationshipMessageInfo = { - type: messageTypes.UPDATE_RELATIONSHIP, - threadID: '10000', - creatorID: '123', - targetID: '456', - time: 10000, - operation: 'request_sent', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.UPDATE_RELATIONSHIP]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -323,26 +424,6 @@ }); it('should return false for RawImagesMessageInfo', () => { - const imageMessageInfo: RawImagesMessageInfo = { - type: messageTypes.IMAGES, - localID: 'local1', - threadID: '10001', - creatorID: '123', - time: 10000, - media: [ - { - id: '1', - uri: 'https://example.com/image1.jpg', - type: 'photo', - dimensions: { - height: 100, - width: 100, - }, - thumbHash: '1234567890', - }, - ], - id: '1', - }; const messageSpec = messageSpecs[messageTypes.IMAGES]; const shouldBeInvalidSidebarSource = @@ -354,26 +435,6 @@ }); it('should return false for RawMediaMessageInfo', () => { - const mediaMessageInfo: RawMediaMessageInfo = { - type: messageTypes.MULTIMEDIA, - localID: 'local1', - threadID: '10001', - creatorID: '123', - time: 10000, - media: [ - { - id: '1', - uri: 'https://example.com/image1.jpg', - type: 'photo', - dimensions: { - height: 100, - width: 100, - }, - thumbHash: '1234567890', - }, - ], - id: '1', - }; const messageSpec = messageSpecs[messageTypes.MULTIMEDIA]; const shouldBeInvalidSidebarSource = @@ -385,22 +446,6 @@ }); it('should return true for RawSidebarSourceMessageInfo', () => { - const sidebarSourceMessageInfo: RawSidebarSourceMessageInfo = { - type: messageTypes.SIDEBAR_SOURCE, - threadID: '10000', - creatorID: '123', - time: 10000, - sourceMessage: { - type: messageTypes.TEXT, - localID: 'local1', - threadID: '10001', - creatorID: '123', - time: 10000, - text: 'This is a text message', - id: '1', - }, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.SIDEBAR_SOURCE]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -413,20 +458,6 @@ }); it('should return false for RawCreateSidebarMessageInfo', () => { - const createSidebarMessageInfo: RawCreateSidebarMessageInfo = { - type: messageTypes.CREATE_SIDEBAR, - threadID: '10000', - creatorID: '123', - time: 10000, - sourceMessageAuthorID: '123', - initialThreadState: { - name: 'Random Thread', - parentThreadID: '10000', - color: '#FFFFFF', - memberIDs: ['1', '2', '3'], - }, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.CREATE_SIDEBAR]; const shouldBeInvalidSidebarSource = isInvalidSidebarSource( @@ -439,17 +470,6 @@ }); it('should return true for RawReactionMessageInfo', () => { - const reactionMessageInfo: RawReactionMessageInfo = { - type: messageTypes.REACTION, - localID: 'local1', - threadID: '10001', - creatorID: '123', - time: 10000, - targetMessageID: '1', - reaction: 'like', - action: 'add_reaction', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.REACTION]; const shouldBeInvalidSidebarSource = @@ -461,15 +481,6 @@ }); it('should return true for RawEditMessageInfo', () => { - const editMessageInfo: RawEditMessageInfo = { - type: messageTypes.EDIT_MESSAGE, - threadID: '10000', - creatorID: '123', - time: 10000, - targetMessageID: '1', - text: 'This is an edited message', - id: '1', - }; const messageSpec = messageSpecs[messageTypes.EDIT_MESSAGE]; const shouldBeInvalidSidebarSource = @@ -481,16 +492,6 @@ }); it('should return true for RawTogglePinMessageInfo', () => { - const togglePinMessageInfo: RawTogglePinMessageInfo = { - type: messageTypes.TOGGLE_PIN, - threadID: '10000', - targetMessageID: '1', - action: 'pin', - pinnedContent: 'a message', - creatorID: '123', - time: 10000, - id: '1', - }; const messageSpec = messageSpecs[messageTypes.TOGGLE_PIN]; const shouldBeInvalidSidebarSource =