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