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