diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/users.ts | 13 | ||||
-rw-r--r-- | server/tests/api/server/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/plugins.ts | 130 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 19 | ||||
-rw-r--r-- | server/tests/cli/index.ts | 1 | ||||
-rw-r--r-- | server/tests/cli/peertube.ts | 202 | ||||
-rw-r--r-- | server/tests/cli/plugins.ts | 87 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 39 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/package.json | 19 | ||||
-rw-r--r-- | server/tests/index.ts | 1 | ||||
-rw-r--r-- | server/tests/plugins/action-hooks.ts | 27 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 27 | ||||
-rw-r--r-- | server/tests/plugins/index.ts | 2 |
13 files changed, 484 insertions, 84 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 5d62fe2b3..5b788e328 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -387,13 +387,24 @@ describe('Test users API validators', function () { | |||
387 | } | 387 | } |
388 | }) | 388 | }) |
389 | 389 | ||
390 | it('Should fail with an invalid theme', async function () { | ||
391 | const fields = { theme: 'invalid' } | ||
392 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | ||
393 | }) | ||
394 | |||
395 | it('Should fail with an unknown theme', async function () { | ||
396 | const fields = { theme: 'peertube-theme-unknown' } | ||
397 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) | ||
398 | }) | ||
399 | |||
390 | it('Should succeed to change password with the correct params', async function () { | 400 | it('Should succeed to change password with the correct params', async function () { |
391 | const fields = { | 401 | const fields = { |
392 | currentPassword: 'my super password', | 402 | currentPassword: 'my super password', |
393 | password: 'my super password', | 403 | password: 'my super password', |
394 | nsfwPolicy: 'blur', | 404 | nsfwPolicy: 'blur', |
395 | autoPlayVideo: false, | 405 | autoPlayVideo: false, |
396 | email: 'super_email@example.com' | 406 | email: 'super_email@example.com', |
407 | theme: 'default' | ||
397 | } | 408 | } |
398 | 409 | ||
399 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) | 410 | await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) |
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 94c15e0d0..3daeeb49a 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -11,3 +11,4 @@ import './reverse-proxy' | |||
11 | import './stats' | 11 | import './stats' |
12 | import './tracker' | 12 | import './tracker' |
13 | import './no-client' | 13 | import './no-client' |
14 | import './plugins' | ||
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts new file mode 100644 index 000000000..9a623c553 --- /dev/null +++ b/server/tests/api/server/plugins.ts | |||
@@ -0,0 +1,130 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { About } from '../../../../shared/models/server/about.model' | ||
6 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | ||
7 | import { | ||
8 | cleanupTests, | ||
9 | deleteCustomConfig, | ||
10 | flushAndRunServer, | ||
11 | getAbout, | ||
12 | getConfig, | ||
13 | getCustomConfig, installPlugin, | ||
14 | killallServers, parallelTests, | ||
15 | registerUser, | ||
16 | reRunServer, ServerInfo, | ||
17 | setAccessTokensToServers, | ||
18 | updateCustomConfig, uploadVideo | ||
19 | } from '../../../../shared/extra-utils' | ||
20 | import { ServerConfig } from '../../../../shared/models' | ||
21 | import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' | ||
22 | |||
23 | const expect = chai.expect | ||
24 | |||
25 | describe('Test plugins', function () { | ||
26 | let server = null | ||
27 | |||
28 | before(async function () { | ||
29 | this.timeout(30000) | ||
30 | |||
31 | server = await flushAndRunServer(1) | ||
32 | await setAccessTokensToServers([ server ]) | ||
33 | |||
34 | { | ||
35 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-hello-world' }) | ||
36 | } | ||
37 | |||
38 | { | ||
39 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-background-color' }) | ||
40 | } | ||
41 | }) | ||
42 | |||
43 | it('Should list available plugins and themes', async function () { | ||
44 | // List without filter | ||
45 | // List with filter (plugin and theme) | ||
46 | }) | ||
47 | |||
48 | it('Should search available plugins', async function () { | ||
49 | // Search with filter (plugin and theme) | ||
50 | // Add pagination | ||
51 | // Add sort | ||
52 | // Add peertube engine | ||
53 | }) | ||
54 | |||
55 | it('Should have an empty global css', async function () { | ||
56 | // get /global.css | ||
57 | }) | ||
58 | |||
59 | it('Should install a plugin and a theme', async function () { | ||
60 | |||
61 | }) | ||
62 | |||
63 | it('Should have the correct global css', async function () { | ||
64 | // get /global.css | ||
65 | }) | ||
66 | |||
67 | it('Should have the plugin loaded in the configuration', async function () { | ||
68 | // Check registered themes/plugins | ||
69 | }) | ||
70 | |||
71 | it('Should update the default theme in the configuration', async function () { | ||
72 | // Update config | ||
73 | }) | ||
74 | |||
75 | it('Should list plugins and themes', async function () { | ||
76 | // List without filter | ||
77 | // List with filter (theme/plugin) | ||
78 | // List with pagination | ||
79 | // List with sort | ||
80 | }) | ||
81 | |||
82 | it('Should get a plugin and a theme', async function () { | ||
83 | // Get plugin | ||
84 | // Get theme | ||
85 | }) | ||
86 | |||
87 | it('Should get registered settings', async function () { | ||
88 | // Get plugin | ||
89 | }) | ||
90 | |||
91 | it('Should update the settings', async function () { | ||
92 | // Update /settings | ||
93 | |||
94 | // get /plugin | ||
95 | }) | ||
96 | |||
97 | it('Should update the plugin and the theme', async function () { | ||
98 | // update BDD -> 0.0.1 | ||
99 | // update package.json (theme + plugin) | ||
100 | // list to check versions | ||
101 | // update plugin + theme | ||
102 | // list to check they have been updated | ||
103 | // check package.json are upgraded too | ||
104 | }) | ||
105 | |||
106 | it('Should uninstall the plugin', async function () { | ||
107 | // uninstall | ||
108 | // list | ||
109 | }) | ||
110 | |||
111 | it('Should have an empty global css', async function () { | ||
112 | // get /global.css | ||
113 | }) | ||
114 | |||
115 | it('Should list uninstalled plugins', async function () { | ||
116 | // { uninstalled: true } | ||
117 | }) | ||
118 | |||
119 | it('Should uninstall the theme', async function () { | ||
120 | // Uninstall | ||
121 | }) | ||
122 | |||
123 | it('Should have updated the configuration', async function () { | ||
124 | // get /config (default theme + registered themes + registered plugins) | ||
125 | }) | ||
126 | |||
127 | after(async function () { | ||
128 | await cleanupTests([ server ]) | ||
129 | }) | ||
130 | }) | ||
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6fc2a070f..3a3fabb4c 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -18,7 +18,7 @@ import { | |||
18 | getUsersList, | 18 | getUsersList, |
19 | getUsersListPaginationAndSort, | 19 | getUsersListPaginationAndSort, |
20 | getVideoChannel, | 20 | getVideoChannel, |
21 | getVideosList, | 21 | getVideosList, installPlugin, |
22 | login, | 22 | login, |
23 | makePutBodyRequest, | 23 | makePutBodyRequest, |
24 | rateVideo, | 24 | rateVideo, |
@@ -57,6 +57,8 @@ describe('Test users', function () { | |||
57 | server = await flushAndRunServer(1) | 57 | server = await flushAndRunServer(1) |
58 | 58 | ||
59 | await setAccessTokensToServers([ server ]) | 59 | await setAccessTokensToServers([ server ]) |
60 | |||
61 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | ||
60 | }) | 62 | }) |
61 | 63 | ||
62 | describe('OAuth client', function () { | 64 | describe('OAuth client', function () { |
@@ -551,6 +553,21 @@ describe('Test users', function () { | |||
551 | expect(user.account.displayName).to.equal('new display name') | 553 | expect(user.account.displayName).to.equal('new display name') |
552 | expect(user.account.description).to.equal('my super description updated') | 554 | expect(user.account.description).to.equal('my super description updated') |
553 | }) | 555 | }) |
556 | |||
557 | it('Should be able to update my theme', async function () { | ||
558 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | ||
559 | await updateMyUser({ | ||
560 | url: server.url, | ||
561 | accessToken: accessTokenUser, | ||
562 | theme | ||
563 | }) | ||
564 | |||
565 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
566 | const body: User = res.body | ||
567 | |||
568 | expect(body.theme).to.equal(theme) | ||
569 | } | ||
570 | }) | ||
554 | }) | 571 | }) |
555 | 572 | ||
556 | describe('Updating another user', function () { | 573 | describe('Updating another user', function () { |
diff --git a/server/tests/cli/index.ts b/server/tests/cli/index.ts index c6b7ec078..5af286fe2 100644 --- a/server/tests/cli/index.ts +++ b/server/tests/cli/index.ts | |||
@@ -3,5 +3,6 @@ import './create-import-video-file-job' | |||
3 | import './create-transcoding-job' | 3 | import './create-transcoding-job' |
4 | import './optimize-old-videos' | 4 | import './optimize-old-videos' |
5 | import './peertube' | 5 | import './peertube' |
6 | import './plugins' | ||
6 | import './reset-password' | 7 | import './reset-password' |
7 | import './update-host' | 8 | import './update-host' |
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index d73e27564..b8c0b1f79 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -43,133 +43,171 @@ describe('Test CLI wrapper', function () { | |||
43 | } | 43 | } |
44 | }) | 44 | }) |
45 | 45 | ||
46 | it('Should display no selected instance', async function () { | 46 | describe('Authentication and instance selection', function () { |
47 | this.timeout(60000) | ||
48 | 47 | ||
49 | const env = getEnvCli(server) | 48 | it('Should display no selected instance', async function () { |
50 | const stdout = await execCLI(`${env} ${cmd} --help`) | 49 | this.timeout(60000) |
51 | 50 | ||
52 | expect(stdout).to.contain('no instance selected') | 51 | const env = getEnvCli(server) |
53 | }) | 52 | const stdout = await execCLI(`${env} ${cmd} --help`) |
54 | 53 | ||
55 | it('Should add a user', async function () { | 54 | expect(stdout).to.contain('no instance selected') |
56 | this.timeout(60000) | 55 | }) |
57 | 56 | ||
58 | const env = getEnvCli(server) | 57 | it('Should add a user', async function () { |
59 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | 58 | this.timeout(60000) |
60 | }) | ||
61 | 59 | ||
62 | it('Should default to this user', async function () { | 60 | const env = getEnvCli(server) |
63 | this.timeout(60000) | 61 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) |
62 | }) | ||
64 | 63 | ||
65 | const env = getEnvCli(server) | 64 | it('Should default to this user', async function () { |
66 | const stdout = await execCLI(`${env} ${cmd} --help`) | 65 | this.timeout(60000) |
67 | 66 | ||
68 | expect(stdout).to.contain(`instance ${server.url} selected`) | 67 | const env = getEnvCli(server) |
69 | }) | 68 | const stdout = await execCLI(`${env} ${cmd} --help`) |
70 | 69 | ||
71 | it('Should remember the user', async function () { | 70 | expect(stdout).to.contain(`instance ${server.url} selected`) |
72 | this.timeout(60000) | 71 | }) |
73 | 72 | ||
74 | const env = getEnvCli(server) | 73 | it('Should remember the user', async function () { |
75 | const stdout = await execCLI(`${env} ${cmd} auth list`) | 74 | this.timeout(60000) |
76 | 75 | ||
77 | expect(stdout).to.contain(server.url) | 76 | const env = getEnvCli(server) |
77 | const stdout = await execCLI(`${env} ${cmd} auth list`) | ||
78 | |||
79 | expect(stdout).to.contain(server.url) | ||
80 | }) | ||
78 | }) | 81 | }) |
79 | 82 | ||
80 | it('Should upload a video', async function () { | 83 | describe('Video upload/import', function () { |
81 | this.timeout(60000) | ||
82 | 84 | ||
83 | const env = getEnvCli(server) | 85 | it('Should upload a video', async function () { |
86 | this.timeout(60000) | ||
84 | 87 | ||
85 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') | 88 | const env = getEnvCli(server) |
86 | 89 | ||
87 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` | 90 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') |
88 | 91 | ||
89 | await execCLI(`${env} ${cmd} upload ${params}`) | 92 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` |
90 | }) | ||
91 | 93 | ||
92 | it('Should have the video uploaded', async function () { | 94 | await execCLI(`${env} ${cmd} upload ${params}`) |
93 | const res = await getVideosList(server.url) | 95 | }) |
94 | 96 | ||
95 | expect(res.body.total).to.equal(1) | 97 | it('Should have the video uploaded', async function () { |
98 | const res = await getVideosList(server.url) | ||
96 | 99 | ||
97 | const videos: Video[] = res.body.data | 100 | expect(res.body.total).to.equal(1) |
98 | 101 | ||
99 | const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body | 102 | const videos: Video[] = res.body.data |
100 | 103 | ||
101 | expect(video.name).to.equal('test upload') | 104 | const video: VideoDetails = (await getVideo(server.url, videos[ 0 ].uuid)).body |
102 | expect(video.support).to.equal('support_text') | ||
103 | expect(video.channel.name).to.equal('user_channel') | ||
104 | }) | ||
105 | 105 | ||
106 | it('Should import a video', async function () { | 106 | expect(video.name).to.equal('test upload') |
107 | this.timeout(60000) | 107 | expect(video.support).to.equal('support_text') |
108 | expect(video.channel.name).to.equal('user_channel') | ||
109 | }) | ||
108 | 110 | ||
109 | const env = getEnvCli(server) | 111 | it('Should import a video', async function () { |
112 | this.timeout(60000) | ||
110 | 113 | ||
111 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` | 114 | const env = getEnvCli(server) |
112 | 115 | ||
113 | await execCLI(`${env} ${cmd} import ${params}`) | 116 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` |
114 | }) | ||
115 | 117 | ||
116 | it('Should have imported the video', async function () { | 118 | await execCLI(`${env} ${cmd} import ${params}`) |
117 | this.timeout(60000) | 119 | }) |
118 | 120 | ||
119 | await waitJobs([ server ]) | 121 | it('Should have imported the video', async function () { |
122 | this.timeout(60000) | ||
120 | 123 | ||
121 | const res = await getVideosList(server.url) | 124 | await waitJobs([ server ]) |
122 | 125 | ||
123 | expect(res.body.total).to.equal(2) | 126 | const res = await getVideosList(server.url) |
124 | 127 | ||
125 | const videos: Video[] = res.body.data | 128 | expect(res.body.total).to.equal(2) |
126 | const video = videos.find(v => v.name === 'small video - youtube') | ||
127 | expect(video).to.not.be.undefined | ||
128 | 129 | ||
129 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body | 130 | const videos: Video[] = res.body.data |
130 | expect(videoDetails.channel.name).to.equal('user_channel') | 131 | const video = videos.find(v => v.name === 'small video - youtube') |
131 | expect(videoDetails.support).to.equal('super support text') | 132 | expect(video).to.not.be.undefined |
132 | expect(videoDetails.nsfw).to.be.false | ||
133 | 133 | ||
134 | // So we can reimport it | 134 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body |
135 | await removeVideo(server.url, userAccessToken, video.id) | 135 | expect(videoDetails.channel.name).to.equal('user_channel') |
136 | }) | 136 | expect(videoDetails.support).to.equal('super support text') |
137 | expect(videoDetails.nsfw).to.be.false | ||
137 | 138 | ||
138 | it('Should import and override some imported attributes', async function () { | 139 | // So we can reimport it |
139 | this.timeout(60000) | 140 | await removeVideo(server.url, userAccessToken, video.id) |
141 | }) | ||
140 | 142 | ||
141 | const env = getEnvCli(server) | 143 | it('Should import and override some imported attributes', async function () { |
144 | this.timeout(60000) | ||
142 | 145 | ||
143 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` | 146 | const env = getEnvCli(server) |
144 | 147 | ||
145 | await execCLI(`${env} ${cmd} import ${params}`) | 148 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` |
146 | 149 | ||
147 | await waitJobs([ server ]) | 150 | await execCLI(`${env} ${cmd} import ${params}`) |
148 | 151 | ||
149 | { | 152 | await waitJobs([ server ]) |
150 | const res = await getVideosList(server.url) | ||
151 | expect(res.body.total).to.equal(2) | ||
152 | 153 | ||
153 | const videos: Video[] = res.body.data | 154 | { |
154 | const video = videos.find(v => v.name === 'toto') | 155 | const res = await getVideosList(server.url) |
155 | expect(video).to.not.be.undefined | 156 | expect(res.body.total).to.equal(2) |
156 | 157 | ||
157 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body | 158 | const videos: Video[] = res.body.data |
158 | expect(videoDetails.channel.name).to.equal('user_channel') | 159 | const video = videos.find(v => v.name === 'toto') |
159 | expect(videoDetails.support).to.equal('support') | 160 | expect(video).to.not.be.undefined |
160 | expect(videoDetails.nsfw).to.be.true | 161 | |
161 | expect(videoDetails.commentsEnabled).to.be.true | 162 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body |
162 | } | 163 | expect(videoDetails.channel.name).to.equal('user_channel') |
164 | expect(videoDetails.support).to.equal('support') | ||
165 | expect(videoDetails.nsfw).to.be.true | ||
166 | expect(videoDetails.commentsEnabled).to.be.true | ||
167 | } | ||
168 | }) | ||
163 | }) | 169 | }) |
164 | 170 | ||
165 | it('Should remove the auth user', async function () { | 171 | describe('Admin auth', function () { |
166 | const env = getEnvCli(server) | 172 | |
173 | it('Should remove the auth user', async function () { | ||
174 | const env = getEnvCli(server) | ||
175 | |||
176 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | ||
177 | |||
178 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
179 | |||
180 | expect(stdout).to.contain('no instance selected') | ||
181 | }) | ||
182 | |||
183 | it('Should add the admin user', async function () { | ||
184 | const env = getEnvCli(server) | ||
185 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) | ||
186 | }) | ||
187 | }) | ||
188 | |||
189 | describe('Manage plugins', function () { | ||
190 | |||
191 | it('Should install a plugin', async function () { | ||
192 | this.timeout(60000) | ||
193 | |||
194 | const env = getEnvCli(server) | ||
195 | await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`) | ||
196 | }) | ||
197 | |||
198 | it('Should list installed plugins', async function () { | ||
199 | const env = getEnvCli(server) | ||
200 | const res = await execCLI(`${env} ${cmd} plugins list`) | ||
167 | 201 | ||
168 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | 202 | expect(res).to.contain('peertube-plugin-hello-world') |
203 | }) | ||
169 | 204 | ||
170 | const stdout = await execCLI(`${env} ${cmd} --help`) | 205 | it('Should uninstall the plugin', async function () { |
206 | const env = getEnvCli(server) | ||
207 | const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
171 | 208 | ||
172 | expect(stdout).to.contain('no instance selected') | 209 | expect(res).to.not.contain('peertube-plugin-hello-world') |
210 | }) | ||
173 | }) | 211 | }) |
174 | 212 | ||
175 | after(async function () { | 213 | after(async function () { |
diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts new file mode 100644 index 000000000..d7bf8a690 --- /dev/null +++ b/server/tests/cli/plugins.ts | |||
@@ -0,0 +1,87 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | execCLI, | ||
7 | flushAndRunServer, | ||
8 | getConfig, | ||
9 | getEnvCli, killallServers, | ||
10 | reRunServer, | ||
11 | root, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers | ||
14 | } from '../../../shared/extra-utils' | ||
15 | import { join } from 'path' | ||
16 | import { ServerConfig } from '../../../shared/models/server' | ||
17 | import { expect } from 'chai' | ||
18 | |||
19 | describe('Test plugin scripts', function () { | ||
20 | let server: ServerInfo | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(30000) | ||
24 | |||
25 | server = await flushAndRunServer(1) | ||
26 | await setAccessTokensToServers([ server ]) | ||
27 | }) | ||
28 | |||
29 | it('Should install a plugin from stateless CLI', async function () { | ||
30 | this.timeout(60000) | ||
31 | |||
32 | const packagePath = join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test') | ||
33 | |||
34 | const env = getEnvCli(server) | ||
35 | await execCLI(`${env} npm run plugin:install -- --plugin-path ${packagePath}`) | ||
36 | }) | ||
37 | |||
38 | it('Should install a theme from stateless CLI', async function () { | ||
39 | this.timeout(60000) | ||
40 | |||
41 | const env = getEnvCli(server) | ||
42 | await execCLI(`${env} npm run plugin:install -- --npm-name peertube-theme-background-red`) | ||
43 | }) | ||
44 | |||
45 | it('Should have the theme and the plugin registered when we restart peertube', async function () { | ||
46 | this.timeout(30000) | ||
47 | |||
48 | killallServers([ server ]) | ||
49 | await reRunServer(server) | ||
50 | |||
51 | const res = await getConfig(server.url) | ||
52 | const config: ServerConfig = res.body | ||
53 | |||
54 | const plugin = config.plugin.registered | ||
55 | .find(p => p.name === 'test') | ||
56 | expect(plugin).to.not.be.undefined | ||
57 | |||
58 | const theme = config.theme.registered | ||
59 | .find(t => t.name === 'background-red') | ||
60 | expect(theme).to.not.be.undefined | ||
61 | }) | ||
62 | |||
63 | it('Should uninstall a plugin from stateless CLI', async function () { | ||
64 | this.timeout(60000) | ||
65 | |||
66 | const env = getEnvCli(server) | ||
67 | await execCLI(`${env} npm run plugin:uninstall -- --npm-name peertube-plugin-test`) | ||
68 | }) | ||
69 | |||
70 | it('Should have removed the plugin on another peertube restart', async function () { | ||
71 | this.timeout(30000) | ||
72 | |||
73 | killallServers([ server ]) | ||
74 | await reRunServer(server) | ||
75 | |||
76 | const res = await getConfig(server.url) | ||
77 | const config: ServerConfig = res.body | ||
78 | |||
79 | const plugin = config.plugin.registered | ||
80 | .find(p => p.name === 'test') | ||
81 | expect(plugin).to.be.undefined | ||
82 | }) | ||
83 | |||
84 | after(async function () { | ||
85 | await cleanupTests([ server ]) | ||
86 | }) | ||
87 | }) | ||
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js new file mode 100644 index 000000000..fae0ef948 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -0,0 +1,39 @@ | |||
1 | async function register ({ registerHook, registerSetting, settingsManager, storageManager }) { | ||
2 | const defaultAdmin = 'PeerTube admin' | ||
3 | |||
4 | registerHook({ | ||
5 | target: 'action:application.listening', | ||
6 | handler: () => displayHelloWorld(settingsManager, defaultAdmin) | ||
7 | }) | ||
8 | |||
9 | registerSetting({ | ||
10 | name: 'admin-name', | ||
11 | label: 'Admin name', | ||
12 | type: 'input', | ||
13 | default: defaultAdmin | ||
14 | }) | ||
15 | |||
16 | const value = await storageManager.getData('toto') | ||
17 | console.log(value) | ||
18 | console.log(value.coucou) | ||
19 | |||
20 | await storageManager.storeData('toto', { coucou: 'hello' + new Date() }) | ||
21 | } | ||
22 | |||
23 | async function unregister () { | ||
24 | return | ||
25 | } | ||
26 | |||
27 | module.exports = { | ||
28 | register, | ||
29 | unregister | ||
30 | } | ||
31 | |||
32 | // ############################################################################ | ||
33 | |||
34 | async function displayHelloWorld (settingsManager, defaultAdmin) { | ||
35 | let value = await settingsManager.getSetting('admin-name') | ||
36 | if (!value) value = defaultAdmin | ||
37 | |||
38 | console.log('hello world ' + value) | ||
39 | } | ||
diff --git a/server/tests/fixtures/peertube-plugin-test/package.json b/server/tests/fixtures/peertube-plugin-test/package.json new file mode 100644 index 000000000..9d6fe5c90 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test/package.json | |||
@@ -0,0 +1,19 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Plugin test", | ||
5 | "engine": { | ||
6 | "peertube": ">=1.3.0" | ||
7 | }, | ||
8 | "keywords": [ | ||
9 | "peertube", | ||
10 | "plugin" | ||
11 | ], | ||
12 | "homepage": "https://github.com/Chocobozzz/PeerTube", | ||
13 | "author": "Chocobozzz", | ||
14 | "bugs": "https://github.com/Chocobozzz/PeerTube/issues", | ||
15 | "library": "./main.js", | ||
16 | "staticDirs": {}, | ||
17 | "css": [], | ||
18 | "clientScripts": [] | ||
19 | } | ||
diff --git a/server/tests/index.ts b/server/tests/index.ts index ed16d65dd..8bddcfc7c 100644 --- a/server/tests/index.ts +++ b/server/tests/index.ts | |||
@@ -3,3 +3,4 @@ import './client' | |||
3 | import './feeds/' | 3 | import './feeds/' |
4 | import './cli/' | 4 | import './cli/' |
5 | import './api/' | 5 | import './api/' |
6 | import './plugins/' | ||
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts new file mode 100644 index 000000000..8abab98c2 --- /dev/null +++ b/server/tests/plugins/action-hooks.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | ||
6 | import { setAccessTokensToServers } from '../../../shared/extra-utils' | ||
7 | |||
8 | const expect = chai.expect | ||
9 | |||
10 | describe('Test plugin filter hooks', function () { | ||
11 | let server: ServerInfo | ||
12 | |||
13 | before(async function () { | ||
14 | this.timeout(30000) | ||
15 | server = await flushAndRunServer(1) | ||
16 | |||
17 | await setAccessTokensToServers([ server ]) | ||
18 | }) | ||
19 | |||
20 | it('Should execute ', async function () { | ||
21 | |||
22 | }) | ||
23 | |||
24 | after(async function () { | ||
25 | await cleanupTests([ server ]) | ||
26 | }) | ||
27 | }) | ||
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts new file mode 100644 index 000000000..8abab98c2 --- /dev/null +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -0,0 +1,27 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | ||
6 | import { setAccessTokensToServers } from '../../../shared/extra-utils' | ||
7 | |||
8 | const expect = chai.expect | ||
9 | |||
10 | describe('Test plugin filter hooks', function () { | ||
11 | let server: ServerInfo | ||
12 | |||
13 | before(async function () { | ||
14 | this.timeout(30000) | ||
15 | server = await flushAndRunServer(1) | ||
16 | |||
17 | await setAccessTokensToServers([ server ]) | ||
18 | }) | ||
19 | |||
20 | it('Should execute ', async function () { | ||
21 | |||
22 | }) | ||
23 | |||
24 | after(async function () { | ||
25 | await cleanupTests([ server ]) | ||
26 | }) | ||
27 | }) | ||
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts new file mode 100644 index 000000000..b640ecc9e --- /dev/null +++ b/server/tests/plugins/index.ts | |||
@@ -0,0 +1,2 @@ | |||
1 | export * from './action-hooks' | ||
2 | export * from './filter-hooks' | ||