2021-03-11 09:54:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import {
|
|
|
|
CheckerBaseParams,
|
|
|
|
checkNewPeerTubeVersion,
|
|
|
|
checkNewPluginVersion,
|
2021-07-07 03:33:49 -05:00
|
|
|
MockJoinPeerTubeVersions,
|
|
|
|
MockSmtpServer,
|
2021-12-17 04:58:15 -06:00
|
|
|
prepareNotificationsTest
|
|
|
|
} from '@server/tests/shared'
|
|
|
|
import { wait } from '@shared/core-utils'
|
2021-07-07 03:33:49 -05:00
|
|
|
import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
|
2021-03-11 09:54:52 -06:00
|
|
|
|
|
|
|
describe('Test admin notifications', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let server: PeerTubeServer
|
2021-03-11 09:54:52 -06:00
|
|
|
let userNotifications: UserNotification[] = []
|
|
|
|
let adminNotifications: UserNotification[] = []
|
|
|
|
let emails: object[] = []
|
|
|
|
let baseParams: CheckerBaseParams
|
|
|
|
let joinPeerTubeServer: MockJoinPeerTubeVersions
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
2021-04-15 06:52:27 -05:00
|
|
|
joinPeerTubeServer = new MockJoinPeerTubeVersions()
|
|
|
|
const port = await joinPeerTubeServer.initialize()
|
|
|
|
|
2021-03-11 09:54:52 -06:00
|
|
|
const config = {
|
|
|
|
peertube: {
|
|
|
|
check_latest_version: {
|
|
|
|
enabled: true,
|
2021-04-15 06:52:27 -05:00
|
|
|
url: `http://localhost:${port}/versions.json`
|
2021-03-11 09:54:52 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
index: {
|
|
|
|
enabled: true,
|
|
|
|
check_latest_versions_interval: '5 seconds'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await prepareNotificationsTest(1, config)
|
|
|
|
emails = res.emails
|
|
|
|
server = res.servers[0]
|
|
|
|
|
|
|
|
userNotifications = res.userNotifications
|
|
|
|
adminNotifications = res.adminNotifications
|
|
|
|
|
|
|
|
baseParams = {
|
|
|
|
server: server,
|
|
|
|
emails,
|
|
|
|
socketNotifications: adminNotifications,
|
|
|
|
token: server.accessToken
|
|
|
|
}
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
|
|
|
|
await server.plugins.install({ npmName: 'peertube-theme-background-red' })
|
2021-03-11 09:54:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('Latest PeerTube version notification', function () {
|
|
|
|
|
|
|
|
it('Should not send a notification to admins if there is not a new version', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
joinPeerTubeServer.setLatestVersion('1.4.2')
|
|
|
|
|
|
|
|
await wait(3000)
|
2021-07-27 02:07:38 -05:00
|
|
|
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
|
2021-03-11 09:54:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a notification to admins on new plugin version', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
joinPeerTubeServer.setLatestVersion('15.4.2')
|
|
|
|
|
|
|
|
await wait(3000)
|
2021-07-27 02:07:38 -05:00
|
|
|
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
|
2021-03-11 09:54:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send the same notification to admins', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await wait(3000)
|
|
|
|
expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have sent a notification to users', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new notification after a new release', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
joinPeerTubeServer.setLatestVersion('15.4.3')
|
|
|
|
|
|
|
|
await wait(3000)
|
2021-07-27 02:07:38 -05:00
|
|
|
await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
|
2021-03-11 09:54:52 -06:00
|
|
|
expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Latest plugin version notification', function () {
|
|
|
|
|
|
|
|
it('Should not send a notification to admins if there is no new plugin version', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await wait(6000)
|
2021-07-27 02:07:38 -05:00
|
|
|
await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
|
2021-03-11 09:54:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a notification to admins on new plugin version', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.sql.setPluginVersion('hello-world', '0.0.1')
|
|
|
|
await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
|
2021-03-11 09:54:52 -06:00
|
|
|
await wait(6000)
|
|
|
|
|
2021-07-27 02:07:38 -05:00
|
|
|
await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
|
2021-03-11 09:54:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not send the same notification to admins', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have sent a notification to users', async function () {
|
|
|
|
expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should send a new notification after a new plugin release', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await server.sql.setPluginVersion('hello-world', '0.0.1')
|
|
|
|
await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
|
2021-03-11 09:54:52 -06:00
|
|
|
await wait(6000)
|
|
|
|
|
|
|
|
expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
MockSmtpServer.Instance.kill()
|
|
|
|
|
|
|
|
await cleanupTests([ server ])
|
|
|
|
})
|
|
|
|
})
|