X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fnotifications%2Fadmin-notifications.ts;h=b3bb4888ec9e071b07cdcbcd9af2599d082e1892;hb=638949c67a1fe6966909184880f0194ac6beb077;hp=e07327d74c51c873061ae403357c9d0ba725f2b5;hpb=32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index e07327d74..b3bb4888e 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -1,22 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' import { expect } from 'chai' -import { MockJoinPeerTubeVersions } from '@shared/extra-utils/mock-servers/joinpeertube-versions' -import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils' -import { ServerInfo } from '../../../../shared/extra-utils/index' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { CheckerBaseParams, checkNewPeerTubeVersion, checkNewPluginVersion, + MockJoinPeerTubeVersions, + MockSmtpServer, prepareNotificationsTest -} from '../../../../shared/extra-utils/users/user-notifications' -import { UserNotification, UserNotificationType } from '../../../../shared/models/users' -import { PluginType } from '@shared/models' +} from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { PluginType, UserNotification, UserNotificationType } from '@shared/models' +import { cleanupTests, PeerTubeServer } from '@shared/server-commands' describe('Test admin notifications', function () { - let server: ServerInfo + let server: PeerTubeServer let userNotifications: UserNotification[] = [] let adminNotifications: UserNotification[] = [] let emails: object[] = [] @@ -26,11 +24,14 @@ describe('Test admin notifications', function () { before(async function () { this.timeout(120000) + joinPeerTubeServer = new MockJoinPeerTubeVersions() + const port = await joinPeerTubeServer.initialize() + const config = { peertube: { check_latest_version: { enabled: true, - url: 'http://localhost:42102/versions.json' + url: `http://localhost:${port}/versions.json` } }, plugins: { @@ -49,26 +50,14 @@ describe('Test admin notifications', function () { adminNotifications = res.adminNotifications baseParams = { - server: server, + server, emails, socketNotifications: adminNotifications, token: server.accessToken } - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-plugin-hello-world' - }) - - await installPlugin({ - url: server.url, - accessToken: server.accessToken, - npmName: 'peertube-theme-background-red' - }) - - joinPeerTubeServer = new MockJoinPeerTubeVersions() - await joinPeerTubeServer.initialize() + await server.plugins.install({ npmName: 'peertube-plugin-hello-world' }) + await server.plugins.install({ npmName: 'peertube-theme-background-red' }) }) describe('Latest PeerTube version notification', function () { @@ -79,7 +68,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('1.4.2') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '1.4.2', 'absence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) }) it('Should send a notification to admins on new plugin version', async function () { @@ -88,7 +77,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('15.4.2') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '15.4.2', 'presence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) }) it('Should not send the same notification to admins', async function () { @@ -110,7 +99,7 @@ describe('Test admin notifications', function () { joinPeerTubeServer.setLatestVersion('15.4.3') await wait(3000) - await checkNewPeerTubeVersion(baseParams, '15.4.3', 'presence') + await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2) }) }) @@ -121,17 +110,17 @@ describe('Test admin notifications', function () { this.timeout(30000) await wait(6000) - await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'absence') + await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) }) it('Should send a notification to admins on new plugin version', async function () { this.timeout(30000) - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') - await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') + await server.sql.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) - await checkNewPluginVersion(baseParams, PluginType.PLUGIN, 'hello-world', 'presence') + await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) }) it('Should not send the same notification to admins', async function () { @@ -149,8 +138,8 @@ describe('Test admin notifications', function () { it('Should send a new notification after a new plugin release', async function () { this.timeout(30000) - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') - await setPluginLatestVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') + await server.sql.setPluginLatestVersion('hello-world', '0.0.1') await wait(6000) expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)