diff options
Diffstat (limited to 'server/tests/api/notifications')
-rw-r--r-- | server/tests/api/notifications/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 55 | ||||
-rw-r--r-- | server/tests/api/notifications/registrations-notifications.ts | 88 |
3 files changed, 107 insertions, 37 deletions
diff --git a/server/tests/api/notifications/index.ts b/server/tests/api/notifications/index.ts index 8caa30a3d..c0216b74f 100644 --- a/server/tests/api/notifications/index.ts +++ b/server/tests/api/notifications/index.ts | |||
@@ -2,4 +2,5 @@ import './admin-notifications' | |||
2 | import './comments-notifications' | 2 | import './comments-notifications' |
3 | import './moderation-notifications' | 3 | import './moderation-notifications' |
4 | import './notifications-api' | 4 | import './notifications-api' |
5 | import './registrations-notifications' | ||
5 | import './user-notifications' | 6 | import './user-notifications' |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index b127a7a31..bb11a08aa 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -11,7 +11,6 @@ import { | |||
11 | checkNewInstanceFollower, | 11 | checkNewInstanceFollower, |
12 | checkNewVideoAbuseForModerators, | 12 | checkNewVideoAbuseForModerators, |
13 | checkNewVideoFromSubscription, | 13 | checkNewVideoFromSubscription, |
14 | checkUserRegistered, | ||
15 | checkVideoAutoBlacklistForModerators, | 14 | checkVideoAutoBlacklistForModerators, |
16 | checkVideoIsPublished, | 15 | checkVideoIsPublished, |
17 | MockInstancesIndex, | 16 | MockInstancesIndex, |
@@ -34,7 +33,7 @@ describe('Test moderation notifications', function () { | |||
34 | let emails: object[] = [] | 33 | let emails: object[] = [] |
35 | 34 | ||
36 | before(async function () { | 35 | before(async function () { |
37 | this.timeout(120000) | 36 | this.timeout(50000) |
38 | 37 | ||
39 | const res = await prepareNotificationsTest(3) | 38 | const res = await prepareNotificationsTest(3) |
40 | emails = res.emails | 39 | emails = res.emails |
@@ -60,7 +59,7 @@ describe('Test moderation notifications', function () { | |||
60 | }) | 59 | }) |
61 | 60 | ||
62 | it('Should not send a notification to moderators on local abuse reported by an admin', async function () { | 61 | it('Should not send a notification to moderators on local abuse reported by an admin', async function () { |
63 | this.timeout(20000) | 62 | this.timeout(50000) |
64 | 63 | ||
65 | const name = 'video for abuse ' + buildUUID() | 64 | const name = 'video for abuse ' + buildUUID() |
66 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | 65 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
@@ -72,7 +71,7 @@ describe('Test moderation notifications', function () { | |||
72 | }) | 71 | }) |
73 | 72 | ||
74 | it('Should send a notification to moderators on local video abuse', async function () { | 73 | it('Should send a notification to moderators on local video abuse', async function () { |
75 | this.timeout(20000) | 74 | this.timeout(50000) |
76 | 75 | ||
77 | const name = 'video for abuse ' + buildUUID() | 76 | const name = 'video for abuse ' + buildUUID() |
78 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | 77 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
@@ -84,7 +83,7 @@ describe('Test moderation notifications', function () { | |||
84 | }) | 83 | }) |
85 | 84 | ||
86 | it('Should send a notification to moderators on remote video abuse', async function () { | 85 | it('Should send a notification to moderators on remote video abuse', async function () { |
87 | this.timeout(20000) | 86 | this.timeout(50000) |
88 | 87 | ||
89 | const name = 'video for abuse ' + buildUUID() | 88 | const name = 'video for abuse ' + buildUUID() |
90 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | 89 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
@@ -99,7 +98,7 @@ describe('Test moderation notifications', function () { | |||
99 | }) | 98 | }) |
100 | 99 | ||
101 | it('Should send a notification to moderators on local comment abuse', async function () { | 100 | it('Should send a notification to moderators on local comment abuse', async function () { |
102 | this.timeout(20000) | 101 | this.timeout(50000) |
103 | 102 | ||
104 | const name = 'video for abuse ' + buildUUID() | 103 | const name = 'video for abuse ' + buildUUID() |
105 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | 104 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
@@ -118,7 +117,7 @@ describe('Test moderation notifications', function () { | |||
118 | }) | 117 | }) |
119 | 118 | ||
120 | it('Should send a notification to moderators on remote comment abuse', async function () { | 119 | it('Should send a notification to moderators on remote comment abuse', async function () { |
121 | this.timeout(20000) | 120 | this.timeout(50000) |
122 | 121 | ||
123 | const name = 'video for abuse ' + buildUUID() | 122 | const name = 'video for abuse ' + buildUUID() |
124 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | 123 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
@@ -140,7 +139,7 @@ describe('Test moderation notifications', function () { | |||
140 | }) | 139 | }) |
141 | 140 | ||
142 | it('Should send a notification to moderators on local account abuse', async function () { | 141 | it('Should send a notification to moderators on local account abuse', async function () { |
143 | this.timeout(20000) | 142 | this.timeout(50000) |
144 | 143 | ||
145 | const username = 'user' + new Date().getTime() | 144 | const username = 'user' + new Date().getTime() |
146 | const { account } = await servers[0].users.create({ username, password: 'donald' }) | 145 | const { account } = await servers[0].users.create({ username, password: 'donald' }) |
@@ -153,7 +152,7 @@ describe('Test moderation notifications', function () { | |||
153 | }) | 152 | }) |
154 | 153 | ||
155 | it('Should send a notification to moderators on remote account abuse', async function () { | 154 | it('Should send a notification to moderators on remote account abuse', async function () { |
156 | this.timeout(20000) | 155 | this.timeout(50000) |
157 | 156 | ||
158 | const username = 'user' + new Date().getTime() | 157 | const username = 'user' + new Date().getTime() |
159 | const tmpToken = await servers[0].users.generateUserAndToken(username) | 158 | const tmpToken = await servers[0].users.generateUserAndToken(username) |
@@ -327,32 +326,6 @@ describe('Test moderation notifications', function () { | |||
327 | }) | 326 | }) |
328 | }) | 327 | }) |
329 | 328 | ||
330 | describe('New registration', function () { | ||
331 | let baseParams: CheckerBaseParams | ||
332 | |||
333 | before(() => { | ||
334 | baseParams = { | ||
335 | server: servers[0], | ||
336 | emails, | ||
337 | socketNotifications: adminNotifications, | ||
338 | token: servers[0].accessToken | ||
339 | } | ||
340 | }) | ||
341 | |||
342 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | ||
343 | this.timeout(10000) | ||
344 | |||
345 | await servers[0].users.register({ username: 'user_45' }) | ||
346 | |||
347 | await waitJobs(servers) | ||
348 | |||
349 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) | ||
350 | |||
351 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } | ||
352 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) | ||
353 | }) | ||
354 | }) | ||
355 | |||
356 | describe('New instance follows', function () { | 329 | describe('New instance follows', function () { |
357 | const instanceIndexServer = new MockInstancesIndex() | 330 | const instanceIndexServer = new MockInstancesIndex() |
358 | let config: any | 331 | let config: any |
@@ -512,10 +485,14 @@ describe('Test moderation notifications', function () { | |||
512 | }) | 485 | }) |
513 | 486 | ||
514 | it('Should not send video publish notification if auto-blacklisted', async function () { | 487 | it('Should not send video publish notification if auto-blacklisted', async function () { |
488 | this.timeout(120000) | ||
489 | |||
515 | await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) | 490 | await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' }) |
516 | }) | 491 | }) |
517 | 492 | ||
518 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | 493 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { |
494 | this.timeout(120000) | ||
495 | |||
519 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) | 496 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' }) |
520 | }) | 497 | }) |
521 | 498 | ||
@@ -524,7 +501,7 @@ describe('Test moderation notifications', function () { | |||
524 | }) | 501 | }) |
525 | 502 | ||
526 | it('Should send video published and unblacklist after video unblacklisted', async function () { | 503 | it('Should send video published and unblacklist after video unblacklisted', async function () { |
527 | this.timeout(40000) | 504 | this.timeout(120000) |
528 | 505 | ||
529 | await servers[0].blacklist.remove({ videoId: uuid }) | 506 | await servers[0].blacklist.remove({ videoId: uuid }) |
530 | 507 | ||
@@ -537,10 +514,14 @@ describe('Test moderation notifications', function () { | |||
537 | }) | 514 | }) |
538 | 515 | ||
539 | it('Should send a local user subscription notification after removed from blacklist', async function () { | 516 | it('Should send a local user subscription notification after removed from blacklist', async function () { |
517 | this.timeout(120000) | ||
518 | |||
540 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) | 519 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' }) |
541 | }) | 520 | }) |
542 | 521 | ||
543 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | 522 | it('Should send a remote user subscription notification after removed from blacklist', async function () { |
523 | this.timeout(120000) | ||
524 | |||
544 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) | 525 | await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' }) |
545 | }) | 526 | }) |
546 | 527 | ||
@@ -576,7 +557,7 @@ describe('Test moderation notifications', function () { | |||
576 | }) | 557 | }) |
577 | 558 | ||
578 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | 559 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { |
579 | this.timeout(40000) | 560 | this.timeout(120000) |
580 | 561 | ||
581 | // In 2 seconds | 562 | // In 2 seconds |
582 | const updateAt = new Date(new Date().getTime() + 2000) | 563 | const updateAt = new Date(new Date().getTime() + 2000) |
diff --git a/server/tests/api/notifications/registrations-notifications.ts b/server/tests/api/notifications/registrations-notifications.ts new file mode 100644 index 000000000..b5a7c2bb5 --- /dev/null +++ b/server/tests/api/notifications/registrations-notifications.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { | ||
4 | CheckerBaseParams, | ||
5 | checkRegistrationRequest, | ||
6 | checkUserRegistered, | ||
7 | MockSmtpServer, | ||
8 | prepareNotificationsTest | ||
9 | } from '@server/tests/shared' | ||
10 | import { UserNotification } from '@shared/models' | ||
11 | import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' | ||
12 | |||
13 | describe('Test registrations notifications', function () { | ||
14 | let server: PeerTubeServer | ||
15 | let userToken1: string | ||
16 | |||
17 | let userNotifications: UserNotification[] = [] | ||
18 | let adminNotifications: UserNotification[] = [] | ||
19 | let emails: object[] = [] | ||
20 | |||
21 | let baseParams: CheckerBaseParams | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(50000) | ||
25 | |||
26 | const res = await prepareNotificationsTest(1) | ||
27 | |||
28 | server = res.servers[0] | ||
29 | emails = res.emails | ||
30 | userToken1 = res.userAccessToken | ||
31 | adminNotifications = res.adminNotifications | ||
32 | userNotifications = res.userNotifications | ||
33 | |||
34 | baseParams = { | ||
35 | server, | ||
36 | emails, | ||
37 | socketNotifications: adminNotifications, | ||
38 | token: server.accessToken | ||
39 | } | ||
40 | }) | ||
41 | |||
42 | describe('New direct registration for moderators', function () { | ||
43 | |||
44 | before(async function () { | ||
45 | await server.config.enableSignup(false) | ||
46 | }) | ||
47 | |||
48 | it('Should send a notification only to moderators when a user registers on the instance', async function () { | ||
49 | this.timeout(50000) | ||
50 | |||
51 | await server.registrations.register({ username: 'user_10' }) | ||
52 | |||
53 | await waitJobs([ server ]) | ||
54 | |||
55 | await checkUserRegistered({ ...baseParams, username: 'user_10', checkType: 'presence' }) | ||
56 | |||
57 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } | ||
58 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_10', checkType: 'absence' }) | ||
59 | }) | ||
60 | }) | ||
61 | |||
62 | describe('New registration request for moderators', function () { | ||
63 | |||
64 | before(async function () { | ||
65 | await server.config.enableSignup(true) | ||
66 | }) | ||
67 | |||
68 | it('Should send a notification on new registration request', async function () { | ||
69 | this.timeout(50000) | ||
70 | |||
71 | const registrationReason = 'my reason' | ||
72 | await server.registrations.requestRegistration({ username: 'user_11', registrationReason }) | ||
73 | |||
74 | await waitJobs([ server ]) | ||
75 | |||
76 | await checkRegistrationRequest({ ...baseParams, username: 'user_11', registrationReason, checkType: 'presence' }) | ||
77 | |||
78 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } | ||
79 | await checkRegistrationRequest({ ...baseParams, ...userOverride, username: 'user_11', registrationReason, checkType: 'absence' }) | ||
80 | }) | ||
81 | }) | ||
82 | |||
83 | after(async function () { | ||
84 | MockSmtpServer.Instance.kill() | ||
85 | |||
86 | await cleanupTests([ server ]) | ||
87 | }) | ||
88 | }) | ||