aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications/registrations-notifications.ts
blob: d20fc8df368bd2dd014b624511f218fd98d9c557 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import {
  CheckerBaseParams,
  checkRegistrationRequest,
  checkUserRegistered,
  MockSmtpServer,
  prepareNotificationsTest
} from '@server/tests/shared'
import { UserNotification } from '@shared/models'
import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'

describe('Test registrations notifications', function () {
  let server: PeerTubeServer
  let userToken1: string

  let userNotifications: UserNotification[] = []
  let adminNotifications: UserNotification[] = []
  let emails: object[] = []

  let baseParams: CheckerBaseParams

  before(async function () {
    this.timeout(120000)

    const res = await prepareNotificationsTest(1)

    server = res.servers[0]
    emails = res.emails
    userToken1 = res.userAccessToken
    adminNotifications = res.adminNotifications
    userNotifications = res.userNotifications

    baseParams = {
      server,
      emails,
      socketNotifications: adminNotifications,
      token: server.accessToken
    }
  })

  describe('New direct registration for moderators', function () {

    before(async function () {
      await server.config.enableSignup(false)
    })

    it('Should send a notification only to moderators when a user registers on the instance', async function () {
      this.timeout(50000)

      await server.registrations.register({ username: 'user_10' })

      await waitJobs([ server ])

      await checkUserRegistered({ ...baseParams, username: 'user_10', checkType: 'presence' })

      const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
      await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_10', checkType: 'absence' })
    })
  })

  describe('New registration request for moderators', function () {

    before(async function () {
      await server.config.enableSignup(true)
    })

    it('Should send a notification on new registration request', async function () {
      this.timeout(50000)

      const registrationReason = 'my reason'
      await server.registrations.requestRegistration({ username: 'user_11', registrationReason })

      await waitJobs([ server ])

      await checkRegistrationRequest({ ...baseParams, username: 'user_11', registrationReason, checkType: 'presence' })

      const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
      await checkRegistrationRequest({ ...baseParams, ...userOverride, username: 'user_11', registrationReason, checkType: 'absence' })
    })
  })

  after(async function () {
    MockSmtpServer.Instance.kill()

    await cleanupTests([ server ])
  })
})