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 /packages/tests/src/plugins/video-constants.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 'packages/tests/src/plugins/video-constants.ts')
-rw-r--r-- | packages/tests/src/plugins/video-constants.ts | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/packages/tests/src/plugins/video-constants.ts b/packages/tests/src/plugins/video-constants.ts new file mode 100644 index 000000000..b81240a64 --- /dev/null +++ b/packages/tests/src/plugins/video-constants.ts | |||
@@ -0,0 +1,180 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createSingleServer, | ||
7 | makeGetRequest, | ||
8 | PeerTubeServer, | ||
9 | PluginsCommand, | ||
10 | setAccessTokensToServers | ||
11 | } from '@peertube/peertube-server-commands' | ||
12 | import { HttpStatusCode, VideoPlaylistPrivacy, VideoPrivacy } from '@peertube/peertube-models' | ||
13 | |||
14 | describe('Test plugin altering video constants', function () { | ||
15 | let server: PeerTubeServer | ||
16 | |||
17 | before(async function () { | ||
18 | this.timeout(30000) | ||
19 | |||
20 | server = await createSingleServer(1) | ||
21 | await setAccessTokensToServers([ server ]) | ||
22 | |||
23 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) | ||
24 | }) | ||
25 | |||
26 | it('Should have updated languages', async function () { | ||
27 | const languages = await server.videos.getLanguages() | ||
28 | |||
29 | expect(languages['en']).to.not.exist | ||
30 | expect(languages['fr']).to.not.exist | ||
31 | |||
32 | expect(languages['al_bhed']).to.equal('Al Bhed') | ||
33 | expect(languages['al_bhed2']).to.equal('Al Bhed 2') | ||
34 | expect(languages['al_bhed3']).to.not.exist | ||
35 | }) | ||
36 | |||
37 | it('Should have updated categories', async function () { | ||
38 | const categories = await server.videos.getCategories() | ||
39 | |||
40 | expect(categories[1]).to.not.exist | ||
41 | expect(categories[2]).to.not.exist | ||
42 | |||
43 | expect(categories[42]).to.equal('Best category') | ||
44 | expect(categories[43]).to.equal('High best category') | ||
45 | }) | ||
46 | |||
47 | it('Should have updated licences', async function () { | ||
48 | const licences = await server.videos.getLicences() | ||
49 | |||
50 | expect(licences[1]).to.not.exist | ||
51 | expect(licences[7]).to.not.exist | ||
52 | |||
53 | expect(licences[42]).to.equal('Best licence') | ||
54 | expect(licences[43]).to.equal('High best licence') | ||
55 | }) | ||
56 | |||
57 | it('Should have updated video privacies', async function () { | ||
58 | const privacies = await server.videos.getPrivacies() | ||
59 | |||
60 | expect(privacies[1]).to.exist | ||
61 | expect(privacies[2]).to.not.exist | ||
62 | expect(privacies[3]).to.exist | ||
63 | expect(privacies[4]).to.exist | ||
64 | }) | ||
65 | |||
66 | it('Should have updated playlist privacies', async function () { | ||
67 | const playlistPrivacies = await server.playlists.getPrivacies() | ||
68 | |||
69 | expect(playlistPrivacies[1]).to.exist | ||
70 | expect(playlistPrivacies[2]).to.exist | ||
71 | expect(playlistPrivacies[3]).to.not.exist | ||
72 | }) | ||
73 | |||
74 | it('Should not be able to create a video with this privacy', async function () { | ||
75 | const attributes = { name: 'video', privacy: VideoPrivacy.UNLISTED } | ||
76 | await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
77 | }) | ||
78 | |||
79 | it('Should not be able to create a video with this privacy', async function () { | ||
80 | const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } | ||
81 | await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
82 | }) | ||
83 | |||
84 | it('Should be able to upload a video with these values', async function () { | ||
85 | const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } | ||
86 | const { uuid } = await server.videos.upload({ attributes }) | ||
87 | |||
88 | const video = await server.videos.get({ id: uuid }) | ||
89 | expect(video.language.label).to.equal('Al Bhed 2') | ||
90 | expect(video.licence.label).to.equal('Best licence') | ||
91 | expect(video.category.label).to.equal('Best category') | ||
92 | }) | ||
93 | |||
94 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { | ||
95 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) | ||
96 | |||
97 | { | ||
98 | const languages = await server.videos.getLanguages() | ||
99 | |||
100 | expect(languages['en']).to.equal('English') | ||
101 | expect(languages['fr']).to.equal('French') | ||
102 | |||
103 | expect(languages['al_bhed']).to.not.exist | ||
104 | expect(languages['al_bhed2']).to.not.exist | ||
105 | expect(languages['al_bhed3']).to.not.exist | ||
106 | } | ||
107 | |||
108 | { | ||
109 | const categories = await server.videos.getCategories() | ||
110 | |||
111 | expect(categories[1]).to.equal('Music') | ||
112 | expect(categories[2]).to.equal('Films') | ||
113 | |||
114 | expect(categories[42]).to.not.exist | ||
115 | expect(categories[43]).to.not.exist | ||
116 | } | ||
117 | |||
118 | { | ||
119 | const licences = await server.videos.getLicences() | ||
120 | |||
121 | expect(licences[1]).to.equal('Attribution') | ||
122 | expect(licences[7]).to.equal('Public Domain Dedication') | ||
123 | |||
124 | expect(licences[42]).to.not.exist | ||
125 | expect(licences[43]).to.not.exist | ||
126 | } | ||
127 | |||
128 | { | ||
129 | const privacies = await server.videos.getPrivacies() | ||
130 | |||
131 | expect(privacies[1]).to.exist | ||
132 | expect(privacies[2]).to.exist | ||
133 | expect(privacies[3]).to.exist | ||
134 | expect(privacies[4]).to.exist | ||
135 | } | ||
136 | |||
137 | { | ||
138 | const playlistPrivacies = await server.playlists.getPrivacies() | ||
139 | |||
140 | expect(playlistPrivacies[1]).to.exist | ||
141 | expect(playlistPrivacies[2]).to.exist | ||
142 | expect(playlistPrivacies[3]).to.exist | ||
143 | } | ||
144 | }) | ||
145 | |||
146 | it('Should be able to reset categories', async function () { | ||
147 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) | ||
148 | |||
149 | { | ||
150 | const categories = await server.videos.getCategories() | ||
151 | |||
152 | expect(categories[1]).to.not.exist | ||
153 | expect(categories[2]).to.not.exist | ||
154 | |||
155 | expect(categories[42]).to.exist | ||
156 | expect(categories[43]).to.exist | ||
157 | } | ||
158 | |||
159 | await makeGetRequest({ | ||
160 | url: server.url, | ||
161 | token: server.accessToken, | ||
162 | path: '/plugins/test-video-constants/router/reset-categories', | ||
163 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
164 | }) | ||
165 | |||
166 | { | ||
167 | const categories = await server.videos.getCategories() | ||
168 | |||
169 | expect(categories[1]).to.exist | ||
170 | expect(categories[2]).to.exist | ||
171 | |||
172 | expect(categories[42]).to.not.exist | ||
173 | expect(categories[43]).to.not.exist | ||
174 | } | ||
175 | }) | ||
176 | |||
177 | after(async function () { | ||
178 | await cleanupTests([ server ]) | ||
179 | }) | ||
180 | }) | ||