]>
Commit | Line | Data |
---|---|---|
32a18cbf C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
32a18cbf | 3 | import { expect } from 'chai' |
32a18cbf C |
4 | import { |
5 | CheckerBaseParams, | |
6 | checkNewPeerTubeVersion, | |
7 | checkNewPluginVersion, | |
ae2abfd3 C |
8 | MockJoinPeerTubeVersions, |
9 | MockSmtpServer, | |
d102de1b C |
10 | prepareNotificationsTest, |
11 | SQLCommand | |
c55e3d72 C |
12 | } from '@server/tests/shared' |
13 | import { wait } from '@shared/core-utils' | |
ae2abfd3 | 14 | import { PluginType, UserNotification, UserNotificationType } from '@shared/models' |
c55e3d72 | 15 | import { cleanupTests, PeerTubeServer } from '@shared/server-commands' |
32a18cbf C |
16 | |
17 | describe('Test admin notifications', function () { | |
254d3579 | 18 | let server: PeerTubeServer |
d102de1b | 19 | let sqlCommand: SQLCommand |
32a18cbf C |
20 | let userNotifications: UserNotification[] = [] |
21 | let adminNotifications: UserNotification[] = [] | |
22 | let emails: object[] = [] | |
23 | let baseParams: CheckerBaseParams | |
24 | let joinPeerTubeServer: MockJoinPeerTubeVersions | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(120000) | |
28 | ||
f6500729 C |
29 | joinPeerTubeServer = new MockJoinPeerTubeVersions() |
30 | const port = await joinPeerTubeServer.initialize() | |
31 | ||
32a18cbf C |
32 | const config = { |
33 | peertube: { | |
34 | check_latest_version: { | |
35 | enabled: true, | |
2732eeff | 36 | url: `http://127.0.0.1:${port}/versions.json` |
32a18cbf C |
37 | } |
38 | }, | |
39 | plugins: { | |
40 | index: { | |
41 | enabled: true, | |
b7faa837 | 42 | check_latest_versions_interval: '3 seconds' |
32a18cbf C |
43 | } |
44 | } | |
45 | } | |
46 | ||
47 | const res = await prepareNotificationsTest(1, config) | |
48 | emails = res.emails | |
49 | server = res.servers[0] | |
50 | ||
51 | userNotifications = res.userNotifications | |
52 | adminNotifications = res.adminNotifications | |
53 | ||
54 | baseParams = { | |
ba2684ce | 55 | server, |
32a18cbf C |
56 | emails, |
57 | socketNotifications: adminNotifications, | |
58 | token: server.accessToken | |
59 | } | |
60 | ||
89d241a7 C |
61 | await server.plugins.install({ npmName: 'peertube-plugin-hello-world' }) |
62 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) | |
d102de1b C |
63 | |
64 | sqlCommand = new SQLCommand(server) | |
32a18cbf C |
65 | }) |
66 | ||
67 | describe('Latest PeerTube version notification', function () { | |
68 | ||
b7faa837 | 69 | it('Should not send a notification to admins if there is no new version', async function () { |
32a18cbf C |
70 | this.timeout(30000) |
71 | ||
72 | joinPeerTubeServer.setLatestVersion('1.4.2') | |
73 | ||
74 | await wait(3000) | |
29837f88 | 75 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) |
32a18cbf C |
76 | }) |
77 | ||
b7faa837 | 78 | it('Should send a notification to admins on new version', async function () { |
32a18cbf C |
79 | this.timeout(30000) |
80 | ||
81 | joinPeerTubeServer.setLatestVersion('15.4.2') | |
82 | ||
83 | await wait(3000) | |
29837f88 | 84 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) |
32a18cbf C |
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) | |
29837f88 | 106 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) |
32a18cbf C |
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) | |
29837f88 | 117 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) |
32a18cbf C |
118 | }) |
119 | ||
120 | it('Should send a notification to admins on new plugin version', async function () { | |
121 | this.timeout(30000) | |
122 | ||
d102de1b C |
123 | await sqlCommand.setPluginVersion('hello-world', '0.0.1') |
124 | await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') | |
32a18cbf C |
125 | await wait(6000) |
126 | ||
29837f88 | 127 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) |
32a18cbf C |
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 | ||
d102de1b C |
145 | await sqlCommand.setPluginVersion('hello-world', '0.0.1') |
146 | await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') | |
32a18cbf C |
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 | ||
d102de1b | 156 | await sqlCommand.cleanup() |
32a18cbf C |
157 | await cleanupTests([ server ]) |
158 | }) | |
159 | }) |