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