|
1 | 1 | /* @flow strict-local */ |
2 | | -import { migrateMessages } from '../getMessages'; |
| 2 | +import { migrateMessage } from '../getMessages'; |
3 | 3 | import { identityOfAuth } from '../../../account/accountMisc'; |
4 | 4 | import * as eg from '../../../__tests__/lib/exampleData'; |
5 | 5 | import type { ServerMessage, ServerReaction } from '../getMessages'; |
@@ -38,75 +38,70 @@ const serverMessage: ServerMessage = { |
38 | 38 | }; |
39 | 39 |
|
40 | 40 | describe('recent server', () => { |
41 | | - const input: $ReadOnlyArray<ServerMessage> = [serverMessage]; |
| 41 | + const input: ServerMessage = serverMessage; |
42 | 42 |
|
43 | | - const expectedOutput: $ReadOnlyArray<Message> = [ |
44 | | - { |
45 | | - ...serverMessage, |
46 | | - reactions: [ |
47 | | - { |
48 | | - user_id: reactingUser.user_id, |
49 | | - emoji_name: serverReaction.emoji_name, |
50 | | - reaction_type: serverReaction.reaction_type, |
51 | | - emoji_code: serverReaction.emoji_code, |
52 | | - }, |
53 | | - ], |
54 | | - avatar_url: GravatarURL.validateAndConstructInstance({ email: serverMessage.sender_email }), |
55 | | - edit_history: |
56 | | - // $FlowIgnore[incompatible-cast] - See MessageEdit type |
57 | | - (serverMessage.edit_history: Message['edit_history']), |
58 | | - }, |
59 | | - ]; |
| 43 | + const expectedOutput: Message = { |
| 44 | + ...serverMessage, |
| 45 | + reactions: [ |
| 46 | + { |
| 47 | + user_id: reactingUser.user_id, |
| 48 | + emoji_name: serverReaction.emoji_name, |
| 49 | + reaction_type: serverReaction.reaction_type, |
| 50 | + emoji_code: serverReaction.emoji_code, |
| 51 | + }, |
| 52 | + ], |
| 53 | + avatar_url: GravatarURL.validateAndConstructInstance({ email: serverMessage.sender_email }), |
| 54 | + edit_history: |
| 55 | + // $FlowIgnore[incompatible-cast] - See MessageEdit type |
| 56 | + (serverMessage.edit_history: Message['edit_history']), |
| 57 | + }; |
60 | 58 |
|
61 | | - const actualOutput: $ReadOnlyArray<Message> = migrateMessages( |
| 59 | + const actualOutput: Message = migrateMessage<Message>( |
62 | 60 | input, |
63 | 61 | identityOfAuth(eg.selfAuth), |
64 | 62 | eg.recentZulipFeatureLevel, |
65 | 63 | true, |
66 | 64 | ); |
67 | 65 |
|
68 | 66 | test('In reactions, replace user object with `user_id`', () => { |
69 | | - expect(actualOutput.map(m => m.reactions)).toEqual(expectedOutput.map(m => m.reactions)); |
| 67 | + expect(actualOutput.reactions).toEqual(expectedOutput.reactions); |
70 | 68 | }); |
71 | 69 |
|
72 | 70 | test('Converts avatar_url correctly', () => { |
73 | | - expect(actualOutput.map(m => m.avatar_url)).toEqual(expectedOutput.map(m => m.avatar_url)); |
| 71 | + expect(actualOutput.avatar_url).toEqual(expectedOutput.avatar_url); |
74 | 72 | }); |
75 | 73 |
|
76 | 74 | test('Keeps edit_history, if allowEditHistory is true', () => { |
77 | | - expect(actualOutput.map(m => m.edit_history)).toEqual(expectedOutput.map(m => m.edit_history)); |
| 75 | + expect(actualOutput.edit_history).toEqual(expectedOutput.edit_history); |
78 | 76 | }); |
79 | 77 |
|
80 | 78 | test('Drops edit_history, if allowEditHistory is false', () => { |
81 | 79 | expect( |
82 | | - migrateMessages(input, identityOfAuth(eg.selfAuth), eg.recentZulipFeatureLevel, false).map( |
83 | | - m => m.edit_history, |
84 | | - ), |
85 | | - ).toEqual(expectedOutput.map(m => null)); |
| 80 | + migrateMessage<Message>(input, identityOfAuth(eg.selfAuth), eg.recentZulipFeatureLevel, false) |
| 81 | + .edit_history, |
| 82 | + ).toEqual(null); |
86 | 83 | }); |
87 | 84 | }); |
88 | 85 |
|
89 | 86 | describe('drops edit_history from pre-118 server', () => { |
90 | 87 | expect( |
91 | | - migrateMessages( |
92 | | - [ |
93 | | - { |
94 | | - ...serverMessage, |
95 | | - edit_history: [ |
96 | | - { |
97 | | - prev_content: 'foo', |
98 | | - prev_rendered_content: '<p>foo</p>', |
99 | | - prev_stream: eg.stream.stream_id, |
100 | | - prev_subject: 'bar', |
101 | | - timestamp: 0, |
102 | | - user_id: eg.selfUser.user_id, |
103 | | - }, |
104 | | - ], |
105 | | - }, |
106 | | - ], |
| 88 | + migrateMessage<Message>( |
| 89 | + { |
| 90 | + ...serverMessage, |
| 91 | + edit_history: [ |
| 92 | + { |
| 93 | + prev_content: 'foo', |
| 94 | + prev_rendered_content: '<p>foo</p>', |
| 95 | + prev_stream: eg.stream.stream_id, |
| 96 | + prev_subject: 'bar', |
| 97 | + timestamp: 0, |
| 98 | + user_id: eg.selfUser.user_id, |
| 99 | + }, |
| 100 | + ], |
| 101 | + }, |
107 | 102 | identityOfAuth(eg.selfAuth), |
108 | 103 | 117, |
109 | 104 | true, |
110 | | - ).map(m => m.edit_history), |
111 | | - ).toEqual([null]); |
| 105 | + ).edit_history, |
| 106 | + ).toEqual(null); |
112 | 107 | }); |
0 commit comments