]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { | |
5 | CheckerBaseParams, | |
6 | checkNewPeerTubeVersion, | |
7 | checkNewPluginVersion, | |
8 | MockJoinPeerTubeVersions, | |
9 | MockSmtpServer, | |
10 | prepareNotificationsTest | |
11 | } from '@server/tests/shared' | |
12 | import { wait } from '@shared/core-utils' | |
13 | import { PluginType, UserNotification, UserNotificationType } from '@shared/models' | |
14 | import { cleanupTests, PeerTubeServer } from '@shared/server-commands' | |
15 | ||
16 | describe('Test admin notifications', function () { | |
17 | let server: PeerTubeServer | |
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 | ||
27 | joinPeerTubeServer = new MockJoinPeerTubeVersions() | |
28 | const port = await joinPeerTubeServer.initialize() | |
29 | ||
30 | const config = { | |
31 | peertube: { | |
32 | check_latest_version: { | |
33 | enabled: true, | |
34 | url: `http://localhost:${port}/versions.json` | |
35 | } | |
36 | }, | |
37 | plugins: { | |
38 | index: { | |
39 | enabled: true, | |
40 | check_latest_versions_interval: '3 seconds' | |
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 = { | |
53 | server, | |
54 | emails, | |
55 | socketNotifications: adminNotifications, | |
56 | token: server.accessToken | |
57 | } | |
58 | ||
59 | await server.plugins.install({ npmName: 'peertube-plugin-hello-world' }) | |
60 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) | |
61 | }) | |
62 | ||
63 | describe('Latest PeerTube version notification', function () { | |
64 | ||
65 | it('Should not send a notification to admins if there is no new version', async function () { | |
66 | this.timeout(30000) | |
67 | ||
68 | joinPeerTubeServer.setLatestVersion('1.4.2') | |
69 | ||
70 | await wait(3000) | |
71 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) | |
72 | }) | |
73 | ||
74 | it('Should send a notification to admins on new version', async function () { | |
75 | this.timeout(30000) | |
76 | ||
77 | joinPeerTubeServer.setLatestVersion('15.4.2') | |
78 | ||
79 | await wait(3000) | |
80 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) | |
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) | |
102 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) | |
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) | |
113 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) | |
114 | }) | |
115 | ||
116 | it('Should send a notification to admins on new plugin version', async function () { | |
117 | this.timeout(30000) | |
118 | ||
119 | await server.sql.setPluginVersion('hello-world', '0.0.1') | |
120 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') | |
121 | await wait(6000) | |
122 | ||
123 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) | |
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 | ||
141 | await server.sql.setPluginVersion('hello-world', '0.0.1') | |
142 | await server.sql.setPluginLatestVersion('hello-world', '0.0.1') | |
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 | }) |