1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5 checkRegistrationRequest,
8 prepareNotificationsTest
9 } from '@server/tests/shared'
10 import { UserNotification } from '@shared/models'
11 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
13 describe('Test registrations notifications', function () {
14 let server: PeerTubeServer
15 let userToken1: string
17 let userNotifications: UserNotification[] = []
18 let adminNotifications: UserNotification[] = []
19 let emails: object[] = []
21 let baseParams: CheckerBaseParams
23 before(async function () {
26 const res = await prepareNotificationsTest(1)
28 server = res.servers[0]
30 userToken1 = res.userAccessToken
31 adminNotifications = res.adminNotifications
32 userNotifications = res.userNotifications
37 socketNotifications: adminNotifications,
38 token: server.accessToken
42 describe('New direct registration for moderators', function () {
44 before(async function () {
45 await server.config.enableSignup(false)
48 it('Should send a notification only to moderators when a user registers on the instance', async function () {
51 await server.registrations.register({ username: 'user_10' })
53 await waitJobs([ server ])
55 await checkUserRegistered({ ...baseParams, username: 'user_10', checkType: 'presence' })
57 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
58 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_10', checkType: 'absence' })
62 describe('New registration request for moderators', function () {
64 before(async function () {
65 await server.config.enableSignup(true)
68 it('Should send a notification on new registration request', async function () {
71 const registrationReason = 'my reason'
72 await server.registrations.requestRegistration({ username: 'user_11', registrationReason })
74 await waitJobs([ server ])
76 await checkRegistrationRequest({ ...baseParams, username: 'user_11', registrationReason, checkType: 'presence' })
78 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
79 await checkRegistrationRequest({ ...baseParams, ...userOverride, username: 'user_11', registrationReason, checkType: 'absence' })
83 after(async function () {
84 MockSmtpServer.Instance.kill()
86 await cleanupTests([ server ])