aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-19 10:37:35 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit9b474844e85cce916370693cc24f53339a695570 (patch)
tree10b1148a7581a2754e336a144c085a05ce72a1db /server/tests/cli
parent32fe00138990627749da58ff9f845584013aa219 (diff)
downloadPeerTube-9b474844e85cce916370693cc24f53339a695570.tar.gz
PeerTube-9b474844e85cce916370693cc24f53339a695570.tar.zst
PeerTube-9b474844e85cce916370693cc24f53339a695570.zip
Add CLI plugins tests
Diffstat (limited to 'server/tests/cli')
-rw-r--r--server/tests/cli/index.ts1
-rw-r--r--server/tests/cli/peertube.ts202
-rw-r--r--server/tests/cli/plugins.ts87
3 files changed, 208 insertions, 82 deletions
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'
3import './create-transcoding-job' 3import './create-transcoding-job'
4import './optimize-old-videos' 4import './optimize-old-videos'
5import './peertube' 5import './peertube'
6import './plugins'
6import './reset-password' 7import './reset-password'
7import './update-host' 8import './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
3import 'mocha'
4import {
5 cleanupTests,
6 execCLI,
7 flushAndRunServer,
8 getConfig,
9 getEnvCli, killallServers,
10 reRunServer,
11 root,
12 ServerInfo,
13 setAccessTokensToServers
14} from '../../../shared/extra-utils'
15import { join } from 'path'
16import { ServerConfig } from '../../../shared/models/server'
17import { expect } from 'chai'
18
19describe('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})