1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
6 checkNewPeerTubeVersion,
8 MockJoinPeerTubeVersions,
10 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 sqlCommand: SQLCommand
20 let userNotifications: UserNotification[] = []
21 let adminNotifications: UserNotification[] = []
22 let emails: object[] = []
23 let baseParams: CheckerBaseParams
24 let joinPeerTubeServer: MockJoinPeerTubeVersions
26 before(async function () {
29 joinPeerTubeServer = new MockJoinPeerTubeVersions()
30 const port = await joinPeerTubeServer.initialize()
34 check_latest_version: {
36 url: `http://127.0.0.1:${port}/versions.json`
42 check_latest_versions_interval: '3 seconds'
47 const res = await prepareNotificationsTest(1, config)
49 server = res.servers[0]
51 userNotifications = res.userNotifications
52 adminNotifications = res.adminNotifications
57 socketNotifications: adminNotifications,
58 token: server.accessToken
61 await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
62 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
64 sqlCommand = new SQLCommand(server)
67 describe('Latest PeerTube version notification', function () {
69 it('Should not send a notification to admins if there is no new version', async function () {
72 joinPeerTubeServer.setLatestVersion('1.4.2')
75 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
78 it('Should send a notification to admins on new version', async function () {
81 joinPeerTubeServer.setLatestVersion('15.4.2')
84 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
87 it('Should not send the same notification to admins', async function () {
91 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
94 it('Should not have sent a notification to users', async function () {
97 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
100 it('Should send a new notification after a new release', async function () {
103 joinPeerTubeServer.setLatestVersion('15.4.3')
106 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
107 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
111 describe('Latest plugin version notification', function () {
113 it('Should not send a notification to admins if there is no new plugin version', async function () {
117 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
120 it('Should send a notification to admins on new plugin version', async function () {
123 await sqlCommand.setPluginVersion('hello-world', '0.0.1')
124 await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1')
127 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
130 it('Should not send the same notification to admins', async function () {
135 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
138 it('Should not have sent a notification to users', async function () {
139 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
142 it('Should send a new notification after a new plugin release', async function () {
145 await sqlCommand.setPluginVersion('hello-world', '0.0.1')
146 await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1')
149 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
153 after(async function () {
154 MockSmtpServer.Instance.kill()
156 await sqlCommand.cleanup()
157 await cleanupTests([ server ])