]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { | |
5 | checkCommentMention, | |
6 | CheckerBaseParams, | |
7 | checkNewCommentOnMyVideo, | |
8 | MockSmtpServer, | |
9 | prepareNotificationsTest | |
10 | } from '@server/tests/shared' | |
11 | import { UserNotification } from '@shared/models' | |
12 | import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' | |
13 | ||
14 | describe('Test comments notifications', function () { | |
15 | let servers: PeerTubeServer[] = [] | |
16 | let userToken: string | |
17 | let userNotifications: UserNotification[] = [] | |
18 | let emails: object[] = [] | |
19 | ||
20 | const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>' | |
21 | const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' + | |
22 | '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' + | |
23 | '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?' | |
24 | ||
25 | before(async function () { | |
26 | this.timeout(120000) | |
27 | ||
28 | const res = await prepareNotificationsTest(2) | |
29 | emails = res.emails | |
30 | userToken = res.userAccessToken | |
31 | servers = res.servers | |
32 | userNotifications = res.userNotifications | |
33 | }) | |
34 | ||
35 | describe('Comment on my video notifications', function () { | |
36 | let baseParams: CheckerBaseParams | |
37 | ||
38 | before(() => { | |
39 | baseParams = { | |
40 | server: servers[0], | |
41 | emails, | |
42 | socketNotifications: userNotifications, | |
43 | token: userToken | |
44 | } | |
45 | }) | |
46 | ||
47 | it('Should not send a new comment notification after a comment on another video', async function () { | |
48 | this.timeout(30000) | |
49 | ||
50 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
51 | ||
52 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | |
53 | const commentId = created.id | |
54 | ||
55 | await waitJobs(servers) | |
56 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | |
57 | }) | |
58 | ||
59 | it('Should not send a new comment notification if I comment my own video', async function () { | |
60 | this.timeout(30000) | |
61 | ||
62 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
63 | ||
64 | const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) | |
65 | const commentId = created.id | |
66 | ||
67 | await waitJobs(servers) | |
68 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | |
69 | }) | |
70 | ||
71 | it('Should not send a new comment notification if the account is muted', async function () { | |
72 | this.timeout(30000) | |
73 | ||
74 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | |
75 | ||
76 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
77 | ||
78 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | |
79 | const commentId = created.id | |
80 | ||
81 | await waitJobs(servers) | |
82 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | |
83 | ||
84 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | |
85 | }) | |
86 | ||
87 | it('Should send a new comment notification after a local comment on my video', async function () { | |
88 | this.timeout(30000) | |
89 | ||
90 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
91 | ||
92 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | |
93 | const commentId = created.id | |
94 | ||
95 | await waitJobs(servers) | |
96 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) | |
97 | }) | |
98 | ||
99 | it('Should send a new comment notification after a remote comment on my video', async function () { | |
100 | this.timeout(30000) | |
101 | ||
102 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
103 | ||
104 | await waitJobs(servers) | |
105 | ||
106 | await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) | |
107 | ||
108 | await waitJobs(servers) | |
109 | ||
110 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | |
111 | expect(data).to.have.lengthOf(1) | |
112 | ||
113 | const commentId = data[0].id | |
114 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) | |
115 | }) | |
116 | ||
117 | it('Should send a new comment notification after a local reply on my video', async function () { | |
118 | this.timeout(30000) | |
119 | ||
120 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
121 | ||
122 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | |
123 | ||
124 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) | |
125 | ||
126 | await waitJobs(servers) | |
127 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) | |
128 | }) | |
129 | ||
130 | it('Should send a new comment notification after a remote reply on my video', async function () { | |
131 | this.timeout(30000) | |
132 | ||
133 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
134 | await waitJobs(servers) | |
135 | ||
136 | { | |
137 | const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) | |
138 | const threadId = created.id | |
139 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) | |
140 | } | |
141 | ||
142 | await waitJobs(servers) | |
143 | ||
144 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | |
145 | expect(data).to.have.lengthOf(1) | |
146 | ||
147 | const threadId = data[0].id | |
148 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) | |
149 | ||
150 | expect(tree.children).to.have.lengthOf(1) | |
151 | const commentId = tree.children[0].comment.id | |
152 | ||
153 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) | |
154 | }) | |
155 | ||
156 | it('Should convert markdown in comment to html', async function () { | |
157 | this.timeout(30000) | |
158 | ||
159 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } }) | |
160 | ||
161 | await servers[0].comments.createThread({ videoId: uuid, text: commentText }) | |
162 | ||
163 | await waitJobs(servers) | |
164 | ||
165 | const latestEmail = emails[emails.length - 1] | |
166 | expect(latestEmail['html']).to.contain(expectedHtml) | |
167 | }) | |
168 | }) | |
169 | ||
170 | describe('Mention notifications', function () { | |
171 | let baseParams: CheckerBaseParams | |
172 | const byAccountDisplayName = 'super root name' | |
173 | ||
174 | before(async () => { | |
175 | baseParams = { | |
176 | server: servers[0], | |
177 | emails, | |
178 | socketNotifications: userNotifications, | |
179 | token: userToken | |
180 | } | |
181 | ||
182 | await servers[0].users.updateMe({ displayName: 'super root name' }) | |
183 | await servers[1].users.updateMe({ displayName: 'super root 2 name' }) | |
184 | }) | |
185 | ||
186 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | |
187 | this.timeout(30000) | |
188 | ||
189 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | |
190 | ||
191 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | |
192 | ||
193 | await waitJobs(servers) | |
194 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | |
195 | }) | |
196 | ||
197 | it('Should not send a new mention comment notification if I mention myself', async function () { | |
198 | this.timeout(30000) | |
199 | ||
200 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
201 | ||
202 | const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) | |
203 | ||
204 | await waitJobs(servers) | |
205 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | |
206 | }) | |
207 | ||
208 | it('Should not send a new mention notification if the account is muted', async function () { | |
209 | this.timeout(30000) | |
210 | ||
211 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | |
212 | ||
213 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
214 | ||
215 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | |
216 | ||
217 | await waitJobs(servers) | |
218 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | |
219 | ||
220 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | |
221 | }) | |
222 | ||
223 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | |
224 | this.timeout(30000) | |
225 | ||
226 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
227 | ||
228 | await waitJobs(servers) | |
229 | const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | |
230 | ||
231 | await waitJobs(servers) | |
232 | ||
233 | const byAccountDisplayName = 'super root 2 name' | |
234 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' }) | |
235 | }) | |
236 | ||
237 | it('Should send a new mention notification after local comments', async function () { | |
238 | this.timeout(30000) | |
239 | ||
240 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
241 | ||
242 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) | |
243 | ||
244 | await waitJobs(servers) | |
245 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' }) | |
246 | ||
247 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) | |
248 | ||
249 | await waitJobs(servers) | |
250 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) | |
251 | }) | |
252 | ||
253 | it('Should send a new mention notification after remote comments', async function () { | |
254 | this.timeout(30000) | |
255 | ||
256 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
257 | ||
258 | await waitJobs(servers) | |
259 | ||
260 | const text1 = `hello @user_1@${servers[0].host} 1` | |
261 | const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 }) | |
262 | ||
263 | await waitJobs(servers) | |
264 | ||
265 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | |
266 | expect(data).to.have.lengthOf(1) | |
267 | ||
268 | const byAccountDisplayName = 'super root 2 name' | |
269 | const threadId = data[0].id | |
270 | await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' }) | |
271 | ||
272 | const text2 = `@user_1@${servers[0].host} hello 2 @root@${servers[0].host}` | |
273 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) | |
274 | ||
275 | await waitJobs(servers) | |
276 | ||
277 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) | |
278 | ||
279 | expect(tree.children).to.have.lengthOf(1) | |
280 | const commentId = tree.children[0].comment.id | |
281 | ||
282 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) | |
283 | }) | |
284 | ||
285 | it('Should convert markdown in comment to html', async function () { | |
286 | this.timeout(30000) | |
287 | ||
288 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | |
289 | ||
290 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' }) | |
291 | ||
292 | await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) | |
293 | ||
294 | await waitJobs(servers) | |
295 | ||
296 | const latestEmail = emails[emails.length - 1] | |
297 | expect(latestEmail['html']).to.contain(expectedHtml) | |
298 | }) | |
299 | }) | |
300 | ||
301 | after(async function () { | |
302 | MockSmtpServer.Instance.kill() | |
303 | ||
304 | await cleanupTests(servers) | |
305 | }) | |
306 | }) |