]>
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 | MockJoinPeerTubeVersions, | |
10 | MockSmtpServer, | |
11 | prepareNotificationsTest | |
12 | } from '@server/tests/shared' | |
13 | import { wait } from '@shared/core-utils' | |
14 | import { PluginType, UserNotification, UserNotificationType } from '@shared/models' | |
15 | import { cleanupTests, PeerTubeServer } from '@shared/server-commands' | |
16 | ||
17 | describe('Test admin notifications', function () { | |
18 | let server: PeerTubeServer | |
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 | ||
28 | joinPeerTubeServer = new MockJoinPeerTubeVersions() | |
29 | const port = await joinPeerTubeServer.initialize() | |
30 | ||
31 | const config = { | |
32 | peertube: { | |
33 | check_latest_version: { | |
34 | enabled: true, | |
35 | url: `http://localhost:${port}/versions.json` | |
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 | ||
60 | await server.plugins.install({ npmName: 'peertube-plugin-hello-world' }) | |
61 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) | |
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) | |
72 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) | |
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) | |
81 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) | |
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) | |
103 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) | |
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) | |
114 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) | |
115 | }) | |
116 | ||
117 | it('Should send a notification to admins on new plugin version', async function () { | |
118 | this.timeout(30000) | |
119 | ||
120 | await server.sql.setPluginVersion('hello-world', '0.0.1') | |
121 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') | |
122 | await wait(6000) | |
123 | ||
124 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) | |
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 | ||
142 | await server.sql.setPluginVersion('hello-world', '0.0.1') | |
143 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') | |
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 | }) |