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