1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
7 checkNewPeerTubeVersion,
9 MockJoinPeerTubeVersions,
11 prepareNotificationsTest
12 } from '@server/tests/shared'
13 import { wait } from '@shared/core-utils'
14 import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
15 import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
17 describe('Test admin notifications', function () {
18 let server: PeerTubeServer
19 let userNotifications: UserNotification[] = []
20 let adminNotifications: UserNotification[] = []
21 let emails: object[] = []
22 let baseParams: CheckerBaseParams
23 let joinPeerTubeServer: MockJoinPeerTubeVersions
25 before(async function () {
28 joinPeerTubeServer = new MockJoinPeerTubeVersions()
29 const port = await joinPeerTubeServer.initialize()
33 check_latest_version: {
35 url: `http://localhost:${port}/versions.json`
41 check_latest_versions_interval: '5 seconds'
46 const res = await prepareNotificationsTest(1, config)
48 server = res.servers[0]
50 userNotifications = res.userNotifications
51 adminNotifications = res.adminNotifications
56 socketNotifications: adminNotifications,
57 token: server.accessToken
60 await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
61 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
64 describe('Latest PeerTube version notification', function () {
66 it('Should not send a notification to admins if there is not a new version', async function () {
69 joinPeerTubeServer.setLatestVersion('1.4.2')
72 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
75 it('Should send a notification to admins on new plugin version', async function () {
78 joinPeerTubeServer.setLatestVersion('15.4.2')
81 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
84 it('Should not send the same notification to admins', async function () {
88 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
91 it('Should not have sent a notification to users', async function () {
94 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
97 it('Should send a new notification after a new release', async function () {
100 joinPeerTubeServer.setLatestVersion('15.4.3')
103 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
104 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
108 describe('Latest plugin version notification', function () {
110 it('Should not send a notification to admins if there is no new plugin version', async function () {
114 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
117 it('Should send a notification to admins on new plugin version', async function () {
120 await server.sql.setPluginVersion('hello-world', '0.0.1')
121 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
124 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
127 it('Should not send the same notification to admins', async function () {
132 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
135 it('Should not have sent a notification to users', async function () {
136 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
139 it('Should send a new notification after a new plugin release', async function () {
142 await server.sql.setPluginVersion('hello-world', '0.0.1')
143 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
146 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
150 after(async function () {
151 MockSmtpServer.Instance.kill()
153 await cleanupTests([ server ])