diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/notifications/admin-notifications.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/notifications/admin-notifications.ts')
-rw-r--r-- | server/tests/api/notifications/admin-notifications.ts | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts deleted file mode 100644 index 4824542c9..000000000 --- a/server/tests/api/notifications/admin-notifications.ts +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
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 | SQLCommand | ||
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 sqlCommand: SQLCommand | ||
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://127.0.0.1:${port}/versions.json` | ||
37 | } | ||
38 | }, | ||
39 | plugins: { | ||
40 | index: { | ||
41 | enabled: true, | ||
42 | check_latest_versions_interval: '3 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, | ||
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 | sqlCommand = new SQLCommand(server) | ||
65 | }) | ||
66 | |||
67 | describe('Latest PeerTube version notification', function () { | ||
68 | |||
69 | it('Should not send a notification to admins if there is no new version', async function () { | ||
70 | this.timeout(30000) | ||
71 | |||
72 | joinPeerTubeServer.setLatestVersion('1.4.2') | ||
73 | |||
74 | await wait(3000) | ||
75 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '1.4.2', checkType: 'absence' }) | ||
76 | }) | ||
77 | |||
78 | it('Should send a notification to admins on new version', async function () { | ||
79 | this.timeout(30000) | ||
80 | |||
81 | joinPeerTubeServer.setLatestVersion('15.4.2') | ||
82 | |||
83 | await wait(3000) | ||
84 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.2', checkType: 'presence' }) | ||
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) | ||
106 | await checkNewPeerTubeVersion({ ...baseParams, latestVersion: '15.4.3', checkType: 'presence' }) | ||
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) | ||
117 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'absence' }) | ||
118 | }) | ||
119 | |||
120 | it('Should send a notification to admins on new plugin version', async function () { | ||
121 | this.timeout(30000) | ||
122 | |||
123 | await sqlCommand.setPluginVersion('hello-world', '0.0.1') | ||
124 | await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') | ||
125 | await wait(6000) | ||
126 | |||
127 | await checkNewPluginVersion({ ...baseParams, pluginType: PluginType.PLUGIN, pluginName: 'hello-world', checkType: 'presence' }) | ||
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 | |||
145 | await sqlCommand.setPluginVersion('hello-world', '0.0.1') | ||
146 | await sqlCommand.setPluginLatestVersion('hello-world', '0.0.1') | ||
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 | |||
156 | await sqlCommand.cleanup() | ||
157 | await cleanupTests([ server ]) | ||
158 | }) | ||
159 | }) | ||