1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
7 checkNewPeerTubeVersion,
10 MockJoinPeerTubeVersions,
13 prepareNotificationsTest,
15 } from '@shared/extra-utils'
16 import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
18 describe('Test admin notifications', function () {
19 let server: PeerTubeServer
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://localhost:${port}/versions.json`
42 check_latest_versions_interval: '5 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' })
65 describe('Latest PeerTube version notification', function () {
67 it('Should not send a notification to admins if there is not a new version', async function () {
70 joinPeerTubeServer.setLatestVersion('1.4.2')
73 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
76 it('Should send a notification to admins on new plugin version', async function () {
79 joinPeerTubeServer.setLatestVersion('15.4.2')
82 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
85 it('Should not send the same notification to admins', async function () {
89 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
92 it('Should not have sent a notification to users', async function () {
95 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
98 it('Should send a new notification after a new release', async function () {
101 joinPeerTubeServer.setLatestVersion('15.4.3')
104 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
105 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
109 describe('Latest plugin version notification', function () {
111 it('Should not send a notification to admins if there is no new plugin version', async function () {
115 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
118 it('Should send a notification to admins on new plugin version', async function () {
121 await server.sql.setPluginVersion('hello-world', '0.0.1')
122 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
125 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
128 it('Should not send the same notification to admins', async function () {
133 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
136 it('Should not have sent a notification to users', async function () {
137 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
140 it('Should send a new notification after a new plugin release', async function () {
143 await server.sql.setPluginVersion('hello-world', '0.0.1')
144 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
147 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
151 after(async function () {
152 MockSmtpServer.Instance.kill()
154 await cleanupTests([ server ])