Page MenuHomePhabricator

D7656.diff
No OneTemporary

D7656.diff

diff --git a/lib/types/update-types.js b/lib/types/update-types.js
--- a/lib/types/update-types.js
+++ b/lib/types/update-types.js
@@ -1,19 +1,25 @@
// @flow
import invariant from 'invariant';
+import t, { type TUnion, type TInterface } from 'tcomb';
-import type { RawEntryInfo } from './entry-types.js';
-import type {
- RawMessageInfo,
- MessageTruncationStatus,
+import { type RawEntryInfo, rawEntryInfoValidator } from './entry-types.js';
+import {
+ type RawMessageInfo,
+ rawMessageInfoValidator,
+ type MessageTruncationStatus,
+ messageTruncationStatusValidator,
} from './message-types.js';
-import type { RawThreadInfo } from './thread-types.js';
-import type {
- UserInfo,
- UserInfos,
- LoggedInUserInfo,
- OldLoggedInUserInfo,
+import { type RawThreadInfo, rawThreadInfoValidator } from './thread-types.js';
+import {
+ type UserInfo,
+ type UserInfos,
+ type LoggedInUserInfo,
+ loggedInUserInfoValidator,
+ type OldLoggedInUserInfo,
+ oldLoggedInUserInfoValidator,
} from './user-types.js';
+import { tNumber, tShape, tID } from '../utils/validation-utils.js';
export const updateTypes = Object.freeze({
DELETE_ACCOUNT: 0,
@@ -202,12 +208,27 @@
+time: number,
+deletedUserID: string,
};
+export const accountDeletionUpdateInfoValidator: TInterface<AccountDeletionUpdateInfo> =
+ tShape<AccountDeletionUpdateInfo>({
+ type: tNumber(updateTypes.DELETE_ACCOUNT),
+ id: t.String,
+ time: t.Number,
+ deletedUserID: t.String,
+ });
+
type ThreadUpdateInfo = {
+type: 1,
+id: string,
+time: number,
+threadInfo: RawThreadInfo,
};
+export const threadUpdateInfoValidator: TInterface<ThreadUpdateInfo> =
+ tShape<ThreadUpdateInfo>({
+ type: tNumber(updateTypes.UPDATE_THREAD),
+ id: t.String,
+ time: t.Number,
+ threadInfo: rawThreadInfoValidator,
+ });
type ThreadReadStatusUpdateInfo = {
+type: 2,
+id: string,
@@ -215,12 +236,28 @@
+threadID: string,
+unread: boolean,
};
+export const threadReadStatusUpdateInfoValidator: TInterface<ThreadReadStatusUpdateInfo> =
+ tShape<ThreadReadStatusUpdateInfo>({
+ type: tNumber(updateTypes.UPDATE_THREAD_READ_STATUS),
+ id: t.String,
+ time: t.Number,
+ threadID: tID,
+ unread: t.Boolean,
+ });
type ThreadDeletionUpdateInfo = {
+type: 3,
+id: string,
+time: number,
+threadID: string,
};
+export const threadDeletionUpdateInfoValidator: TInterface<ThreadDeletionUpdateInfo> =
+ tShape<ThreadDeletionUpdateInfo>({
+ type: tNumber(updateTypes.DELETE_THREAD),
+ id: t.String,
+ time: t.Number,
+ threadID: tID,
+ });
+
type ThreadJoinUpdateInfo = {
+type: 4,
+id: string,
@@ -230,18 +267,42 @@
+truncationStatus: MessageTruncationStatus,
+rawEntryInfos: $ReadOnlyArray<RawEntryInfo>,
};
+export const threadJoinUpdateInfoValidator: TInterface<ThreadJoinUpdateInfo> =
+ tShape<ThreadJoinUpdateInfo>({
+ type: tNumber(updateTypes.JOIN_THREAD),
+ id: t.String,
+ time: t.Number,
+ threadInfo: rawThreadInfoValidator,
+ rawMessageInfos: t.list(rawMessageInfoValidator),
+ truncationStatus: messageTruncationStatusValidator,
+ rawEntryInfos: t.list(rawEntryInfoValidator),
+ });
type BadDeviceTokenUpdateInfo = {
+type: 5,
+id: string,
+time: number,
+deviceToken: string,
};
+export const badDeviceTokenUpdateInfoValidator: TInterface<BadDeviceTokenUpdateInfo> =
+ tShape<BadDeviceTokenUpdateInfo>({
+ type: tNumber(updateTypes.BAD_DEVICE_TOKEN),
+ id: t.String,
+ time: t.Number,
+ deviceToken: t.String,
+ });
type EntryUpdateInfo = {
+type: 6,
+id: string,
+time: number,
+entryInfo: RawEntryInfo,
};
+export const entryUpdateInfoValidator: TInterface<EntryUpdateInfo> =
+ tShape<EntryUpdateInfo>({
+ type: tNumber(updateTypes.UPDATE_ENTRY),
+ id: t.String,
+ time: t.Number,
+ entryInfo: rawEntryInfoValidator,
+ });
type CurrentUserUpdateInfo = {
+type: 7,
+id: string,
@@ -255,6 +316,13 @@
// Updated UserInfo is already contained within the UpdatesResultWithUserInfos
+updatedUserID: string,
};
+export const userUpdateInfoValidator: TInterface<UserUpdateInfo> =
+ tShape<UserUpdateInfo>({
+ type: tNumber(updateTypes.UPDATE_USER),
+ id: t.String,
+ time: t.Number,
+ updatedUserID: t.String,
+ });
export type ClientUpdateInfo =
| AccountDeletionUpdateInfo
| ThreadUpdateInfo
@@ -272,6 +340,16 @@
+time: number,
+currentUserInfo: LoggedInUserInfo | OldLoggedInUserInfo,
};
+export const serverCurrentUserUpdateInfoValidator: TInterface<ServerCurrentUserUpdateInfo> =
+ tShape<ServerCurrentUserUpdateInfo>({
+ type: tNumber(updateTypes.UPDATE_CURRENT_USER),
+ id: t.String,
+ time: t.Number,
+ currentUserInfo: t.union([
+ loggedInUserInfoValidator,
+ oldLoggedInUserInfoValidator,
+ ]),
+ });
export type ServerUpdateInfo =
| AccountDeletionUpdateInfo
| ThreadUpdateInfo
@@ -282,6 +360,17 @@
| EntryUpdateInfo
| ServerCurrentUserUpdateInfo
| UserUpdateInfo;
+export const serverUpdateInfoValidator: TUnion<ServerUpdateInfo> = t.union([
+ accountDeletionUpdateInfoValidator,
+ threadUpdateInfoValidator,
+ threadReadStatusUpdateInfoValidator,
+ threadDeletionUpdateInfoValidator,
+ threadJoinUpdateInfoValidator,
+ badDeviceTokenUpdateInfoValidator,
+ entryUpdateInfoValidator,
+ serverCurrentUserUpdateInfoValidator,
+ userUpdateInfoValidator,
+]);
export type ServerUpdatesResult = {
+currentAsOf: number,
diff --git a/lib/types/validation.test.js b/lib/types/validation.test.js
--- a/lib/types/validation.test.js
+++ b/lib/types/validation.test.js
@@ -10,6 +10,18 @@
} from './media-types.js';
import { messageTypes } from './message-types-enum.js';
import { threadTypes, rawThreadInfoValidator } from './thread-types.js';
+import {
+ updateTypes,
+ accountDeletionUpdateInfoValidator,
+ badDeviceTokenUpdateInfoValidator,
+ entryUpdateInfoValidator,
+ serverCurrentUserUpdateInfoValidator,
+ threadDeletionUpdateInfoValidator,
+ threadJoinUpdateInfoValidator,
+ threadReadStatusUpdateInfoValidator,
+ threadUpdateInfoValidator,
+ userUpdateInfoValidator,
+} from './update-types.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
describe('media validation', () => {
@@ -49,252 +61,251 @@
});
});
-describe('message validation', () => {
- const messages = [
- {
- type: messageTypes.TEXT,
- threadID: '83859',
- creatorID: '83853',
- time: 1682077048858,
- text: 'text',
- localID: 'local1',
- id: '92837',
- },
- {
- type: messageTypes.CREATE_THREAD,
- id: '83876',
- threadID: '83859',
- time: 1673561105839,
- creatorID: '83853',
- initialThreadState: {
- type: 6,
- name: null,
- parentThreadID: '1',
- color: '57697f',
- memberIDs: ['256', '83853'],
- },
- },
- {
- type: messageTypes.ADD_MEMBERS,
- id: '4754380',
- threadID: '4746046',
- time: 1680179819346,
- creatorID: '256',
- addedUserIDs: ['518252', '1329299', '1559042'],
- },
- {
- type: messageTypes.CREATE_SUB_THREAD,
- threadID: '87111',
- creatorID: '83928',
- time: 1682083573756,
- childThreadID: '92993',
- id: '93000',
- },
- {
- type: messageTypes.CHANGE_SETTINGS,
- threadID: '83859',
- creatorID: '83853',
- time: 1682082984605,
- field: 'color',
- value: 'b8753d',
- id: '92880',
- },
- {
- type: messageTypes.REMOVE_MEMBERS,
- threadID: '92993',
- creatorID: '83928',
- time: 1682083613415,
- removedUserIDs: ['83890'],
- id: '93012',
- },
- {
- type: messageTypes.CHANGE_ROLE,
- threadID: '85027',
- creatorID: '256',
- time: 1632393331694,
- userIDs: ['85081'],
- newRole: 'role',
- id: '85431',
- },
- {
- type: messageTypes.LEAVE_THREAD,
- id: '93027',
- threadID: '92993',
- time: 1682083651037,
- creatorID: '83928',
- },
- {
- type: messageTypes.JOIN_THREAD,
- threadID: '92993',
- creatorID: '83928',
- time: 1682083678595,
- id: '93035',
- },
- {
- type: messageTypes.CREATE_ENTRY,
- threadID: '84695',
- creatorID: '83928',
- time: 1682083217395,
- entryID: '92917',
- date: '2023-04-02',
- text: 'text',
- id: '92920',
- },
- {
- type: messageTypes.EDIT_ENTRY,
- threadID: '84695',
- creatorID: '83928',
- time: 1682083374471,
- entryID: '92917',
- date: '2023-04-02',
- text: 'text',
- id: '92950',
- },
- {
- type: messageTypes.DELETE_ENTRY,
- threadID: '86033',
- creatorID: '83928',
- time: 1682083220296,
- entryID: '92904',
- date: '2023-04-02',
- text: 'text',
- id: '92932',
- },
- {
- type: messageTypes.RESTORE_ENTRY,
- id: '92962',
- threadID: '86033',
- time: 1682083414244,
- creatorID: '83928',
- entryID: '92904',
- date: '2023-04-02',
- text: 'text',
+const messages = [
+ {
+ type: messageTypes.TEXT,
+ threadID: '83859',
+ creatorID: '83853',
+ time: 1682077048858,
+ text: 'text',
+ localID: 'local1',
+ id: '92837',
+ },
+ {
+ type: messageTypes.CREATE_THREAD,
+ id: '83876',
+ threadID: '83859',
+ time: 1673561105839,
+ creatorID: '83853',
+ initialThreadState: {
+ type: 6,
+ name: null,
+ parentThreadID: '1',
+ color: '57697f',
+ memberIDs: ['256', '83853'],
},
- {
- type: messageTypes.UNSUPPORTED,
- threadID: '87080',
+ },
+ {
+ type: messageTypes.ADD_MEMBERS,
+ id: '4754380',
+ threadID: '4746046',
+ time: 1680179819346,
+ creatorID: '256',
+ addedUserIDs: ['518252', '1329299', '1559042'],
+ },
+ {
+ type: messageTypes.CREATE_SUB_THREAD,
+ threadID: '87111',
+ creatorID: '83928',
+ time: 1682083573756,
+ childThreadID: '92993',
+ id: '93000',
+ },
+ {
+ type: messageTypes.CHANGE_SETTINGS,
+ threadID: '83859',
+ creatorID: '83853',
+ time: 1682082984605,
+ field: 'color',
+ value: 'b8753d',
+ id: '92880',
+ },
+ {
+ type: messageTypes.REMOVE_MEMBERS,
+ threadID: '92993',
+ creatorID: '83928',
+ time: 1682083613415,
+ removedUserIDs: ['83890'],
+ id: '93012',
+ },
+ {
+ type: messageTypes.CHANGE_ROLE,
+ threadID: '85027',
+ creatorID: '256',
+ time: 1632393331694,
+ userIDs: ['85081'],
+ newRole: 'role',
+ id: '85431',
+ },
+ {
+ type: messageTypes.LEAVE_THREAD,
+ id: '93027',
+ threadID: '92993',
+ time: 1682083651037,
+ creatorID: '83928',
+ },
+ {
+ type: messageTypes.JOIN_THREAD,
+ threadID: '92993',
+ creatorID: '83928',
+ time: 1682083678595,
+ id: '93035',
+ },
+ {
+ type: messageTypes.CREATE_ENTRY,
+ threadID: '84695',
+ creatorID: '83928',
+ time: 1682083217395,
+ entryID: '92917',
+ date: '2023-04-02',
+ text: 'text',
+ id: '92920',
+ },
+ {
+ type: messageTypes.EDIT_ENTRY,
+ threadID: '84695',
+ creatorID: '83928',
+ time: 1682083374471,
+ entryID: '92917',
+ date: '2023-04-02',
+ text: 'text',
+ id: '92950',
+ },
+ {
+ type: messageTypes.DELETE_ENTRY,
+ threadID: '86033',
+ creatorID: '83928',
+ time: 1682083220296,
+ entryID: '92904',
+ date: '2023-04-02',
+ text: 'text',
+ id: '92932',
+ },
+ {
+ type: messageTypes.RESTORE_ENTRY,
+ id: '92962',
+ threadID: '86033',
+ time: 1682083414244,
+ creatorID: '83928',
+ entryID: '92904',
+ date: '2023-04-02',
+ text: 'text',
+ },
+ {
+ type: messageTypes.UNSUPPORTED,
+ threadID: '87080',
+ creatorID: '256',
+ time: 1640733462322,
+ robotext: 'unsupported message',
+ unsupportedMessageInfo: {
+ type: 105,
+ threadID: '97489',
creatorID: '256',
- time: 1640733462322,
- robotext: 'unsupported message',
- unsupportedMessageInfo: {
- type: 105,
- threadID: '97489',
- creatorID: '256',
- time: 1640773011289,
- id: '97672',
- },
- id: '97730',
- },
- {
- type: messageTypes.IMAGES,
- threadID: '92796',
- creatorID: '83928',
- time: 1682083469079,
- media: [
- {
- id: '92974',
- uri: 'http://0.0.0.0:3000/comm/upload/92974/ff3d02ded71e2762',
- type: 'photo',
- dimensions: {
- width: 220,
- height: 220,
- },
- },
- ],
- localID: 'local0',
- id: '92976',
- },
- {
- type: messageTypes.MULTIMEDIA,
- threadID: '89644',
- creatorID: '83853',
- time: 1682076177257,
- media: [
- {
- type: 'video',
- id: '92769',
- uri: 'http://0.0.0.0:3000/comm/upload/92769/4bcc6987b25b2f66',
- dimensions: {
- width: 480,
- height: 270,
- },
- thumbnailID: '92770',
- thumbnailURI:
- 'http://0.0.0.0:3000/comm/upload/92770/d56466051dcef1db',
- },
- ],
- id: '92771',
- },
- {
- type: messageTypes.UPDATE_RELATIONSHIP,
- threadID: '92796',
- creatorID: '83928',
- targetID: '83853',
- time: 1682083716312,
- operation: 'request_sent',
- id: '93039',
+ time: 1640773011289,
+ id: '97672',
},
- {
- type: messageTypes.SIDEBAR_SOURCE,
- threadID: '93044',
- creatorID: '83928',
- time: 1682083756831,
- sourceMessage: {
- type: 0,
- id: '92816',
- threadID: '92796',
- time: 1682076737518,
- creatorID: '83928',
- text: 'text',
+ id: '97730',
+ },
+ {
+ type: messageTypes.IMAGES,
+ threadID: '92796',
+ creatorID: '83928',
+ time: 1682083469079,
+ media: [
+ {
+ id: '92974',
+ uri: 'http://0.0.0.0:3000/comm/upload/92974/ff3d02ded71e2762',
+ type: 'photo',
+ dimensions: {
+ width: 220,
+ height: 220,
+ },
},
- id: '93049',
- },
- {
- type: messageTypes.CREATE_SIDEBAR,
- threadID: '93044',
- creatorID: '83928',
- time: 1682083756831,
- sourceMessageAuthorID: '83928',
- initialThreadState: {
- name: 'text',
- parentThreadID: '92796',
- color: 'aa4b4b',
- memberIDs: ['83853', '83928'],
+ ],
+ localID: 'local0',
+ id: '92976',
+ },
+ {
+ type: messageTypes.MULTIMEDIA,
+ threadID: '89644',
+ creatorID: '83853',
+ time: 1682076177257,
+ media: [
+ {
+ type: 'video',
+ id: '92769',
+ uri: 'http://0.0.0.0:3000/comm/upload/92769/4bcc6987b25b2f66',
+ dimensions: {
+ width: 480,
+ height: 270,
+ },
+ thumbnailID: '92770',
+ thumbnailURI: 'http://0.0.0.0:3000/comm/upload/92770/d56466051dcef1db',
},
- id: '93050',
- },
- {
- type: messageTypes.REACTION,
- threadID: '86033',
- localID: 'local8',
- creatorID: '83928',
- time: 1682083295820,
- targetMessageID: '91607',
- reaction: '😂',
- action: 'add_reaction',
- id: '92943',
- },
- {
- type: messageTypes.EDIT_MESSAGE,
- threadID: '86033',
+ ],
+ id: '92771',
+ },
+ {
+ type: messageTypes.UPDATE_RELATIONSHIP,
+ threadID: '92796',
+ creatorID: '83928',
+ targetID: '83853',
+ time: 1682083716312,
+ operation: 'request_sent',
+ id: '93039',
+ },
+ {
+ type: messageTypes.SIDEBAR_SOURCE,
+ threadID: '93044',
+ creatorID: '83928',
+ time: 1682083756831,
+ sourceMessage: {
+ type: 0,
+ id: '92816',
+ threadID: '92796',
+ time: 1682076737518,
creatorID: '83928',
- time: 1682083295820,
- targetMessageID: '91607',
text: 'text',
- id: '92943',
},
- {
- type: messageTypes.TOGGLE_PIN,
- threadID: '86033',
- targetMessageID: '91607',
- action: 'pin',
- pinnedContent: 'text',
- creatorID: '83928',
- time: 1682083295820,
- id: '92943',
+ id: '93049',
+ },
+ {
+ type: messageTypes.CREATE_SIDEBAR,
+ threadID: '93044',
+ creatorID: '83928',
+ time: 1682083756831,
+ sourceMessageAuthorID: '83928',
+ initialThreadState: {
+ name: 'text',
+ parentThreadID: '92796',
+ color: 'aa4b4b',
+ memberIDs: ['83853', '83928'],
},
- ];
+ id: '93050',
+ },
+ {
+ type: messageTypes.REACTION,
+ threadID: '86033',
+ localID: 'local8',
+ creatorID: '83928',
+ time: 1682083295820,
+ targetMessageID: '91607',
+ reaction: '😂',
+ action: 'add_reaction',
+ id: '92943',
+ },
+ {
+ type: messageTypes.EDIT_MESSAGE,
+ threadID: '86033',
+ creatorID: '83928',
+ time: 1682083295820,
+ targetMessageID: '91607',
+ text: 'text',
+ id: '92943',
+ },
+ {
+ type: messageTypes.TOGGLE_PIN,
+ threadID: '86033',
+ targetMessageID: '91607',
+ action: 'pin',
+ pinnedContent: 'text',
+ creatorID: '83928',
+ time: 1682083295820,
+ id: '92943',
+ },
+];
+describe('message validation', () => {
for (const validatorMessageTypeName in messageTypes) {
const validatorMessageType = messageTypes[validatorMessageTypeName];
const validator = messageSpecs[validatorMessageType].validator;
@@ -322,214 +333,104 @@
}
});
-describe('thread validation', () => {
- const thread = {
- id: '85171',
- type: threadTypes.PERSONAL,
- name: '',
- description: '',
- color: '6d49ab',
- creationTime: 1675887298557,
- parentThreadID: '1',
- members: [
- {
- id: '256',
- role: null,
- permissions: {
- know_of: {
- value: true,
- source: '1',
- },
- membership: {
- value: false,
- source: null,
- },
- visible: {
- value: true,
- source: '1',
- },
- voiced: {
- value: true,
- source: '1',
- },
- edit_entries: {
- value: true,
- source: '1',
- },
- edit_thread: {
- value: true,
- source: '1',
- },
- edit_thread_description: {
- value: true,
- source: '1',
- },
- edit_thread_color: {
- value: true,
- source: '1',
- },
- delete_thread: {
- value: true,
- source: '1',
- },
- create_subthreads: {
- value: true,
- source: '1',
- },
- create_sidebars: {
- value: true,
- source: '1',
- },
- join_thread: {
- value: true,
- source: '1',
- },
- edit_permissions: {
- value: true,
- source: '1',
- },
- add_members: {
- value: true,
- source: '1',
- },
- remove_members: {
- value: true,
- source: '1',
- },
- change_role: {
- value: true,
- source: '1',
- },
- leave_thread: {
- value: false,
- source: null,
- },
- react_to_message: {
- value: false,
- source: null,
- },
- edit_message: {
- value: false,
- source: null,
- },
- manage_pins: {
- value: true,
- source: '1',
- },
- },
- isSender: false,
- },
- {
- id: '83853',
- role: '85172',
- permissions: {
- know_of: {
- value: true,
- source: '85171',
- },
- membership: {
- value: false,
- source: null,
- },
- visible: {
- value: true,
- source: '85171',
- },
- voiced: {
- value: true,
- source: '85171',
- },
- edit_entries: {
- value: true,
- source: '85171',
- },
- edit_thread: {
- value: true,
- source: '85171',
- },
- edit_thread_description: {
- value: true,
- source: '85171',
- },
- edit_thread_color: {
- value: true,
- source: '85171',
- },
- delete_thread: {
- value: false,
- source: null,
- },
- create_subthreads: {
- value: false,
- source: null,
- },
- create_sidebars: {
- value: true,
- source: '85171',
- },
- join_thread: {
- value: false,
- source: null,
- },
- edit_permissions: {
- value: false,
- source: null,
- },
- add_members: {
- value: false,
- source: null,
- },
- remove_members: {
- value: false,
- source: null,
- },
- change_role: {
- value: false,
- source: null,
- },
- leave_thread: {
- value: false,
- source: null,
- },
- react_to_message: {
- value: true,
- source: '85171',
- },
- edit_message: {
- value: true,
- source: '85171',
- },
- manage_pins: {
- value: false,
- source: null,
- },
- },
- isSender: true,
- },
- ],
- roles: {
- '85172': {
- id: '85172',
- name: 'Members',
- permissions: {
- know_of: true,
- visible: true,
- voiced: true,
- react_to_message: true,
- edit_message: true,
- edit_entries: true,
- edit_thread: true,
- edit_thread_color: true,
- edit_thread_description: true,
- create_sidebars: true,
- descendant_open_know_of: true,
- descendant_open_visible: true,
- child_open_join_thread: true,
- },
- isDefault: true,
+const thread = {
+ id: '85171',
+ type: threadTypes.PERSONAL,
+ name: '',
+ description: '',
+ color: '6d49ab',
+ creationTime: 1675887298557,
+ parentThreadID: '1',
+ members: [
+ {
+ id: '256',
+ role: null,
+ permissions: {
+ know_of: {
+ value: true,
+ source: '1',
+ },
+ membership: {
+ value: false,
+ source: null,
+ },
+ visible: {
+ value: true,
+ source: '1',
+ },
+ voiced: {
+ value: true,
+ source: '1',
+ },
+ edit_entries: {
+ value: true,
+ source: '1',
+ },
+ edit_thread: {
+ value: true,
+ source: '1',
+ },
+ edit_thread_description: {
+ value: true,
+ source: '1',
+ },
+ edit_thread_color: {
+ value: true,
+ source: '1',
+ },
+ delete_thread: {
+ value: true,
+ source: '1',
+ },
+ create_subthreads: {
+ value: true,
+ source: '1',
+ },
+ create_sidebars: {
+ value: true,
+ source: '1',
+ },
+ join_thread: {
+ value: true,
+ source: '1',
+ },
+ edit_permissions: {
+ value: true,
+ source: '1',
+ },
+ add_members: {
+ value: true,
+ source: '1',
+ },
+ remove_members: {
+ value: true,
+ source: '1',
+ },
+ change_role: {
+ value: true,
+ source: '1',
+ },
+ leave_thread: {
+ value: false,
+ source: null,
+ },
+ react_to_message: {
+ value: false,
+ source: null,
+ },
+ edit_message: {
+ value: false,
+ source: null,
+ },
+ manage_pins: {
+ value: true,
+ source: '1',
+ },
},
+ isSender: false,
},
- currentUser: {
+ {
+ id: '83853',
role: '85172',
permissions: {
know_of: {
@@ -613,18 +514,128 @@
source: null,
},
},
- subscription: {
- home: true,
- pushNotifs: true,
+ isSender: true,
+ },
+ ],
+ roles: {
+ '85172': {
+ id: '85172',
+ name: 'Members',
+ permissions: {
+ know_of: true,
+ visible: true,
+ voiced: true,
+ react_to_message: true,
+ edit_message: true,
+ edit_entries: true,
+ edit_thread: true,
+ edit_thread_color: true,
+ edit_thread_description: true,
+ create_sidebars: true,
+ descendant_open_know_of: true,
+ descendant_open_visible: true,
+ child_open_join_thread: true,
},
- unread: false,
+ isDefault: true,
},
- repliesCount: 0,
- containingThreadID: '1',
- community: '1',
- pinnedCount: 0,
- };
+ },
+ currentUser: {
+ role: '85172',
+ permissions: {
+ know_of: {
+ value: true,
+ source: '85171',
+ },
+ membership: {
+ value: false,
+ source: null,
+ },
+ visible: {
+ value: true,
+ source: '85171',
+ },
+ voiced: {
+ value: true,
+ source: '85171',
+ },
+ edit_entries: {
+ value: true,
+ source: '85171',
+ },
+ edit_thread: {
+ value: true,
+ source: '85171',
+ },
+ edit_thread_description: {
+ value: true,
+ source: '85171',
+ },
+ edit_thread_color: {
+ value: true,
+ source: '85171',
+ },
+ delete_thread: {
+ value: false,
+ source: null,
+ },
+ create_subthreads: {
+ value: false,
+ source: null,
+ },
+ create_sidebars: {
+ value: true,
+ source: '85171',
+ },
+ join_thread: {
+ value: false,
+ source: null,
+ },
+ edit_permissions: {
+ value: false,
+ source: null,
+ },
+ add_members: {
+ value: false,
+ source: null,
+ },
+ remove_members: {
+ value: false,
+ source: null,
+ },
+ change_role: {
+ value: false,
+ source: null,
+ },
+ leave_thread: {
+ value: false,
+ source: null,
+ },
+ react_to_message: {
+ value: true,
+ source: '85171',
+ },
+ edit_message: {
+ value: true,
+ source: '85171',
+ },
+ manage_pins: {
+ value: false,
+ source: null,
+ },
+ },
+ subscription: {
+ home: true,
+ pushNotifs: true,
+ },
+ unread: false,
+ },
+ repliesCount: 0,
+ containingThreadID: '1',
+ community: '1',
+ pinnedCount: 0,
+};
+describe('thread validation', () => {
it('should validate correct thread', () => {
expect(rawThreadInfoValidator.is(thread)).toBe(true);
});
@@ -635,19 +646,19 @@
});
});
-describe('entry validation', () => {
- const entry = {
- id: '92860',
- threadID: '85068',
- text: 'text',
- year: 2023,
- month: 4,
- day: 2,
- creationTime: 1682082939882,
- creatorID: '83853',
- deleted: false,
- };
+const entry = {
+ id: '92860',
+ threadID: '85068',
+ text: 'text',
+ year: 2023,
+ month: 4,
+ day: 2,
+ creationTime: 1682082939882,
+ creatorID: '83853',
+ deleted: false,
+};
+describe('entry validation', () => {
it('should validate correct entry', () => {
expect(rawEntryInfoValidator.is(entry)).toBe(true);
});
@@ -655,3 +666,103 @@
expect(rawEntryInfoValidator.is({ ...entry, threadID: 0 })).toBe(false);
});
});
+
+describe('server update validation', () => {
+ const updates = [
+ {
+ type: updateTypes.DELETE_ACCOUNT,
+ id: '98424',
+ time: 1640870111106,
+ deletedUserID: '98262',
+ },
+ {
+ type: updateTypes.UPDATE_THREAD,
+ id: '97948',
+ time: 1640868525494,
+ threadInfo: thread,
+ },
+ {
+ type: updateTypes.UPDATE_THREAD_READ_STATUS,
+ id: '98002',
+ time: 1640869373326,
+ threadID: '83794',
+ unread: true,
+ },
+ {
+ type: updateTypes.DELETE_THREAD,
+ id: '98208',
+ time: 1640869773339,
+ threadID: '97852',
+ },
+ {
+ type: updateTypes.JOIN_THREAD,
+ id: '98126',
+ time: 1640869494461,
+ threadInfo: thread,
+ rawMessageInfos: messages,
+ truncationStatus: 'exhaustive',
+ rawEntryInfos: [entry],
+ },
+ {
+ type: updateTypes.BAD_DEVICE_TOKEN,
+ id: '98208',
+ time: 1640869773495,
+ deviceToken: 'some-device-token',
+ },
+ {
+ type: updateTypes.UPDATE_ENTRY,
+ id: '98233',
+ time: 1640869844908,
+ entryInfo: entry,
+ },
+ {
+ type: updateTypes.UPDATE_CURRENT_USER,
+ id: '98237',
+ time: 1640869934058,
+ currentUserInfo: {
+ id: '256',
+ username: 'ashoat',
+ },
+ },
+ {
+ type: updateTypes.UPDATE_USER,
+ id: '97988',
+ time: 1640869211822,
+ updatedUserID: '86565',
+ },
+ ];
+
+ const validatorByUpdateType = {
+ [updateTypes.DELETE_ACCOUNT]: accountDeletionUpdateInfoValidator,
+ [updateTypes.UPDATE_THREAD]: threadUpdateInfoValidator,
+ [updateTypes.UPDATE_THREAD_READ_STATUS]:
+ threadReadStatusUpdateInfoValidator,
+ [updateTypes.DELETE_THREAD]: threadDeletionUpdateInfoValidator,
+ [updateTypes.JOIN_THREAD]: threadJoinUpdateInfoValidator,
+ [updateTypes.BAD_DEVICE_TOKEN]: badDeviceTokenUpdateInfoValidator,
+ [updateTypes.UPDATE_ENTRY]: entryUpdateInfoValidator,
+ [updateTypes.UPDATE_CURRENT_USER]: serverCurrentUserUpdateInfoValidator,
+ [updateTypes.UPDATE_USER]: userUpdateInfoValidator,
+ };
+
+ for (const validatorUpdateType in validatorByUpdateType) {
+ const validator = validatorByUpdateType[validatorUpdateType];
+ const validatorUpdateTypeName = _findKey(
+ e => e === Number(validatorUpdateType),
+ )(updateTypes);
+
+ for (const update of updates) {
+ const updateTypeName = _findKey(e => e === update.type)(updateTypes);
+
+ if (Number(validatorUpdateType) === update.type) {
+ it(`${validatorUpdateTypeName} should validate ${updateTypeName}`, () => {
+ expect(validator.is(update)).toBe(true);
+ });
+ } else {
+ it(`${validatorUpdateTypeName} shouldn't validate ${updateTypeName}`, () => {
+ expect(validator.is(update)).toBe(false);
+ });
+ }
+ }
+ }
+});

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 12:08 PM (2 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2596944
Default Alt Text
D7656.diff (30 KB)

Event Timeline