]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/notifications/admin-notifications.ts
Move test functions outside extra-utils
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / admin-notifications.ts
CommitLineData
32a18cbf
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
32a18cbf
C
5import {
6 CheckerBaseParams,
7 checkNewPeerTubeVersion,
8 checkNewPluginVersion,
ae2abfd3
C
9 MockJoinPeerTubeVersions,
10 MockSmtpServer,
c55e3d72
C
11 prepareNotificationsTest
12} from '@server/tests/shared'
13import { wait } from '@shared/core-utils'
ae2abfd3 14import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
c55e3d72 15import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
32a18cbf
C
16
17describe('Test admin notifications', function () {
254d3579 18 let server: PeerTubeServer
32a18cbf
C
19 let userNotifications: UserNotification[] = []
20 let adminNotifications: UserNotification[] = []
21 let emails: object[] = []
22 let baseParams: CheckerBaseParams
23 let joinPeerTubeServer: MockJoinPeerTubeVersions
24
25 before(async function () {
26 this.timeout(120000)
27
f6500729
C
28 joinPeerTubeServer = new MockJoinPeerTubeVersions()
29 const port = await joinPeerTubeServer.initialize()
30
32a18cbf
C
31 const config = {
32 peertube: {
33 check_latest_version: {
34 enabled: true,
f6500729 35 url: `http://localhost:${port}/versions.json`
32a18cbf
C
36 }
37 },
38 plugins: {
39 index: {
40 enabled: true,
41 check_latest_versions_interval: '5 seconds'
42 }
43 }
44 }
45
46 const res = await prepareNotificationsTest(1, config)
47 emails = res.emails
48 server = res.servers[0]
49
50 userNotifications = res.userNotifications
51 adminNotifications = res.adminNotifications
52
53 baseParams = {
54 server: server,
55 emails,
56 socketNotifications: adminNotifications,
57 token: server.accessToken
58 }
59
89d241a7
C
60 await server.plugins.install({ npmName: 'peertube-plugin-hello-world' })
61 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
32a18cbf
C
62 })
63
64 describe('Latest PeerTube version notification', function () {
65
66 it('Should not send a notification to admins if there is not a new version', async function () {
67 this.timeout(30000)
68
69 joinPeerTubeServer.setLatestVersion('1.4.2')
70
71 await wait(3000)
29837f88 72 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' })
32a18cbf
C
73 })
74
75 it('Should send a notification to admins on new plugin version', async function () {
76 this.timeout(30000)
77
78 joinPeerTubeServer.setLatestVersion('15.4.2')
79
80 await wait(3000)
29837f88 81 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' })
32a18cbf
C
82 })
83
84 it('Should not send the same notification to admins', async function () {
85 this.timeout(30000)
86
87 await wait(3000)
88 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(1)
89 })
90
91 it('Should not have sent a notification to users', async function () {
92 this.timeout(30000)
93
94 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(0)
95 })
96
97 it('Should send a new notification after a new release', async function () {
98 this.timeout(30000)
99
100 joinPeerTubeServer.setLatestVersion('15.4.3')
101
102 await wait(3000)
29837f88 103 await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' })
32a18cbf
C
104 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
105 })
106 })
107
108 describe('Latest plugin version notification', function () {
109
110 it('Should not send a notification to admins if there is no new plugin version', async function () {
111 this.timeout(30000)
112
113 await wait(6000)
29837f88 114 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' })
32a18cbf
C
115 })
116
117 it('Should send a notification to admins on new plugin version', async function () {
118 this.timeout(30000)
119
89d241a7
C
120 await server.sql.setPluginVersion('hello-world', '0.0.1')
121 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
32a18cbf
C
122 await wait(6000)
123
29837f88 124 await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' })
32a18cbf
C
125 })
126
127 it('Should not send the same notification to admins', async function () {
128 this.timeout(30000)
129
130 await wait(6000)
131
132 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(1)
133 })
134
135 it('Should not have sent a notification to users', async function () {
136 expect(userNotifications.filter(n => n.type === UserNotificationType.NEW_PLUGIN_VERSION)).to.have.lengthOf(0)
137 })
138
139 it('Should send a new notification after a new plugin release', async function () {
140 this.timeout(30000)
141
89d241a7
C
142 await server.sql.setPluginVersion('hello-world', '0.0.1')
143 await server.sql.setPluginLatestVersion('hello-world', '0.0.1')
32a18cbf
C
144 await wait(6000)
145
146 expect(adminNotifications.filter(n => n.type === UserNotificationType.NEW_PEERTUBE_VERSION)).to.have.lengthOf(2)
147 })
148 })
149
150 after(async function () {
151 MockSmtpServer.Instance.kill()
152
153 await cleanupTests([ server ])
154 })
155})