diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-16 15:52:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-16 15:55:42 +0200 |
commit | 8eb07b01306429abe5c538ff7aa0a16e44fff26f (patch) | |
tree | aa6461099e0652a54c9f49ecd5652f3ddfcc0fc1 /server/tests/api | |
parent | 1ba471c55fdbf05ef2c10152b3e4b0c5d8da3213 (diff) | |
download | PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.tar.gz PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.tar.zst PeerTube-8eb07b01306429abe5c538ff7aa0a16e44fff26f.zip |
Split notification tests
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/notifications/comments-notifications.ts | 309 | ||||
-rw-r--r-- | server/tests/api/notifications/index.ts | 3 | ||||
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 439 | ||||
-rw-r--r-- | server/tests/api/notifications/notifications-api.ts | 205 | ||||
-rw-r--r-- | server/tests/api/notifications/user-notifications.ts | 989 | ||||
-rw-r--r-- | server/tests/api/videos/video-channels.ts | 4 |
6 files changed, 996 insertions, 953 deletions
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts new file mode 100644 index 000000000..cd3ed2f70 --- /dev/null +++ b/server/tests/api/notifications/comments-notifications.ts | |||
@@ -0,0 +1,309 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { cleanupTests, getVideoCommentThreads, getVideoThreadComments, updateMyUser, wait } from '../../../../shared/extra-utils' | ||
6 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | ||
7 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
8 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
9 | import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist' | ||
10 | import { | ||
11 | checkCommentMention, | ||
12 | CheckerBaseParams, | ||
13 | checkNewCommentOnMyVideo, | ||
14 | prepareNotificationsTest | ||
15 | } from '../../../../shared/extra-utils/users/user-notifications' | ||
16 | import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | ||
17 | import { UserNotification } from '../../../../shared/models/users' | ||
18 | import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
19 | |||
20 | const expect = chai.expect | ||
21 | |||
22 | describe('Test comments notifications', function () { | ||
23 | let servers: ServerInfo[] = [] | ||
24 | let userAccessToken: string | ||
25 | let userNotifications: UserNotification[] = [] | ||
26 | let emails: object[] = [] | ||
27 | |||
28 | before(async function () { | ||
29 | this.timeout(120000) | ||
30 | |||
31 | const res = await prepareNotificationsTest(2) | ||
32 | emails = res.emails | ||
33 | userAccessToken = res.userAccessToken | ||
34 | servers = res.servers | ||
35 | userNotifications = res.userNotifications | ||
36 | }) | ||
37 | |||
38 | describe('Comment on my video notifications', function () { | ||
39 | let baseParams: CheckerBaseParams | ||
40 | |||
41 | before(() => { | ||
42 | baseParams = { | ||
43 | server: servers[0], | ||
44 | emails, | ||
45 | socketNotifications: userNotifications, | ||
46 | token: userAccessToken | ||
47 | } | ||
48 | }) | ||
49 | |||
50 | it('Should not send a new comment notification after a comment on another video', async function () { | ||
51 | this.timeout(10000) | ||
52 | |||
53 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
54 | const uuid = resVideo.body.video.uuid | ||
55 | |||
56 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
57 | const commentId = resComment.body.comment.id | ||
58 | |||
59 | await wait(500) | ||
60 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | ||
61 | }) | ||
62 | |||
63 | it('Should not send a new comment notification if I comment my own video', async function () { | ||
64 | this.timeout(10000) | ||
65 | |||
66 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
67 | const uuid = resVideo.body.video.uuid | ||
68 | |||
69 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') | ||
70 | const commentId = resComment.body.comment.id | ||
71 | |||
72 | await wait(500) | ||
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(10000) | ||
78 | |||
79 | await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
80 | |||
81 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
82 | const uuid = resVideo.body.video.uuid | ||
83 | |||
84 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
85 | const commentId = resComment.body.comment.id | ||
86 | |||
87 | await wait(500) | ||
88 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | ||
89 | |||
90 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
91 | }) | ||
92 | |||
93 | it('Should send a new comment notification after a local comment on my video', async function () { | ||
94 | this.timeout(10000) | ||
95 | |||
96 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
97 | const uuid = resVideo.body.video.uuid | ||
98 | |||
99 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
100 | const commentId = resComment.body.comment.id | ||
101 | |||
102 | await wait(500) | ||
103 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | ||
104 | }) | ||
105 | |||
106 | it('Should send a new comment notification after a remote comment on my video', async function () { | ||
107 | this.timeout(10000) | ||
108 | |||
109 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
110 | const uuid = resVideo.body.video.uuid | ||
111 | |||
112 | await waitJobs(servers) | ||
113 | |||
114 | await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') | ||
115 | |||
116 | await waitJobs(servers) | ||
117 | |||
118 | const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
119 | expect(resComment.body.data).to.have.lengthOf(1) | ||
120 | const commentId = resComment.body.data[0].id | ||
121 | |||
122 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | ||
123 | }) | ||
124 | |||
125 | it('Should send a new comment notification after a local reply on my video', async function () { | ||
126 | this.timeout(10000) | ||
127 | |||
128 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
129 | const uuid = resVideo.body.video.uuid | ||
130 | |||
131 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
132 | const threadId = resThread.body.comment.id | ||
133 | |||
134 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') | ||
135 | const commentId = resComment.body.comment.id | ||
136 | |||
137 | await wait(500) | ||
138 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | ||
139 | }) | ||
140 | |||
141 | it('Should send a new comment notification after a remote reply on my video', async function () { | ||
142 | this.timeout(10000) | ||
143 | |||
144 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
145 | const uuid = resVideo.body.video.uuid | ||
146 | await waitJobs(servers) | ||
147 | |||
148 | { | ||
149 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') | ||
150 | const threadId = resThread.body.comment.id | ||
151 | await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') | ||
152 | } | ||
153 | |||
154 | await waitJobs(servers) | ||
155 | |||
156 | const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
157 | expect(resThread.body.data).to.have.lengthOf(1) | ||
158 | const threadId = resThread.body.data[0].id | ||
159 | |||
160 | const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId) | ||
161 | const tree = resComments.body as VideoCommentThreadTree | ||
162 | |||
163 | expect(tree.children).to.have.lengthOf(1) | ||
164 | const commentId = tree.children[0].comment.id | ||
165 | |||
166 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | ||
167 | }) | ||
168 | }) | ||
169 | |||
170 | describe('Mention notifications', function () { | ||
171 | let baseParams: CheckerBaseParams | ||
172 | |||
173 | before(async () => { | ||
174 | baseParams = { | ||
175 | server: servers[0], | ||
176 | emails, | ||
177 | socketNotifications: userNotifications, | ||
178 | token: userAccessToken | ||
179 | } | ||
180 | |||
181 | await updateMyUser({ | ||
182 | url: servers[0].url, | ||
183 | accessToken: servers[0].accessToken, | ||
184 | displayName: 'super root name' | ||
185 | }) | ||
186 | |||
187 | await updateMyUser({ | ||
188 | url: servers[1].url, | ||
189 | accessToken: servers[1].accessToken, | ||
190 | displayName: 'super root 2 name' | ||
191 | }) | ||
192 | }) | ||
193 | |||
194 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | ||
195 | this.timeout(10000) | ||
196 | |||
197 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
198 | const uuid = resVideo.body.video.uuid | ||
199 | |||
200 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
201 | const commentId = resComment.body.comment.id | ||
202 | |||
203 | await wait(500) | ||
204 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
205 | }) | ||
206 | |||
207 | it('Should not send a new mention comment notification if I mention myself', async function () { | ||
208 | this.timeout(10000) | ||
209 | |||
210 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
211 | const uuid = resVideo.body.video.uuid | ||
212 | |||
213 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') | ||
214 | const commentId = resComment.body.comment.id | ||
215 | |||
216 | await wait(500) | ||
217 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
218 | }) | ||
219 | |||
220 | it('Should not send a new mention notification if the account is muted', async function () { | ||
221 | this.timeout(10000) | ||
222 | |||
223 | await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
224 | |||
225 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
226 | const uuid = resVideo.body.video.uuid | ||
227 | |||
228 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
229 | const commentId = resComment.body.comment.id | ||
230 | |||
231 | await wait(500) | ||
232 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
233 | |||
234 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
235 | }) | ||
236 | |||
237 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | ||
238 | this.timeout(20000) | ||
239 | |||
240 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
241 | const uuid = resVideo.body.video.uuid | ||
242 | |||
243 | await waitJobs(servers) | ||
244 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello') | ||
245 | const threadId = resThread.body.comment.id | ||
246 | |||
247 | await waitJobs(servers) | ||
248 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') | ||
249 | }) | ||
250 | |||
251 | it('Should send a new mention notification after local comments', async function () { | ||
252 | this.timeout(10000) | ||
253 | |||
254 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
255 | const uuid = resVideo.body.video.uuid | ||
256 | |||
257 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') | ||
258 | const threadId = resThread.body.comment.id | ||
259 | |||
260 | await wait(500) | ||
261 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') | ||
262 | |||
263 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') | ||
264 | const commentId = resComment.body.comment.id | ||
265 | |||
266 | await wait(500) | ||
267 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') | ||
268 | }) | ||
269 | |||
270 | it('Should send a new mention notification after remote comments', async function () { | ||
271 | this.timeout(20000) | ||
272 | |||
273 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
274 | const uuid = resVideo.body.video.uuid | ||
275 | |||
276 | await waitJobs(servers) | ||
277 | |||
278 | const text1 = `hello @user_1@localhost:${servers[0].port} 1` | ||
279 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) | ||
280 | const server2ThreadId = resThread.body.comment.id | ||
281 | |||
282 | await waitJobs(servers) | ||
283 | |||
284 | const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
285 | expect(resThread2.body.data).to.have.lengthOf(1) | ||
286 | const server1ThreadId = resThread2.body.data[0].id | ||
287 | await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') | ||
288 | |||
289 | const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` | ||
290 | await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) | ||
291 | |||
292 | await waitJobs(servers) | ||
293 | |||
294 | const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId) | ||
295 | const tree = resComments.body as VideoCommentThreadTree | ||
296 | |||
297 | expect(tree.children).to.have.lengthOf(1) | ||
298 | const commentId = tree.children[0].comment.id | ||
299 | |||
300 | await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') | ||
301 | }) | ||
302 | }) | ||
303 | |||
304 | after(async function () { | ||
305 | MockSmtpServer.Instance.kill() | ||
306 | |||
307 | await cleanupTests(servers) | ||
308 | }) | ||
309 | }) | ||
diff --git a/server/tests/api/notifications/index.ts b/server/tests/api/notifications/index.ts index b573f850e..bd07a339e 100644 --- a/server/tests/api/notifications/index.ts +++ b/server/tests/api/notifications/index.ts | |||
@@ -1 +1,4 @@ | |||
1 | import './comments-notifications' | ||
2 | import './moderation-notifications' | ||
3 | import './notifications-api' | ||
1 | import './user-notifications' | 4 | import './user-notifications' |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts new file mode 100644 index 000000000..b90732a7a --- /dev/null +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -0,0 +1,439 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { v4 as uuidv4 } from 'uuid' | ||
5 | import { | ||
6 | addVideoToBlacklist, | ||
7 | cleanupTests, | ||
8 | follow, | ||
9 | getCustomConfig, | ||
10 | immutableAssign, | ||
11 | MockInstancesIndex, | ||
12 | registerUser, | ||
13 | removeVideoFromBlacklist, | ||
14 | reportVideoAbuse, | ||
15 | unfollow, | ||
16 | updateCustomConfig, | ||
17 | updateCustomSubConfig, | ||
18 | wait | ||
19 | } from '../../../../shared/extra-utils' | ||
20 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | ||
21 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
23 | import { | ||
24 | checkAutoInstanceFollowing, | ||
25 | CheckerBaseParams, | ||
26 | checkNewBlacklistOnMyVideo, | ||
27 | checkNewInstanceFollower, | ||
28 | checkNewVideoAbuseForModerators, | ||
29 | checkNewVideoFromSubscription, | ||
30 | checkUserRegistered, | ||
31 | checkVideoAutoBlacklistForModerators, | ||
32 | checkVideoIsPublished, | ||
33 | prepareNotificationsTest | ||
34 | } from '../../../../shared/extra-utils/users/user-notifications' | ||
35 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | ||
36 | import { CustomConfig } from '../../../../shared/models/server' | ||
37 | import { UserNotification } from '../../../../shared/models/users' | ||
38 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
39 | |||
40 | describe('Test moderation notifications', function () { | ||
41 | let servers: ServerInfo[] = [] | ||
42 | let userAccessToken: string | ||
43 | let userNotifications: UserNotification[] = [] | ||
44 | let adminNotifications: UserNotification[] = [] | ||
45 | let adminNotificationsServer2: UserNotification[] = [] | ||
46 | let emails: object[] = [] | ||
47 | |||
48 | before(async function () { | ||
49 | this.timeout(120000) | ||
50 | |||
51 | const res = await prepareNotificationsTest(3) | ||
52 | emails = res.emails | ||
53 | userAccessToken = res.userAccessToken | ||
54 | servers = res.servers | ||
55 | userNotifications = res.userNotifications | ||
56 | adminNotifications = res.adminNotifications | ||
57 | adminNotificationsServer2 = res.adminNotificationsServer2 | ||
58 | }) | ||
59 | |||
60 | describe('Video abuse for moderators notification', function () { | ||
61 | let baseParams: CheckerBaseParams | ||
62 | |||
63 | before(() => { | ||
64 | baseParams = { | ||
65 | server: servers[0], | ||
66 | emails, | ||
67 | socketNotifications: adminNotifications, | ||
68 | token: servers[0].accessToken | ||
69 | } | ||
70 | }) | ||
71 | |||
72 | it('Should send a notification to moderators on local video abuse', async function () { | ||
73 | this.timeout(10000) | ||
74 | |||
75 | const name = 'video for abuse ' + uuidv4() | ||
76 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
77 | const uuid = resVideo.body.video.uuid | ||
78 | |||
79 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') | ||
80 | |||
81 | await waitJobs(servers) | ||
82 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | ||
83 | }) | ||
84 | |||
85 | it('Should send a notification to moderators on remote video abuse', async function () { | ||
86 | this.timeout(10000) | ||
87 | |||
88 | const name = 'video for abuse ' + uuidv4() | ||
89 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
90 | const uuid = resVideo.body.video.uuid | ||
91 | |||
92 | await waitJobs(servers) | ||
93 | |||
94 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') | ||
95 | |||
96 | await waitJobs(servers) | ||
97 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | ||
98 | }) | ||
99 | }) | ||
100 | |||
101 | describe('Video blacklist on my video', function () { | ||
102 | let baseParams: CheckerBaseParams | ||
103 | |||
104 | before(() => { | ||
105 | baseParams = { | ||
106 | server: servers[0], | ||
107 | emails, | ||
108 | socketNotifications: userNotifications, | ||
109 | token: userAccessToken | ||
110 | } | ||
111 | }) | ||
112 | |||
113 | it('Should send a notification to video owner on blacklist', async function () { | ||
114 | this.timeout(10000) | ||
115 | |||
116 | const name = 'video for abuse ' + uuidv4() | ||
117 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
118 | const uuid = resVideo.body.video.uuid | ||
119 | |||
120 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
121 | |||
122 | await waitJobs(servers) | ||
123 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | ||
124 | }) | ||
125 | |||
126 | it('Should send a notification to video owner on unblacklist', async function () { | ||
127 | this.timeout(10000) | ||
128 | |||
129 | const name = 'video for abuse ' + uuidv4() | ||
130 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
131 | const uuid = resVideo.body.video.uuid | ||
132 | |||
133 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
134 | |||
135 | await waitJobs(servers) | ||
136 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
137 | await waitJobs(servers) | ||
138 | |||
139 | await wait(500) | ||
140 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | ||
141 | }) | ||
142 | }) | ||
143 | |||
144 | describe('New registration', function () { | ||
145 | let baseParams: CheckerBaseParams | ||
146 | |||
147 | before(() => { | ||
148 | baseParams = { | ||
149 | server: servers[0], | ||
150 | emails, | ||
151 | socketNotifications: adminNotifications, | ||
152 | token: servers[0].accessToken | ||
153 | } | ||
154 | }) | ||
155 | |||
156 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | ||
157 | this.timeout(10000) | ||
158 | |||
159 | await registerUser(servers[0].url, 'user_45', 'password') | ||
160 | |||
161 | await waitJobs(servers) | ||
162 | |||
163 | await checkUserRegistered(baseParams, 'user_45', 'presence') | ||
164 | |||
165 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
166 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | ||
167 | }) | ||
168 | }) | ||
169 | |||
170 | describe('New instance follows', function () { | ||
171 | const instanceIndexServer = new MockInstancesIndex() | ||
172 | const config = { | ||
173 | followings: { | ||
174 | instance: { | ||
175 | autoFollowIndex: { | ||
176 | indexUrl: 'http://localhost:42101/api/v1/instances/hosts', | ||
177 | enabled: true | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | let baseParams: CheckerBaseParams | ||
183 | |||
184 | before(async () => { | ||
185 | baseParams = { | ||
186 | server: servers[0], | ||
187 | emails, | ||
188 | socketNotifications: adminNotifications, | ||
189 | token: servers[0].accessToken | ||
190 | } | ||
191 | |||
192 | await instanceIndexServer.initialize() | ||
193 | instanceIndexServer.addInstance(servers[1].host) | ||
194 | }) | ||
195 | |||
196 | it('Should send a notification only to admin when there is a new instance follower', async function () { | ||
197 | this.timeout(20000) | ||
198 | |||
199 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
200 | |||
201 | await waitJobs(servers) | ||
202 | |||
203 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | ||
204 | |||
205 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
206 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | ||
207 | }) | ||
208 | |||
209 | it('Should send a notification on auto follow back', async function () { | ||
210 | this.timeout(40000) | ||
211 | |||
212 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
213 | await waitJobs(servers) | ||
214 | |||
215 | const config = { | ||
216 | followings: { | ||
217 | instance: { | ||
218 | autoFollowBack: { enabled: true } | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
223 | |||
224 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
225 | |||
226 | await waitJobs(servers) | ||
227 | |||
228 | const followerHost = servers[0].host | ||
229 | const followingHost = servers[2].host | ||
230 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
231 | |||
232 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
233 | await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') | ||
234 | |||
235 | config.followings.instance.autoFollowBack.enabled = false | ||
236 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
237 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | ||
238 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
239 | }) | ||
240 | |||
241 | it('Should send a notification on auto instances index follow', async function () { | ||
242 | this.timeout(30000) | ||
243 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
244 | |||
245 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
246 | |||
247 | await wait(5000) | ||
248 | await waitJobs(servers) | ||
249 | |||
250 | const followerHost = servers[0].host | ||
251 | const followingHost = servers[1].host | ||
252 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
253 | |||
254 | config.followings.instance.autoFollowIndex.enabled = false | ||
255 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
256 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
257 | }) | ||
258 | }) | ||
259 | |||
260 | describe('Video-related notifications when video auto-blacklist is enabled', function () { | ||
261 | let userBaseParams: CheckerBaseParams | ||
262 | let adminBaseParamsServer1: CheckerBaseParams | ||
263 | let adminBaseParamsServer2: CheckerBaseParams | ||
264 | let videoUUID: string | ||
265 | let videoName: string | ||
266 | let currentCustomConfig: CustomConfig | ||
267 | |||
268 | before(async () => { | ||
269 | |||
270 | adminBaseParamsServer1 = { | ||
271 | server: servers[0], | ||
272 | emails, | ||
273 | socketNotifications: adminNotifications, | ||
274 | token: servers[0].accessToken | ||
275 | } | ||
276 | |||
277 | adminBaseParamsServer2 = { | ||
278 | server: servers[1], | ||
279 | emails, | ||
280 | socketNotifications: adminNotificationsServer2, | ||
281 | token: servers[1].accessToken | ||
282 | } | ||
283 | |||
284 | userBaseParams = { | ||
285 | server: servers[0], | ||
286 | emails, | ||
287 | socketNotifications: userNotifications, | ||
288 | token: userAccessToken | ||
289 | } | ||
290 | |||
291 | const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) | ||
292 | currentCustomConfig = resCustomConfig.body | ||
293 | const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { | ||
294 | autoBlacklist: { | ||
295 | videos: { | ||
296 | ofUsers: { | ||
297 | enabled: true | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | }) | ||
302 | // enable transcoding otherwise own publish notification after transcoding not expected | ||
303 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | ||
304 | await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) | ||
305 | |||
306 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
307 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
308 | |||
309 | }) | ||
310 | |||
311 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | ||
312 | this.timeout(20000) | ||
313 | |||
314 | videoName = 'video with auto-blacklist ' + uuidv4() | ||
315 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) | ||
316 | videoUUID = resVideo.body.video.uuid | ||
317 | |||
318 | await waitJobs(servers) | ||
319 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | ||
320 | }) | ||
321 | |||
322 | it('Should not send video publish notification if auto-blacklisted', async function () { | ||
323 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | ||
324 | }) | ||
325 | |||
326 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | ||
327 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | ||
328 | }) | ||
329 | |||
330 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | ||
331 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | ||
332 | }) | ||
333 | |||
334 | it('Should send video published and unblacklist after video unblacklisted', async function () { | ||
335 | this.timeout(20000) | ||
336 | |||
337 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) | ||
338 | |||
339 | await waitJobs(servers) | ||
340 | |||
341 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | ||
342 | // One notification might be better anyways | ||
343 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | ||
344 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | ||
345 | }) | ||
346 | |||
347 | it('Should send a local user subscription notification after removed from blacklist', async function () { | ||
348 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | ||
349 | }) | ||
350 | |||
351 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | ||
352 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | ||
353 | }) | ||
354 | |||
355 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | ||
356 | this.timeout(20000) | ||
357 | |||
358 | const updateAt = new Date(new Date().getTime() + 1000000) | ||
359 | |||
360 | const name = 'video with auto-blacklist and future schedule ' + uuidv4() | ||
361 | |||
362 | const data = { | ||
363 | name, | ||
364 | privacy: VideoPrivacy.PRIVATE, | ||
365 | scheduleUpdate: { | ||
366 | updateAt: updateAt.toISOString(), | ||
367 | privacy: VideoPrivacy.PUBLIC | ||
368 | } | ||
369 | } | ||
370 | |||
371 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | ||
372 | const uuid = resVideo.body.video.uuid | ||
373 | |||
374 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
375 | |||
376 | await waitJobs(servers) | ||
377 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | ||
378 | |||
379 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | ||
380 | // One notification might be better anyways | ||
381 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | ||
382 | |||
383 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | ||
384 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | ||
385 | }) | ||
386 | |||
387 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | ||
388 | this.timeout(20000) | ||
389 | |||
390 | // In 2 seconds | ||
391 | const updateAt = new Date(new Date().getTime() + 2000) | ||
392 | |||
393 | const name = 'video with schedule done and still auto-blacklisted ' + uuidv4() | ||
394 | |||
395 | const data = { | ||
396 | name, | ||
397 | privacy: VideoPrivacy.PRIVATE, | ||
398 | scheduleUpdate: { | ||
399 | updateAt: updateAt.toISOString(), | ||
400 | privacy: VideoPrivacy.PUBLIC | ||
401 | } | ||
402 | } | ||
403 | |||
404 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | ||
405 | const uuid = resVideo.body.video.uuid | ||
406 | |||
407 | await wait(6000) | ||
408 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | ||
409 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | ||
410 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | ||
411 | }) | ||
412 | |||
413 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | ||
414 | this.timeout(20000) | ||
415 | |||
416 | const name = 'video without auto-blacklist ' + uuidv4() | ||
417 | |||
418 | // admin with blacklist right will not be auto-blacklisted | ||
419 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | ||
420 | const uuid = resVideo.body.video.uuid | ||
421 | |||
422 | await waitJobs(servers) | ||
423 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | ||
424 | }) | ||
425 | |||
426 | after(async () => { | ||
427 | await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) | ||
428 | |||
429 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
430 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
431 | }) | ||
432 | }) | ||
433 | |||
434 | after(async function () { | ||
435 | MockSmtpServer.Instance.kill() | ||
436 | |||
437 | await cleanupTests(servers) | ||
438 | }) | ||
439 | }) | ||
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts new file mode 100644 index 000000000..b81995449 --- /dev/null +++ b/server/tests/api/notifications/notifications-api.ts | |||
@@ -0,0 +1,205 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { addUserSubscription } from '@shared/extra-utils/users/user-subscriptions' | ||
6 | import { cleanupTests, getMyUserInformation, immutableAssign, uploadRandomVideo, waitJobs } from '../../../../shared/extra-utils' | ||
7 | import { ServerInfo } from '../../../../shared/extra-utils/index' | ||
8 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
9 | import { | ||
10 | CheckerBaseParams, | ||
11 | checkNewVideoFromSubscription, | ||
12 | getAllNotificationsSettings, | ||
13 | getUserNotifications, | ||
14 | markAsReadAllNotifications, | ||
15 | markAsReadNotifications, | ||
16 | prepareNotificationsTest, | ||
17 | updateMyNotificationSettings | ||
18 | } from '../../../../shared/extra-utils/users/user-notifications' | ||
19 | import { User, UserNotification, UserNotificationSettingValue } from '../../../../shared/models/users' | ||
20 | |||
21 | const expect = chai.expect | ||
22 | |||
23 | describe('Test notifications API', function () { | ||
24 | let server: ServerInfo | ||
25 | let userNotifications: UserNotification[] = [] | ||
26 | let userAccessToken: string | ||
27 | let emails: object[] = [] | ||
28 | |||
29 | before(async function () { | ||
30 | this.timeout(120000) | ||
31 | |||
32 | const res = await prepareNotificationsTest(1) | ||
33 | emails = res.emails | ||
34 | userAccessToken = res.userAccessToken | ||
35 | userNotifications = res.userNotifications | ||
36 | server = res.servers[0] | ||
37 | |||
38 | await addUserSubscription(server.url, userAccessToken, 'root_channel@localhost:' + server.port) | ||
39 | |||
40 | for (let i = 0; i < 10; i++) { | ||
41 | await uploadRandomVideo(server, false) | ||
42 | } | ||
43 | |||
44 | await waitJobs([ server ]) | ||
45 | }) | ||
46 | |||
47 | describe('Mark as read', function () { | ||
48 | |||
49 | it('Should mark as read some notifications', async function () { | ||
50 | const res = await getUserNotifications(server.url, userAccessToken, 2, 3) | ||
51 | const ids = res.body.data.map(n => n.id) | ||
52 | |||
53 | await markAsReadNotifications(server.url, userAccessToken, ids) | ||
54 | }) | ||
55 | |||
56 | it('Should have the notifications marked as read', async function () { | ||
57 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10) | ||
58 | |||
59 | const notifications = res.body.data as UserNotification[] | ||
60 | expect(notifications[0].read).to.be.false | ||
61 | expect(notifications[1].read).to.be.false | ||
62 | expect(notifications[2].read).to.be.true | ||
63 | expect(notifications[3].read).to.be.true | ||
64 | expect(notifications[4].read).to.be.true | ||
65 | expect(notifications[5].read).to.be.false | ||
66 | }) | ||
67 | |||
68 | it('Should only list read notifications', async function () { | ||
69 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, false) | ||
70 | |||
71 | const notifications = res.body.data as UserNotification[] | ||
72 | for (const notification of notifications) { | ||
73 | expect(notification.read).to.be.true | ||
74 | } | ||
75 | }) | ||
76 | |||
77 | it('Should only list unread notifications', async function () { | ||
78 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) | ||
79 | |||
80 | const notifications = res.body.data as UserNotification[] | ||
81 | for (const notification of notifications) { | ||
82 | expect(notification.read).to.be.false | ||
83 | } | ||
84 | }) | ||
85 | |||
86 | it('Should mark as read all notifications', async function () { | ||
87 | await markAsReadAllNotifications(server.url, userAccessToken) | ||
88 | |||
89 | const res = await getUserNotifications(server.url, userAccessToken, 0, 10, true) | ||
90 | |||
91 | expect(res.body.total).to.equal(0) | ||
92 | expect(res.body.data).to.have.lengthOf(0) | ||
93 | }) | ||
94 | }) | ||
95 | |||
96 | describe('Notification settings', function () { | ||
97 | let baseParams: CheckerBaseParams | ||
98 | |||
99 | before(() => { | ||
100 | baseParams = { | ||
101 | server: server, | ||
102 | emails, | ||
103 | socketNotifications: userNotifications, | ||
104 | token: userAccessToken | ||
105 | } | ||
106 | }) | ||
107 | |||
108 | it('Should not have notifications', async function () { | ||
109 | this.timeout(20000) | ||
110 | |||
111 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | ||
112 | newVideoFromSubscription: UserNotificationSettingValue.NONE | ||
113 | })) | ||
114 | |||
115 | { | ||
116 | const res = await getMyUserInformation(server.url, userAccessToken) | ||
117 | const info = res.body as User | ||
118 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | ||
119 | } | ||
120 | |||
121 | const { name, uuid } = await uploadRandomVideo(server) | ||
122 | |||
123 | const check = { web: true, mail: true } | ||
124 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
125 | }) | ||
126 | |||
127 | it('Should only have web notifications', async function () { | ||
128 | this.timeout(20000) | ||
129 | |||
130 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | ||
131 | newVideoFromSubscription: UserNotificationSettingValue.WEB | ||
132 | })) | ||
133 | |||
134 | { | ||
135 | const res = await getMyUserInformation(server.url, userAccessToken) | ||
136 | const info = res.body as User | ||
137 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | ||
138 | } | ||
139 | |||
140 | const { name, uuid } = await uploadRandomVideo(server) | ||
141 | |||
142 | { | ||
143 | const check = { mail: true, web: false } | ||
144 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
145 | } | ||
146 | |||
147 | { | ||
148 | const check = { mail: false, web: true } | ||
149 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | ||
150 | } | ||
151 | }) | ||
152 | |||
153 | it('Should only have mail notifications', async function () { | ||
154 | this.timeout(20000) | ||
155 | |||
156 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | ||
157 | newVideoFromSubscription: UserNotificationSettingValue.EMAIL | ||
158 | })) | ||
159 | |||
160 | { | ||
161 | const res = await getMyUserInformation(server.url, userAccessToken) | ||
162 | const info = res.body as User | ||
163 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | ||
164 | } | ||
165 | |||
166 | const { name, uuid } = await uploadRandomVideo(server) | ||
167 | |||
168 | { | ||
169 | const check = { mail: false, web: true } | ||
170 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
171 | } | ||
172 | |||
173 | { | ||
174 | const check = { mail: true, web: false } | ||
175 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | ||
176 | } | ||
177 | }) | ||
178 | |||
179 | it('Should have email and web notifications', async function () { | ||
180 | this.timeout(20000) | ||
181 | |||
182 | await updateMyNotificationSettings(server.url, userAccessToken, immutableAssign(getAllNotificationsSettings(), { | ||
183 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
184 | })) | ||
185 | |||
186 | { | ||
187 | const res = await getMyUserInformation(server.url, userAccessToken) | ||
188 | const info = res.body as User | ||
189 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( | ||
190 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
191 | ) | ||
192 | } | ||
193 | |||
194 | const { name, uuid } = await uploadRandomVideo(server) | ||
195 | |||
196 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | ||
197 | }) | ||
198 | }) | ||
199 | |||
200 | after(async function () { | ||
201 | MockSmtpServer.Instance.kill() | ||
202 | |||
203 | await cleanupTests([ server ]) | ||
204 | }) | ||
205 | }) | ||
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 04abc6738..e5f6aa864 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -1,176 +1,55 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { v4 as uuidv4 } from 'uuid' | ||
5 | import { | 6 | import { |
6 | addVideoToBlacklist, | ||
7 | cleanupTests, | 7 | cleanupTests, |
8 | createUser, | ||
9 | doubleFollow, | ||
10 | flushAndRunMultipleServers, | ||
11 | follow, | ||
12 | getCustomConfig, | ||
13 | getMyUserInformation, | ||
14 | getVideoCommentThreads, | ||
15 | getVideoThreadComments, | ||
16 | immutableAssign, | ||
17 | MockInstancesIndex, | ||
18 | registerUser, | ||
19 | removeVideoFromBlacklist, | ||
20 | reportVideoAbuse, | ||
21 | unfollow, | ||
22 | updateCustomConfig, | ||
23 | updateCustomSubConfig, | ||
24 | updateMyUser, | 8 | updateMyUser, |
25 | updateVideo, | 9 | updateVideo, |
26 | updateVideoChannel, | 10 | updateVideoChannel, |
27 | userLogin, | 11 | uploadRandomVideoOnServers, |
28 | wait | 12 | wait |
29 | } from '../../../../shared/extra-utils' | 13 | } from '../../../../shared/extra-utils' |
30 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | 14 | import { ServerInfo } from '../../../../shared/extra-utils/index' |
31 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 15 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' |
32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 16 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
33 | import { getUserNotificationSocket } from '../../../../shared/extra-utils/socket/socket-io' | ||
34 | import { | 17 | import { |
35 | checkAutoInstanceFollowing, | ||
36 | checkCommentMention, | ||
37 | CheckerBaseParams, | 18 | CheckerBaseParams, |
38 | checkMyVideoImportIsFinished, | 19 | checkMyVideoImportIsFinished, |
39 | checkNewActorFollow, | 20 | checkNewActorFollow, |
40 | checkNewBlacklistOnMyVideo, | ||
41 | checkNewCommentOnMyVideo, | ||
42 | checkNewInstanceFollower, | ||
43 | checkNewVideoAbuseForModerators, | ||
44 | checkNewVideoFromSubscription, | 21 | checkNewVideoFromSubscription, |
45 | checkUserRegistered, | ||
46 | checkVideoAutoBlacklistForModerators, | ||
47 | checkVideoIsPublished, | 22 | checkVideoIsPublished, |
48 | getLastNotification, | 23 | getLastNotification, |
49 | getUserNotifications, | 24 | prepareNotificationsTest |
50 | markAsReadAllNotifications, | ||
51 | markAsReadNotifications, | ||
52 | updateMyNotificationSettings | ||
53 | } from '../../../../shared/extra-utils/users/user-notifications' | 25 | } from '../../../../shared/extra-utils/users/user-notifications' |
54 | import { | ||
55 | User, | ||
56 | UserNotification, | ||
57 | UserNotificationSetting, | ||
58 | UserNotificationSettingValue, | ||
59 | UserNotificationType | ||
60 | } from '../../../../shared/models/users' | ||
61 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
62 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' | 26 | import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' |
63 | import { VideoPrivacy } from '../../../../shared/models/videos' | ||
64 | import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' | 27 | import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' |
65 | import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' | 28 | import { UserNotification, UserNotificationType } from '../../../../shared/models/users' |
66 | import { v4 as uuidv4 } from 'uuid' | 29 | import { VideoPrivacy } from '../../../../shared/models/videos' |
67 | import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist' | ||
68 | import { CustomConfig } from '../../../../shared/models/server' | ||
69 | import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' | ||
70 | 30 | ||
71 | const expect = chai.expect | 31 | const expect = chai.expect |
72 | 32 | ||
73 | async function uploadVideoByRemoteAccount (servers: ServerInfo[], additionalParams: any = {}) { | 33 | describe('Test user notifications', function () { |
74 | const name = 'remote video ' + uuidv4() | ||
75 | |||
76 | const data = Object.assign({ name }, additionalParams) | ||
77 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, data) | ||
78 | |||
79 | await waitJobs(servers) | ||
80 | |||
81 | return { uuid: res.body.video.uuid, name } | ||
82 | } | ||
83 | |||
84 | async function uploadVideoByLocalAccount (servers: ServerInfo[], additionalParams: any = {}) { | ||
85 | const name = 'local video ' + uuidv4() | ||
86 | |||
87 | const data = Object.assign({ name }, additionalParams) | ||
88 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, data) | ||
89 | |||
90 | await waitJobs(servers) | ||
91 | |||
92 | return { uuid: res.body.video.uuid, name } | ||
93 | } | ||
94 | |||
95 | describe('Test users notifications', function () { | ||
96 | let servers: ServerInfo[] = [] | 34 | let servers: ServerInfo[] = [] |
97 | let userAccessToken: string | 35 | let userAccessToken: string |
98 | const userNotifications: UserNotification[] = [] | 36 | let userNotifications: UserNotification[] = [] |
99 | const adminNotifications: UserNotification[] = [] | 37 | let adminNotifications: UserNotification[] = [] |
100 | const adminNotificationsServer2: UserNotification[] = [] | 38 | let adminNotificationsServer2: UserNotification[] = [] |
101 | const emails: object[] = [] | 39 | let emails: object[] = [] |
102 | let channelId: number | 40 | let channelId: number |
103 | 41 | ||
104 | const allNotificationSettings: UserNotificationSetting = { | ||
105 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
106 | newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
107 | videoAbuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
108 | videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
109 | blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
110 | myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
111 | myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
112 | commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
113 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
114 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
115 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
116 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
117 | } | ||
118 | |||
119 | before(async function () { | 42 | before(async function () { |
120 | this.timeout(120000) | 43 | this.timeout(120000) |
121 | 44 | ||
122 | const port = await MockSmtpServer.Instance.collectEmails(emails) | 45 | const res = await prepareNotificationsTest(3) |
123 | 46 | emails = res.emails | |
124 | const overrideConfig = { | 47 | userAccessToken = res.userAccessToken |
125 | smtp: { | 48 | servers = res.servers |
126 | hostname: 'localhost', | 49 | userNotifications = res.userNotifications |
127 | port | 50 | adminNotifications = res.adminNotifications |
128 | } | 51 | adminNotificationsServer2 = res.adminNotificationsServer2 |
129 | } | 52 | channelId = res.channelId |
130 | servers = await flushAndRunMultipleServers(3, overrideConfig) | ||
131 | |||
132 | // Get the access tokens | ||
133 | await setAccessTokensToServers(servers) | ||
134 | |||
135 | // Server 1 and server 2 follow each other | ||
136 | await doubleFollow(servers[0], servers[1]) | ||
137 | |||
138 | await waitJobs(servers) | ||
139 | |||
140 | const user = { | ||
141 | username: 'user_1', | ||
142 | password: 'super password' | ||
143 | } | ||
144 | await createUser({ | ||
145 | url: servers[0].url, | ||
146 | accessToken: servers[0].accessToken, | ||
147 | username: user.username, | ||
148 | password: user.password, | ||
149 | videoQuota: 10 * 1000 * 1000 | ||
150 | }) | ||
151 | userAccessToken = await userLogin(servers[0], user) | ||
152 | |||
153 | await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings) | ||
154 | await updateMyNotificationSettings(servers[0].url, servers[0].accessToken, allNotificationSettings) | ||
155 | await updateMyNotificationSettings(servers[1].url, servers[1].accessToken, allNotificationSettings) | ||
156 | |||
157 | { | ||
158 | const socket = getUserNotificationSocket(servers[0].url, userAccessToken) | ||
159 | socket.on('new-notification', n => userNotifications.push(n)) | ||
160 | } | ||
161 | { | ||
162 | const socket = getUserNotificationSocket(servers[0].url, servers[0].accessToken) | ||
163 | socket.on('new-notification', n => adminNotifications.push(n)) | ||
164 | } | ||
165 | { | ||
166 | const socket = getUserNotificationSocket(servers[1].url, servers[1].accessToken) | ||
167 | socket.on('new-notification', n => adminNotificationsServer2.push(n)) | ||
168 | } | ||
169 | |||
170 | { | ||
171 | const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
172 | channelId = resChannel.body.videoChannels[0].id | ||
173 | } | ||
174 | }) | 53 | }) |
175 | 54 | ||
176 | describe('New video from my subscription notification', function () { | 55 | describe('New video from my subscription notification', function () { |
@@ -188,7 +67,7 @@ describe('Test users notifications', function () { | |||
188 | it('Should not send notifications if the user does not follow the video publisher', async function () { | 67 | it('Should not send notifications if the user does not follow the video publisher', async function () { |
189 | this.timeout(10000) | 68 | this.timeout(10000) |
190 | 69 | ||
191 | await uploadVideoByLocalAccount(servers) | 70 | await uploadRandomVideoOnServers(servers, 1) |
192 | 71 | ||
193 | const notification = await getLastNotification(servers[0].url, userAccessToken) | 72 | const notification = await getLastNotification(servers[0].url, userAccessToken) |
194 | expect(notification).to.be.undefined | 73 | expect(notification).to.be.undefined |
@@ -203,7 +82,7 @@ describe('Test users notifications', function () { | |||
203 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) | 82 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) |
204 | await waitJobs(servers) | 83 | await waitJobs(servers) |
205 | 84 | ||
206 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | 85 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) |
207 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 86 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
208 | }) | 87 | }) |
209 | 88 | ||
@@ -213,7 +92,7 @@ describe('Test users notifications', function () { | |||
213 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) | 92 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[1].port) |
214 | await waitJobs(servers) | 93 | await waitJobs(servers) |
215 | 94 | ||
216 | const { name, uuid } = await uploadVideoByRemoteAccount(servers) | 95 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2) |
217 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 96 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
218 | }) | 97 | }) |
219 | 98 | ||
@@ -230,7 +109,7 @@ describe('Test users notifications', function () { | |||
230 | privacy: VideoPrivacy.PUBLIC | 109 | privacy: VideoPrivacy.PUBLIC |
231 | } | 110 | } |
232 | } | 111 | } |
233 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | 112 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
234 | 113 | ||
235 | await wait(6000) | 114 | await wait(6000) |
236 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | 115 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') |
@@ -249,7 +128,7 @@ describe('Test users notifications', function () { | |||
249 | privacy: VideoPrivacy.PUBLIC | 128 | privacy: VideoPrivacy.PUBLIC |
250 | } | 129 | } |
251 | } | 130 | } |
252 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | 131 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
253 | await waitJobs(servers) | 132 | await waitJobs(servers) |
254 | 133 | ||
255 | await wait(6000) | 134 | await wait(6000) |
@@ -268,7 +147,7 @@ describe('Test users notifications', function () { | |||
268 | privacy: VideoPrivacy.PUBLIC | 147 | privacy: VideoPrivacy.PUBLIC |
269 | } | 148 | } |
270 | } | 149 | } |
271 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | 150 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
272 | 151 | ||
273 | await wait(6000) | 152 | await wait(6000) |
274 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 153 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
@@ -278,7 +157,7 @@ describe('Test users notifications', function () { | |||
278 | this.timeout(10000) | 157 | this.timeout(10000) |
279 | 158 | ||
280 | const data = { privacy: VideoPrivacy.PRIVATE } | 159 | const data = { privacy: VideoPrivacy.PRIVATE } |
281 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | 160 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
282 | 161 | ||
283 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 162 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
284 | 163 | ||
@@ -292,7 +171,7 @@ describe('Test users notifications', function () { | |||
292 | this.timeout(20000) | 171 | this.timeout(20000) |
293 | 172 | ||
294 | const data = { privacy: VideoPrivacy.PRIVATE } | 173 | const data = { privacy: VideoPrivacy.PRIVATE } |
295 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | 174 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
296 | 175 | ||
297 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') | 176 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'absence') |
298 | 177 | ||
@@ -306,7 +185,7 @@ describe('Test users notifications', function () { | |||
306 | this.timeout(20000) | 185 | this.timeout(20000) |
307 | 186 | ||
308 | const data = { privacy: VideoPrivacy.PRIVATE } | 187 | const data = { privacy: VideoPrivacy.PRIVATE } |
309 | const { name, uuid } = await uploadVideoByLocalAccount(servers, data) | 188 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1, data) |
310 | 189 | ||
311 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | 190 | await updateVideo(servers[0].url, servers[0].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) |
312 | 191 | ||
@@ -317,7 +196,7 @@ describe('Test users notifications', function () { | |||
317 | this.timeout(20000) | 196 | this.timeout(20000) |
318 | 197 | ||
319 | const data = { privacy: VideoPrivacy.PRIVATE } | 198 | const data = { privacy: VideoPrivacy.PRIVATE } |
320 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | 199 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
321 | 200 | ||
322 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) | 201 | await updateVideo(servers[1].url, servers[1].accessToken, uuid, { privacy: VideoPrivacy.UNLISTED }) |
323 | 202 | ||
@@ -345,356 +224,6 @@ describe('Test users notifications', function () { | |||
345 | }) | 224 | }) |
346 | }) | 225 | }) |
347 | 226 | ||
348 | describe('Comment on my video notifications', function () { | ||
349 | let baseParams: CheckerBaseParams | ||
350 | |||
351 | before(() => { | ||
352 | baseParams = { | ||
353 | server: servers[0], | ||
354 | emails, | ||
355 | socketNotifications: userNotifications, | ||
356 | token: userAccessToken | ||
357 | } | ||
358 | }) | ||
359 | |||
360 | it('Should not send a new comment notification after a comment on another video', async function () { | ||
361 | this.timeout(10000) | ||
362 | |||
363 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
364 | const uuid = resVideo.body.video.uuid | ||
365 | |||
366 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
367 | const commentId = resComment.body.comment.id | ||
368 | |||
369 | await wait(500) | ||
370 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | ||
371 | }) | ||
372 | |||
373 | it('Should not send a new comment notification if I comment my own video', async function () { | ||
374 | this.timeout(10000) | ||
375 | |||
376 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
377 | const uuid = resVideo.body.video.uuid | ||
378 | |||
379 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment') | ||
380 | const commentId = resComment.body.comment.id | ||
381 | |||
382 | await wait(500) | ||
383 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | ||
384 | }) | ||
385 | |||
386 | it('Should not send a new comment notification if the account is muted', async function () { | ||
387 | this.timeout(10000) | ||
388 | |||
389 | await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
390 | |||
391 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
392 | const uuid = resVideo.body.video.uuid | ||
393 | |||
394 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
395 | const commentId = resComment.body.comment.id | ||
396 | |||
397 | await wait(500) | ||
398 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence') | ||
399 | |||
400 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
401 | }) | ||
402 | |||
403 | it('Should send a new comment notification after a local comment on my video', async function () { | ||
404 | this.timeout(10000) | ||
405 | |||
406 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
407 | const uuid = resVideo.body.video.uuid | ||
408 | |||
409 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
410 | const commentId = resComment.body.comment.id | ||
411 | |||
412 | await wait(500) | ||
413 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | ||
414 | }) | ||
415 | |||
416 | it('Should send a new comment notification after a remote comment on my video', async function () { | ||
417 | this.timeout(10000) | ||
418 | |||
419 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
420 | const uuid = resVideo.body.video.uuid | ||
421 | |||
422 | await waitJobs(servers) | ||
423 | |||
424 | await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') | ||
425 | |||
426 | await waitJobs(servers) | ||
427 | |||
428 | const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
429 | expect(resComment.body.data).to.have.lengthOf(1) | ||
430 | const commentId = resComment.body.data[0].id | ||
431 | |||
432 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence') | ||
433 | }) | ||
434 | |||
435 | it('Should send a new comment notification after a local reply on my video', async function () { | ||
436 | this.timeout(10000) | ||
437 | |||
438 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
439 | const uuid = resVideo.body.video.uuid | ||
440 | |||
441 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment') | ||
442 | const threadId = resThread.body.comment.id | ||
443 | |||
444 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply') | ||
445 | const commentId = resComment.body.comment.id | ||
446 | |||
447 | await wait(500) | ||
448 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | ||
449 | }) | ||
450 | |||
451 | it('Should send a new comment notification after a remote reply on my video', async function () { | ||
452 | this.timeout(10000) | ||
453 | |||
454 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
455 | const uuid = resVideo.body.video.uuid | ||
456 | await waitJobs(servers) | ||
457 | |||
458 | { | ||
459 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment') | ||
460 | const threadId = resThread.body.comment.id | ||
461 | await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply') | ||
462 | } | ||
463 | |||
464 | await waitJobs(servers) | ||
465 | |||
466 | const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
467 | expect(resThread.body.data).to.have.lengthOf(1) | ||
468 | const threadId = resThread.body.data[0].id | ||
469 | |||
470 | const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId) | ||
471 | const tree = resComments.body as VideoCommentThreadTree | ||
472 | |||
473 | expect(tree.children).to.have.lengthOf(1) | ||
474 | const commentId = tree.children[0].comment.id | ||
475 | |||
476 | await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence') | ||
477 | }) | ||
478 | }) | ||
479 | |||
480 | describe('Mention notifications', function () { | ||
481 | let baseParams: CheckerBaseParams | ||
482 | |||
483 | before(async () => { | ||
484 | baseParams = { | ||
485 | server: servers[0], | ||
486 | emails, | ||
487 | socketNotifications: userNotifications, | ||
488 | token: userAccessToken | ||
489 | } | ||
490 | |||
491 | await updateMyUser({ | ||
492 | url: servers[0].url, | ||
493 | accessToken: servers[0].accessToken, | ||
494 | displayName: 'super root name' | ||
495 | }) | ||
496 | |||
497 | await updateMyUser({ | ||
498 | url: servers[1].url, | ||
499 | accessToken: servers[1].accessToken, | ||
500 | displayName: 'super root 2 name' | ||
501 | }) | ||
502 | }) | ||
503 | |||
504 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | ||
505 | this.timeout(10000) | ||
506 | |||
507 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' }) | ||
508 | const uuid = resVideo.body.video.uuid | ||
509 | |||
510 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
511 | const commentId = resComment.body.comment.id | ||
512 | |||
513 | await wait(500) | ||
514 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
515 | }) | ||
516 | |||
517 | it('Should not send a new mention comment notification if I mention myself', async function () { | ||
518 | this.timeout(10000) | ||
519 | |||
520 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
521 | const uuid = resVideo.body.video.uuid | ||
522 | |||
523 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello') | ||
524 | const commentId = resComment.body.comment.id | ||
525 | |||
526 | await wait(500) | ||
527 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
528 | }) | ||
529 | |||
530 | it('Should not send a new mention notification if the account is muted', async function () { | ||
531 | this.timeout(10000) | ||
532 | |||
533 | await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
534 | |||
535 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
536 | const uuid = resVideo.body.video.uuid | ||
537 | |||
538 | const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello') | ||
539 | const commentId = resComment.body.comment.id | ||
540 | |||
541 | await wait(500) | ||
542 | await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence') | ||
543 | |||
544 | await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root') | ||
545 | }) | ||
546 | |||
547 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | ||
548 | this.timeout(20000) | ||
549 | |||
550 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
551 | const uuid = resVideo.body.video.uuid | ||
552 | |||
553 | await waitJobs(servers) | ||
554 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello') | ||
555 | const threadId = resThread.body.comment.id | ||
556 | |||
557 | await waitJobs(servers) | ||
558 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence') | ||
559 | }) | ||
560 | |||
561 | it('Should send a new mention notification after local comments', async function () { | ||
562 | this.timeout(10000) | ||
563 | |||
564 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
565 | const uuid = resVideo.body.video.uuid | ||
566 | |||
567 | const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1') | ||
568 | const threadId = resThread.body.comment.id | ||
569 | |||
570 | await wait(500) | ||
571 | await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence') | ||
572 | |||
573 | const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1') | ||
574 | const commentId = resComment.body.comment.id | ||
575 | |||
576 | await wait(500) | ||
577 | await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence') | ||
578 | }) | ||
579 | |||
580 | it('Should send a new mention notification after remote comments', async function () { | ||
581 | this.timeout(20000) | ||
582 | |||
583 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' }) | ||
584 | const uuid = resVideo.body.video.uuid | ||
585 | |||
586 | await waitJobs(servers) | ||
587 | |||
588 | const text1 = `hello @user_1@localhost:${servers[0].port} 1` | ||
589 | const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1) | ||
590 | const server2ThreadId = resThread.body.comment.id | ||
591 | |||
592 | await waitJobs(servers) | ||
593 | |||
594 | const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5) | ||
595 | expect(resThread2.body.data).to.have.lengthOf(1) | ||
596 | const server1ThreadId = resThread2.body.data[0].id | ||
597 | await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence') | ||
598 | |||
599 | const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}` | ||
600 | await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2) | ||
601 | |||
602 | await waitJobs(servers) | ||
603 | |||
604 | const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId) | ||
605 | const tree = resComments.body as VideoCommentThreadTree | ||
606 | |||
607 | expect(tree.children).to.have.lengthOf(1) | ||
608 | const commentId = tree.children[0].comment.id | ||
609 | |||
610 | await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence') | ||
611 | }) | ||
612 | }) | ||
613 | |||
614 | describe('Video abuse for moderators notification', function () { | ||
615 | let baseParams: CheckerBaseParams | ||
616 | |||
617 | before(() => { | ||
618 | baseParams = { | ||
619 | server: servers[0], | ||
620 | emails, | ||
621 | socketNotifications: adminNotifications, | ||
622 | token: servers[0].accessToken | ||
623 | } | ||
624 | }) | ||
625 | |||
626 | it('Should send a notification to moderators on local video abuse', async function () { | ||
627 | this.timeout(10000) | ||
628 | |||
629 | const name = 'video for abuse ' + uuidv4() | ||
630 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
631 | const uuid = resVideo.body.video.uuid | ||
632 | |||
633 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, uuid, 'super reason') | ||
634 | |||
635 | await waitJobs(servers) | ||
636 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | ||
637 | }) | ||
638 | |||
639 | it('Should send a notification to moderators on remote video abuse', async function () { | ||
640 | this.timeout(10000) | ||
641 | |||
642 | const name = 'video for abuse ' + uuidv4() | ||
643 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
644 | const uuid = resVideo.body.video.uuid | ||
645 | |||
646 | await waitJobs(servers) | ||
647 | |||
648 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, uuid, 'super reason') | ||
649 | |||
650 | await waitJobs(servers) | ||
651 | await checkNewVideoAbuseForModerators(baseParams, uuid, name, 'presence') | ||
652 | }) | ||
653 | }) | ||
654 | |||
655 | describe('Video blacklist on my video', function () { | ||
656 | let baseParams: CheckerBaseParams | ||
657 | |||
658 | before(() => { | ||
659 | baseParams = { | ||
660 | server: servers[0], | ||
661 | emails, | ||
662 | socketNotifications: userNotifications, | ||
663 | token: userAccessToken | ||
664 | } | ||
665 | }) | ||
666 | |||
667 | it('Should send a notification to video owner on blacklist', async function () { | ||
668 | this.timeout(10000) | ||
669 | |||
670 | const name = 'video for abuse ' + uuidv4() | ||
671 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
672 | const uuid = resVideo.body.video.uuid | ||
673 | |||
674 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
675 | |||
676 | await waitJobs(servers) | ||
677 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') | ||
678 | }) | ||
679 | |||
680 | it('Should send a notification to video owner on unblacklist', async function () { | ||
681 | this.timeout(10000) | ||
682 | |||
683 | const name = 'video for abuse ' + uuidv4() | ||
684 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) | ||
685 | const uuid = resVideo.body.video.uuid | ||
686 | |||
687 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
688 | |||
689 | await waitJobs(servers) | ||
690 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
691 | await waitJobs(servers) | ||
692 | |||
693 | await wait(500) | ||
694 | await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'unblacklist') | ||
695 | }) | ||
696 | }) | ||
697 | |||
698 | describe('My video is published', function () { | 227 | describe('My video is published', function () { |
699 | let baseParams: CheckerBaseParams | 228 | let baseParams: CheckerBaseParams |
700 | 229 | ||
@@ -710,7 +239,7 @@ describe('Test users notifications', function () { | |||
710 | it('Should not send a notification if transcoding is not enabled', async function () { | 239 | it('Should not send a notification if transcoding is not enabled', async function () { |
711 | this.timeout(10000) | 240 | this.timeout(10000) |
712 | 241 | ||
713 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | 242 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 1) |
714 | await waitJobs(servers) | 243 | await waitJobs(servers) |
715 | 244 | ||
716 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | 245 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') |
@@ -719,7 +248,7 @@ describe('Test users notifications', function () { | |||
719 | it('Should not send a notification if the wait transcoding is false', async function () { | 248 | it('Should not send a notification if the wait transcoding is false', async function () { |
720 | this.timeout(50000) | 249 | this.timeout(50000) |
721 | 250 | ||
722 | await uploadVideoByRemoteAccount(servers, { waitTranscoding: false }) | 251 | await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: false }) |
723 | await waitJobs(servers) | 252 | await waitJobs(servers) |
724 | 253 | ||
725 | const notification = await getLastNotification(servers[0].url, userAccessToken) | 254 | const notification = await getLastNotification(servers[0].url, userAccessToken) |
@@ -731,7 +260,7 @@ describe('Test users notifications', function () { | |||
731 | it('Should send a notification even if the video is not transcoded in other resolutions', async function () { | 260 | it('Should send a notification even if the video is not transcoded in other resolutions', async function () { |
732 | this.timeout(50000) | 261 | this.timeout(50000) |
733 | 262 | ||
734 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) | 263 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true, fixture: 'video_short_240p.mp4' }) |
735 | await waitJobs(servers) | 264 | await waitJobs(servers) |
736 | 265 | ||
737 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 266 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') |
@@ -740,7 +269,7 @@ describe('Test users notifications', function () { | |||
740 | it('Should send a notification with a transcoded video', async function () { | 269 | it('Should send a notification with a transcoded video', async function () { |
741 | this.timeout(50000) | 270 | this.timeout(50000) |
742 | 271 | ||
743 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, { waitTranscoding: true }) | 272 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, { waitTranscoding: true }) |
744 | await waitJobs(servers) | 273 | await waitJobs(servers) |
745 | 274 | ||
746 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 275 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') |
@@ -778,14 +307,14 @@ describe('Test users notifications', function () { | |||
778 | privacy: VideoPrivacy.PUBLIC | 307 | privacy: VideoPrivacy.PUBLIC |
779 | } | 308 | } |
780 | } | 309 | } |
781 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | 310 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
782 | 311 | ||
783 | await wait(6000) | 312 | await wait(6000) |
784 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') | 313 | await checkVideoIsPublished(baseParams, name, uuid, 'presence') |
785 | }) | 314 | }) |
786 | 315 | ||
787 | it('Should not send a notification before the video is published', async function () { | 316 | it('Should not send a notification before the video is published', async function () { |
788 | this.timeout(20000) | 317 | this.timeout(40000) |
789 | 318 | ||
790 | const updateAt = new Date(new Date().getTime() + 1000000) | 319 | const updateAt = new Date(new Date().getTime() + 1000000) |
791 | 320 | ||
@@ -796,7 +325,7 @@ describe('Test users notifications', function () { | |||
796 | privacy: VideoPrivacy.PUBLIC | 325 | privacy: VideoPrivacy.PUBLIC |
797 | } | 326 | } |
798 | } | 327 | } |
799 | const { name, uuid } = await uploadVideoByRemoteAccount(servers, data) | 328 | const { name, uuid } = await uploadRandomVideoOnServers(servers, 2, data) |
800 | 329 | ||
801 | await wait(6000) | 330 | await wait(6000) |
802 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') | 331 | await checkVideoIsPublished(baseParams, name, uuid, 'absence') |
@@ -852,122 +381,6 @@ describe('Test users notifications', function () { | |||
852 | }) | 381 | }) |
853 | }) | 382 | }) |
854 | 383 | ||
855 | describe('New registration', function () { | ||
856 | let baseParams: CheckerBaseParams | ||
857 | |||
858 | before(() => { | ||
859 | baseParams = { | ||
860 | server: servers[0], | ||
861 | emails, | ||
862 | socketNotifications: adminNotifications, | ||
863 | token: servers[0].accessToken | ||
864 | } | ||
865 | }) | ||
866 | |||
867 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | ||
868 | this.timeout(10000) | ||
869 | |||
870 | await registerUser(servers[0].url, 'user_45', 'password') | ||
871 | |||
872 | await waitJobs(servers) | ||
873 | |||
874 | await checkUserRegistered(baseParams, 'user_45', 'presence') | ||
875 | |||
876 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
877 | await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') | ||
878 | }) | ||
879 | }) | ||
880 | |||
881 | describe('New instance follows', function () { | ||
882 | const instanceIndexServer = new MockInstancesIndex() | ||
883 | const config = { | ||
884 | followings: { | ||
885 | instance: { | ||
886 | autoFollowIndex: { | ||
887 | indexUrl: 'http://localhost:42101/api/v1/instances/hosts', | ||
888 | enabled: true | ||
889 | } | ||
890 | } | ||
891 | } | ||
892 | } | ||
893 | let baseParams: CheckerBaseParams | ||
894 | |||
895 | before(async () => { | ||
896 | baseParams = { | ||
897 | server: servers[0], | ||
898 | emails, | ||
899 | socketNotifications: adminNotifications, | ||
900 | token: servers[0].accessToken | ||
901 | } | ||
902 | |||
903 | await instanceIndexServer.initialize() | ||
904 | instanceIndexServer.addInstance(servers[1].host) | ||
905 | }) | ||
906 | |||
907 | it('Should send a notification only to admin when there is a new instance follower', async function () { | ||
908 | this.timeout(20000) | ||
909 | |||
910 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
911 | |||
912 | await waitJobs(servers) | ||
913 | |||
914 | await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') | ||
915 | |||
916 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
917 | await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') | ||
918 | }) | ||
919 | |||
920 | it('Should send a notification on auto follow back', async function () { | ||
921 | this.timeout(40000) | ||
922 | |||
923 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
924 | await waitJobs(servers) | ||
925 | |||
926 | const config = { | ||
927 | followings: { | ||
928 | instance: { | ||
929 | autoFollowBack: { enabled: true } | ||
930 | } | ||
931 | } | ||
932 | } | ||
933 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
934 | |||
935 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) | ||
936 | |||
937 | await waitJobs(servers) | ||
938 | |||
939 | const followerHost = servers[0].host | ||
940 | const followingHost = servers[2].host | ||
941 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
942 | |||
943 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | ||
944 | await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') | ||
945 | |||
946 | config.followings.instance.autoFollowBack.enabled = false | ||
947 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
948 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | ||
949 | await unfollow(servers[2].url, servers[2].accessToken, servers[0]) | ||
950 | }) | ||
951 | |||
952 | it('Should send a notification on auto instances index follow', async function () { | ||
953 | this.timeout(30000) | ||
954 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
955 | |||
956 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
957 | |||
958 | await wait(5000) | ||
959 | await waitJobs(servers) | ||
960 | |||
961 | const followerHost = servers[0].host | ||
962 | const followingHost = servers[1].host | ||
963 | await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') | ||
964 | |||
965 | config.followings.instance.autoFollowIndex.enabled = false | ||
966 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
967 | await unfollow(servers[0].url, servers[0].accessToken, servers[1]) | ||
968 | }) | ||
969 | }) | ||
970 | |||
971 | describe('New actor follow', function () { | 384 | describe('New actor follow', function () { |
972 | let baseParams: CheckerBaseParams | 385 | let baseParams: CheckerBaseParams |
973 | const myChannelName = 'super channel name' | 386 | const myChannelName = 'super channel name' |
@@ -1046,332 +459,6 @@ describe('Test users notifications', function () { | |||
1046 | // }) | 459 | // }) |
1047 | }) | 460 | }) |
1048 | 461 | ||
1049 | describe('Video-related notifications when video auto-blacklist is enabled', function () { | ||
1050 | let userBaseParams: CheckerBaseParams | ||
1051 | let adminBaseParamsServer1: CheckerBaseParams | ||
1052 | let adminBaseParamsServer2: CheckerBaseParams | ||
1053 | let videoUUID: string | ||
1054 | let videoName: string | ||
1055 | let currentCustomConfig: CustomConfig | ||
1056 | |||
1057 | before(async () => { | ||
1058 | |||
1059 | adminBaseParamsServer1 = { | ||
1060 | server: servers[0], | ||
1061 | emails, | ||
1062 | socketNotifications: adminNotifications, | ||
1063 | token: servers[0].accessToken | ||
1064 | } | ||
1065 | |||
1066 | adminBaseParamsServer2 = { | ||
1067 | server: servers[1], | ||
1068 | emails, | ||
1069 | socketNotifications: adminNotificationsServer2, | ||
1070 | token: servers[1].accessToken | ||
1071 | } | ||
1072 | |||
1073 | userBaseParams = { | ||
1074 | server: servers[0], | ||
1075 | emails, | ||
1076 | socketNotifications: userNotifications, | ||
1077 | token: userAccessToken | ||
1078 | } | ||
1079 | |||
1080 | const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) | ||
1081 | currentCustomConfig = resCustomConfig.body | ||
1082 | const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { | ||
1083 | autoBlacklist: { | ||
1084 | videos: { | ||
1085 | ofUsers: { | ||
1086 | enabled: true | ||
1087 | } | ||
1088 | } | ||
1089 | } | ||
1090 | }) | ||
1091 | // enable transcoding otherwise own publish notification after transcoding not expected | ||
1092 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | ||
1093 | await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) | ||
1094 | |||
1095 | await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
1096 | await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
1097 | |||
1098 | }) | ||
1099 | |||
1100 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | ||
1101 | this.timeout(20000) | ||
1102 | |||
1103 | videoName = 'video with auto-blacklist ' + uuidv4() | ||
1104 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) | ||
1105 | videoUUID = resVideo.body.video.uuid | ||
1106 | |||
1107 | await waitJobs(servers) | ||
1108 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | ||
1109 | }) | ||
1110 | |||
1111 | it('Should not send video publish notification if auto-blacklisted', async function () { | ||
1112 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | ||
1113 | }) | ||
1114 | |||
1115 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | ||
1116 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | ||
1117 | }) | ||
1118 | |||
1119 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | ||
1120 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | ||
1121 | }) | ||
1122 | |||
1123 | it('Should send video published and unblacklist after video unblacklisted', async function () { | ||
1124 | this.timeout(20000) | ||
1125 | |||
1126 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) | ||
1127 | |||
1128 | await waitJobs(servers) | ||
1129 | |||
1130 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | ||
1131 | // One notification might be better anyways | ||
1132 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | ||
1133 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | ||
1134 | }) | ||
1135 | |||
1136 | it('Should send a local user subscription notification after removed from blacklist', async function () { | ||
1137 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | ||
1138 | }) | ||
1139 | |||
1140 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | ||
1141 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | ||
1142 | }) | ||
1143 | |||
1144 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | ||
1145 | this.timeout(20000) | ||
1146 | |||
1147 | const updateAt = new Date(new Date().getTime() + 1000000) | ||
1148 | |||
1149 | const name = 'video with auto-blacklist and future schedule ' + uuidv4() | ||
1150 | |||
1151 | const data = { | ||
1152 | name, | ||
1153 | privacy: VideoPrivacy.PRIVATE, | ||
1154 | scheduleUpdate: { | ||
1155 | updateAt: updateAt.toISOString(), | ||
1156 | privacy: VideoPrivacy.PUBLIC | ||
1157 | } | ||
1158 | } | ||
1159 | |||
1160 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | ||
1161 | const uuid = resVideo.body.video.uuid | ||
1162 | |||
1163 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) | ||
1164 | |||
1165 | await waitJobs(servers) | ||
1166 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | ||
1167 | |||
1168 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | ||
1169 | // One notification might be better anyways | ||
1170 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | ||
1171 | |||
1172 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | ||
1173 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | ||
1174 | }) | ||
1175 | |||
1176 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | ||
1177 | this.timeout(20000) | ||
1178 | |||
1179 | // In 2 seconds | ||
1180 | const updateAt = new Date(new Date().getTime() + 2000) | ||
1181 | |||
1182 | const name = 'video with schedule done and still auto-blacklisted ' + uuidv4() | ||
1183 | |||
1184 | const data = { | ||
1185 | name, | ||
1186 | privacy: VideoPrivacy.PRIVATE, | ||
1187 | scheduleUpdate: { | ||
1188 | updateAt: updateAt.toISOString(), | ||
1189 | privacy: VideoPrivacy.PUBLIC | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | ||
1194 | const uuid = resVideo.body.video.uuid | ||
1195 | |||
1196 | await wait(6000) | ||
1197 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | ||
1198 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | ||
1199 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | ||
1200 | }) | ||
1201 | |||
1202 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | ||
1203 | this.timeout(20000) | ||
1204 | |||
1205 | const name = 'video without auto-blacklist ' + uuidv4() | ||
1206 | |||
1207 | // admin with blacklist right will not be auto-blacklisted | ||
1208 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | ||
1209 | const uuid = resVideo.body.video.uuid | ||
1210 | |||
1211 | await waitJobs(servers) | ||
1212 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | ||
1213 | }) | ||
1214 | |||
1215 | after(async () => { | ||
1216 | await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) | ||
1217 | |||
1218 | await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
1219 | await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) | ||
1220 | }) | ||
1221 | }) | ||
1222 | |||
1223 | describe('Mark as read', function () { | ||
1224 | it('Should mark as read some notifications', async function () { | ||
1225 | const res = await getUserNotifications(servers[0].url, userAccessToken, 2, 3) | ||
1226 | const ids = res.body.data.map(n => n.id) | ||
1227 | |||
1228 | await markAsReadNotifications(servers[0].url, userAccessToken, ids) | ||
1229 | }) | ||
1230 | |||
1231 | it('Should have the notifications marked as read', async function () { | ||
1232 | const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10) | ||
1233 | |||
1234 | const notifications = res.body.data as UserNotification[] | ||
1235 | expect(notifications[0].read).to.be.false | ||
1236 | expect(notifications[1].read).to.be.false | ||
1237 | expect(notifications[2].read).to.be.true | ||
1238 | expect(notifications[3].read).to.be.true | ||
1239 | expect(notifications[4].read).to.be.true | ||
1240 | expect(notifications[5].read).to.be.false | ||
1241 | }) | ||
1242 | |||
1243 | it('Should only list read notifications', async function () { | ||
1244 | const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, false) | ||
1245 | |||
1246 | const notifications = res.body.data as UserNotification[] | ||
1247 | for (const notification of notifications) { | ||
1248 | expect(notification.read).to.be.true | ||
1249 | } | ||
1250 | }) | ||
1251 | |||
1252 | it('Should only list unread notifications', async function () { | ||
1253 | const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, true) | ||
1254 | |||
1255 | const notifications = res.body.data as UserNotification[] | ||
1256 | for (const notification of notifications) { | ||
1257 | expect(notification.read).to.be.false | ||
1258 | } | ||
1259 | }) | ||
1260 | |||
1261 | it('Should mark as read all notifications', async function () { | ||
1262 | await markAsReadAllNotifications(servers[0].url, userAccessToken) | ||
1263 | |||
1264 | const res = await getUserNotifications(servers[0].url, userAccessToken, 0, 10, true) | ||
1265 | |||
1266 | expect(res.body.total).to.equal(0) | ||
1267 | expect(res.body.data).to.have.lengthOf(0) | ||
1268 | }) | ||
1269 | }) | ||
1270 | |||
1271 | describe('Notification settings', function () { | ||
1272 | let baseParams: CheckerBaseParams | ||
1273 | |||
1274 | before(() => { | ||
1275 | baseParams = { | ||
1276 | server: servers[0], | ||
1277 | emails, | ||
1278 | socketNotifications: userNotifications, | ||
1279 | token: userAccessToken | ||
1280 | } | ||
1281 | }) | ||
1282 | |||
1283 | it('Should not have notifications', async function () { | ||
1284 | this.timeout(20000) | ||
1285 | |||
1286 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | ||
1287 | newVideoFromSubscription: UserNotificationSettingValue.NONE | ||
1288 | })) | ||
1289 | |||
1290 | { | ||
1291 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | ||
1292 | const info = res.body as User | ||
1293 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) | ||
1294 | } | ||
1295 | |||
1296 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | ||
1297 | |||
1298 | const check = { web: true, mail: true } | ||
1299 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
1300 | }) | ||
1301 | |||
1302 | it('Should only have web notifications', async function () { | ||
1303 | this.timeout(20000) | ||
1304 | |||
1305 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | ||
1306 | newVideoFromSubscription: UserNotificationSettingValue.WEB | ||
1307 | })) | ||
1308 | |||
1309 | { | ||
1310 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | ||
1311 | const info = res.body as User | ||
1312 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) | ||
1313 | } | ||
1314 | |||
1315 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | ||
1316 | |||
1317 | { | ||
1318 | const check = { mail: true, web: false } | ||
1319 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
1320 | } | ||
1321 | |||
1322 | { | ||
1323 | const check = { mail: false, web: true } | ||
1324 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | ||
1325 | } | ||
1326 | }) | ||
1327 | |||
1328 | it('Should only have mail notifications', async function () { | ||
1329 | this.timeout(20000) | ||
1330 | |||
1331 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | ||
1332 | newVideoFromSubscription: UserNotificationSettingValue.EMAIL | ||
1333 | })) | ||
1334 | |||
1335 | { | ||
1336 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | ||
1337 | const info = res.body as User | ||
1338 | expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) | ||
1339 | } | ||
1340 | |||
1341 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | ||
1342 | |||
1343 | { | ||
1344 | const check = { mail: false, web: true } | ||
1345 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'absence') | ||
1346 | } | ||
1347 | |||
1348 | { | ||
1349 | const check = { mail: true, web: false } | ||
1350 | await checkNewVideoFromSubscription(immutableAssign(baseParams, { check }), name, uuid, 'presence') | ||
1351 | } | ||
1352 | }) | ||
1353 | |||
1354 | it('Should have email and web notifications', async function () { | ||
1355 | this.timeout(20000) | ||
1356 | |||
1357 | await updateMyNotificationSettings(servers[0].url, userAccessToken, immutableAssign(allNotificationSettings, { | ||
1358 | newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
1359 | })) | ||
1360 | |||
1361 | { | ||
1362 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | ||
1363 | const info = res.body as User | ||
1364 | expect(info.notificationSettings.newVideoFromSubscription).to.equal( | ||
1365 | UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | ||
1366 | ) | ||
1367 | } | ||
1368 | |||
1369 | const { name, uuid } = await uploadVideoByLocalAccount(servers) | ||
1370 | |||
1371 | await checkNewVideoFromSubscription(baseParams, name, uuid, 'presence') | ||
1372 | }) | ||
1373 | }) | ||
1374 | |||
1375 | after(async function () { | 462 | after(async function () { |
1376 | MockSmtpServer.Instance.kill() | 463 | MockSmtpServer.Instance.kill() |
1377 | 464 | ||
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index e7d9238dd..3493a723d 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { User, Video, VideoChannel, ViewsPerDate, VideoDetails } from '../../../../shared/index' | 4 | import * as chai from 'chai' |
6 | import { | 5 | import { |
7 | cleanupTests, | 6 | cleanupTests, |
8 | createUser, | 7 | createUser, |
@@ -30,6 +29,7 @@ import { | |||
30 | viewVideo | 29 | viewVideo |
31 | } from '../../../../shared/extra-utils/index' | 30 | } from '../../../../shared/extra-utils/index' |
32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 31 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
32 | import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' | ||
33 | 33 | ||
34 | const expect = chai.expect | 34 | const expect = chai.expect |
35 | 35 | ||