1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions'
6 import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'
7 import { ServerInfo } from '../../../../shared/extra-utils/index'
8 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
11 checkNewPeerTubeVersion,
12 checkNewPluginVersion,
13 prepareNotificationsTest
14 } from '../../../../shared/extra-utils/users/user-notifications'
15 import { UserNotification, UserNotificationType } from '../../../../shared/models/users'
16 import { PluginType } from '@shared/models'
18 describe('Test admin notifications', function () {
19 let server: ServerInfo
20 let userNotifications: UserNotification[] = []
21 let adminNotifications: UserNotification[] = []
22 let emails: object[] = []
23 let baseParams: CheckerBaseParams
24 let joinPeerTubeServer: MockJoinPeerTubeVersions
26 before(async function () {
31 check_latest_version: {
33 url: 'http://localhost:42102/versions.json'
39 check_latest_versions_interval: '5 seconds'
44 const res = await prepareNotificationsTest(1, config)
46 server = res.servers[0]
48 userNotifications = res.userNotifications
49 adminNotifications = res.adminNotifications
54 socketNotifications: adminNotifications,
55 token: server.accessToken
60 accessToken: server.accessToken,
61 npmName: 'peertube-plugin-hello-world'
66 accessToken: server.accessToken,
67 npmName: 'peertube-theme-background-red'
70 joinPeerTubeServer = new MockJoinPeerTubeVersions()
71 await joinPeerTubeServer.initialize()
74 describe('Latest PeerTube version notification', function () {
76 it('Should not send a notification to admins if there is not a new version', async function () {
79 joinPeerTubeServer.setLatestVersion('1.4.2')
82 await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence')
85 it('Should send a notification to admins on new plugin version', async function () {
88 joinPeerTubeServer.setLatestVersion('15.4.2')
91 await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence')
94 it('Should not send the same notification to admins', async function () {
98 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
101 it('Should not have sent a notification to users', async function () {
104 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
107 it('Should send a new notification after a new release', async function () {
110 joinPeerTubeServer.setLatestVersion('15.4.3')
113 await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence')
114 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
118 describe('Latest plugin version notification', function () {
120 it('Should not send a notification to admins if there is no new plugin version', async function () {
124 await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence')
127 it('Should send a notification to admins on new plugin version', async function () {
130 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
131 await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1')
134 await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence')
137 it('Should not send the same notification to admins', async function () {
142 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
145 it('Should not have sent a notification to users', async function () {
146 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
149 it('Should send a new notification after a new plugin release', async function () {
152 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
153 await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1')
156 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
160 after(async function () {
161 MockSmtpServer.Instance.kill()
163 await cleanupTests([ server ])