aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/tests/src/api/notifications/registrations-notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/api/notifications/registrations-notifications.ts')
-rw-r--r--packages/tests/src/api/notifications/registrations-notifications.ts83
1 files changed, 83 insertions, 0 deletions
diff --git a/packages/tests/src/api/notifications/registrations-notifications.ts b/packages/tests/src/api/notifications/registrations-notifications.ts
new file mode 100644
index 000000000..1f166cb36
--- /dev/null
+++ b/packages/tests/src/api/notifications/registrations-notifications.ts
@@ -0,0 +1,83 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { UserNotification } from '@peertube/peertube-models'
4import { cleanupTests, PeerTubeServer, waitJobs } from '@peertube/peertube-server-commands'
5import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js'
6import { CheckerBaseParams, prepareNotificationsTest, checkUserRegistered, checkRegistrationRequest } from '@tests/shared/notifications.js'
7
8describe('Test registrations notifications', function () {
9 let server: PeerTubeServer
10 let userToken1: string
11
12 let userNotifications: UserNotification[] = []
13 let adminNotifications: UserNotification[] = []
14 let emails: object[] = []
15
16 let baseParams: CheckerBaseParams
17
18 before(async function () {
19 this.timeout(120000)
20
21 const res = await prepareNotificationsTest(1)
22
23 server = res.servers[0]
24 emails = res.emails
25 userToken1 = res.userAccessToken
26 adminNotifications = res.adminNotifications
27 userNotifications = res.userNotifications
28
29 baseParams = {
30 server,
31 emails,
32 socketNotifications: adminNotifications,
33 token: server.accessToken
34 }
35 })
36
37 describe('New direct registration for moderators', function () {
38
39 before(async function () {
40 await server.config.enableSignup(false)
41 })
42
43 it('Should send a notification only to moderators when a user registers on the instance', async function () {
44 this.timeout(50000)
45
46 await server.registrations.register({ username: 'user_10' })
47
48 await waitJobs([ server ])
49
50 await checkUserRegistered({ ...baseParams, username: 'user_10', checkType: 'presence' })
51
52 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
53 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_10', checkType: 'absence' })
54 })
55 })
56
57 describe('New registration request for moderators', function () {
58
59 before(async function () {
60 await server.config.enableSignup(true)
61 })
62
63 it('Should send a notification on new registration request', async function () {
64 this.timeout(50000)
65
66 const registrationReason = 'my reason'
67 await server.registrations.requestRegistration({ username: 'user_11', registrationReason })
68
69 await waitJobs([ server ])
70
71 await checkRegistrationRequest({ ...baseParams, username: 'user_11', registrationReason, checkType: 'presence' })
72
73 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
74 await checkRegistrationRequest({ ...baseParams, ...userOverride, username: 'user_11', registrationReason, checkType: 'absence' })
75 })
76 })
77
78 after(async function () {
79 MockSmtpServer.Instance.kill()
80
81 await cleanupTests([ server ])
82 })
83})