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