forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrateMessages-test.js
56 lines (47 loc) · 1.77 KB
/
migrateMessages-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* @flow strict-local */
import omit from 'lodash.omit';
import { migrateMessages } from '../getMessages';
import { identityOfAuth } from '../../../account/accountMisc';
import * as eg from '../../../__tests__/lib/exampleData';
import type { ServerMessage, ServerReaction } from '../getMessages';
import type { Message } from '../../modelTypes';
describe('migrateMessages', () => {
const reactingUser = eg.makeUser();
const serverReaction: ServerReaction = {
emoji_name: '+1',
reaction_type: 'unicode_emoji',
emoji_code: '1f44d',
user: {
email: reactingUser.email,
full_name: reactingUser.full_name,
id: reactingUser.user_id,
},
};
type CommonFields = $Diff<Message, { reactions: mixed }>;
const serverMessage: ServerMessage = {
// The `omit` shouldn't be necessary with Flow v0.111: "Spreads
// now overwrite properties instead of inferring unions"
// (https://medium.com/flow-type/spreads-common-errors-fixes-9701012e9d58).
...(omit(eg.streamMessage(), 'reactions'): CommonFields),
reactions: [serverReaction],
};
const input: ServerMessage[] = [serverMessage];
const expectedOutput: Message[] = [
{
// The `omit` shouldn't be necessary with Flow v0.111.
...(omit(serverMessage, 'reactions'): CommonFields),
reactions: [
{
user_id: reactingUser.user_id,
emoji_name: serverReaction.emoji_name,
reaction_type: serverReaction.reaction_type,
emoji_code: serverReaction.emoji_code,
},
],
},
];
const actualOutput: Message[] = migrateMessages(input, identityOfAuth(eg.selfAuth));
test('Replace user object with `user_id`', () => {
expect(actualOutput.map(m => m.reactions)).toEqual(expectedOutput.map(m => m.reactions));
});
});