1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
7 checkNewPeerTubeVersion,
10 MockJoinPeerTubeVersions,
12 prepareNotificationsTest,
14 setPluginLatestVersion,
17 } from '@shared/extra-utils'
18 import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
20 describe('Test admin notifications', function () {
21 let server: ServerInfo
22 let userNotifications: UserNotification[] = []
23 let adminNotifications: UserNotification[] = []
24 let emails: object[] = []
25 let baseParams: CheckerBaseParams
26 let joinPeerTubeServer: MockJoinPeerTubeVersions
28 before(async function () {
31 joinPeerTubeServer = new MockJoinPeerTubeVersions()
32 const port = await joinPeerTubeServer.initialize()
36 check_latest_version: {
38 url: `http://localhost:${port}/versions.json`
44 check_latest_versions_interval: '5 seconds'
49 const res = await prepareNotificationsTest(1, config)
51 server = res.servers[0]
53 userNotifications = res.userNotifications
54 adminNotifications = res.adminNotifications
59 socketNotifications: adminNotifications,
60 token: server.accessToken
63 await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' })
64 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })
67 describe('Latest PeerTube version notification', function () {
69 it('Should not send a notification to admins if there is not a new version', async function () {
72 joinPeerTubeServer.setLatestVersion('1.4.2')
75 await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence')
78 it('Should send a notification to admins on new plugin version', async function () {
81 joinPeerTubeServer.setLatestVersion('15.4.2')
84 await checkNewPeerTubeVersion(baseParams, '15.4.2', '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, '15.4.3', '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.PLUGIN, 'hello-world', 'absence')
120 it('Should send a notification to admins on new plugin version', async function () {
123 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
124 await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1')
127 await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', '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 setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
146 await setPluginLatestVersion(server.internalServerNumber, '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 cleanupTests([ server ])