1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
6 checkNewPeerTubeVersion,
8 MockJoinPeerTubeVersions,
10 prepareNotificationsTest
11 } from '@server/tests/shared'
12 import { wait } from '@shared/core-utils'
13 import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
14 import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
16 describe('Test admin notifications', function () {
17 let server: PeerTubeServer
18 let userNotifications: UserNotification[] = []
19 let adminNotifications: UserNotification[] = []
20 let emails: object[] = []
21 let baseParams: CheckerBaseParams
22 let joinPeerTubeServer: MockJoinPeerTubeVersions
24 before(async function () {
27 joinPeerTubeServer = new MockJoinPeerTubeVersions()
28 const port = await joinPeerTubeServer.initialize()
32 check_latest_version: {
34 url: `http://127.0.0.1:${port}/versions.json`
40 check_latest_versions_interval: '3 seconds'
45 const res = await prepareNotificationsTest(1, config)
47 server = res.servers[0]
49 userNotifications = res.userNotifications
50 adminNotifications = res.adminNotifications
55 socketNotifications: adminNotifications,
56 token: server.accessToken
59 await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
60 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
63 describe('Latest PeerTube version notification', function () {
65 it('Should not send a notification to admins if there is no new version', async function () {
68 joinPeerTubeServer.setLatestVersion('1.4.2')
71 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
74 it('Should send a notification to admins on new version', async function () {
77 joinPeerTubeServer.setLatestVersion('15.4.2')
80 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
83 it('Should not send the same notification to admins', async function () {
87 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
90 it('Should not have sent a notification to users', async function () {
93 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
96 it('Should send a new notification after a new release', async function () {
99 joinPeerTubeServer.setLatestVersion('15.4.3')
102 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
103 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
107 describe('Latest plugin version notification', function () {
109 it('Should not send a notification to admins if there is no new plugin version', async function () {
113 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
116 it('Should send a notification to admins on new plugin version', async function () {
119 await server.sql.setPluginVersion('hello-world', '0.0.1')
120 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
123 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
126 it('Should not send the same notification to admins', async function () {
131 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
134 it('Should not have sent a notification to users', async function () {
135 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
138 it('Should send a new notification after a new plugin release', async function () {
141 await server.sql.setPluginVersion('hello-world', '0.0.1')
142 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
145 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
149 after(async function () {
150 MockSmtpServer.Instance.kill()
152 await cleanupTests([ server ])