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