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