Changeset View
Changeset View
Standalone View
Standalone View
lib/types/validation.test.js
// @flow | // @flow | ||||
import _findKey from 'lodash/fp/findKey.js'; | import _findKey from 'lodash/fp/findKey.js'; | ||||
import { | import { | ||||
imageValidator, | imageValidator, | ||||
videoValidator, | videoValidator, | ||||
mediaValidator, | mediaValidator, | ||||
} from './media-types.js'; | } from './media-types.js'; | ||||
import { messageTypes } from './message-types-enum.js'; | import { messageTypes } from './message-types-enum.js'; | ||||
import { threadTypes, rawThreadInfoValidator } from './thread-types.js'; | |||||
import { messageSpecs } from '../shared/messages/message-specs.js'; | import { messageSpecs } from '../shared/messages/message-specs.js'; | ||||
describe('media validation', () => { | describe('media validation', () => { | ||||
const photo = { | const photo = { | ||||
id: '92696', | id: '92696', | ||||
type: 'photo', | type: 'photo', | ||||
uri: 'http://0.0.0.0:3000/comm/upload/92696/0fb272bd1c75d976', | uri: 'http://0.0.0.0:3000/comm/upload/92696/0fb272bd1c75d976', | ||||
dimensions: { | dimensions: { | ||||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | for (const message of messages) { | ||||
) { | ) { | ||||
it(`${validatorMessageTypeName} shouldn't validate ${messageTypeName}`, () => { | it(`${validatorMessageTypeName} shouldn't validate ${messageTypeName}`, () => { | ||||
expect(validator.is(message)).toBe(false); | expect(validator.is(message)).toBe(false); | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
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, | |||||
}, | |||||
}, | |||||
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, | |||||
}; | |||||
it('should validate correct thread', () => { | |||||
expect(rawThreadInfoValidator.is(thread)).toBe(true); | |||||
}); | |||||
it('should not validate incorrect thread', () => { | |||||
expect( | |||||
rawThreadInfoValidator.is({ ...thread, creationTime: undefined }), | |||||
).toBe(false); | |||||
}); | |||||
}); |