]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/peertube.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
1a12f66d 2
8704acf4 3import 'mocha'
1a12f66d 4import { expect } from 'chai'
8704acf4 5import {
5c0ecc34 6 areHttpImportTestsDisabled,
1a12f66d
C
7 buildAbsoluteFixturePath,
8 cleanupTests,
329619b3 9 CLICommand,
a1587156 10 doubleFollow,
254d3579 11 createSingleServer,
6910f20f 12 ImportsCommand,
254d3579 13 PeerTubeServer,
a1587156 14 setAccessTokensToServers,
353f8bc0 15 testHelloWorldRegisteredSettings,
1205823f 16 waitJobs
94565d52 17} from '../../../shared/extra-utils'
8704acf4
RK
18
19describe('Test CLI wrapper', function () {
254d3579 20 let server: PeerTubeServer
1205823f 21 let userAccessToken: string
1a12f66d 22
329619b3
C
23 let cliCommand: CLICommand
24
8704acf4
RK
25 const cmd = 'node ./dist/server/tools/peertube.js'
26
27 before(async function () {
28 this.timeout(30000)
1a12f66d 29
254d3579 30 server = await createSingleServer(1)
8704acf4
RK
31 await setAccessTokensToServers([ server ])
32
89d241a7 33 await server.users.create({ username: 'user_1', password: 'super_password' })
1a12f66d 34
89d241a7 35 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
1a12f66d
C
36
37 {
a5461888 38 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
89d241a7 39 await server.channels.create({ token: userAccessToken, attributes })
1a12f66d 40 }
329619b3 41
89d241a7 42 cliCommand = server.cli
8704acf4
RK
43 })
44
9b474844 45 describe('Authentication and instance selection', function () {
8704acf4 46
078f17e6
C
47 it('Should get an access token', async function () {
48 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
49 const token = stdout.trim()
50
89d241a7 51 const body = await server.users.getMyInfo({ token })
7926c5f9 52 expect(body.username).to.equal('user_1')
078f17e6
C
53 })
54
9b474844
C
55 it('Should display no selected instance', async function () {
56 this.timeout(60000)
8704acf4 57
329619b3 58 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
9b474844
C
59 expect(stdout).to.contain('no instance selected')
60 })
1a12f66d 61
9b474844
C
62 it('Should add a user', async function () {
63 this.timeout(60000)
1a12f66d 64
329619b3 65 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
9b474844 66 })
1a12f66d 67
8e76aa1d
TS
68 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
69 this.timeout(60000)
70
329619b3
C
71 let fullServerURL = server.url + '/'
72
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
8e76aa1d
TS
74
75 fullServerURL = server.url + '/asdfasdf'
329619b3 76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
8e76aa1d
TS
77 })
78
9b474844
C
79 it('Should default to this user', async function () {
80 this.timeout(60000)
1a12f66d 81
329619b3 82 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
9b474844
C
83 expect(stdout).to.contain(`instance ${server.url} selected`)
84 })
1a12f66d 85
9b474844
C
86 it('Should remember the user', async function () {
87 this.timeout(60000)
1a12f66d 88
329619b3 89 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
9b474844
C
90 expect(stdout).to.contain(server.url)
91 })
1a12f66d
C
92 })
93
9b474844 94 describe('Video upload/import', function () {
1a12f66d 95
9b474844
C
96 it('Should upload a video', async function () {
97 this.timeout(60000)
1a12f66d 98
9b474844 99 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
9b474844 100 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
1a12f66d 101
329619b3 102 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
9b474844 103 })
1a12f66d 104
9b474844 105 it('Should have the video uploaded', async function () {
89d241a7 106 const { total, data } = await server.videos.list()
d23dd9fb 107 expect(total).to.equal(1)
1a12f66d 108
89d241a7 109 const video = await server.videos.get({ id: data[0].uuid })
9b474844
C
110 expect(video.name).to.equal('test upload')
111 expect(video.support).to.equal('support_text')
112 expect(video.channel.name).to.equal('user_channel')
113 })
1a12f66d 114
9b474844 115 it('Should import a video', async function () {
5c0ecc34
C
116 if (areHttpImportTestsDisabled()) return
117
9b474844 118 this.timeout(60000)
1a12f66d 119
6910f20f 120 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
329619b3 121 await cliCommand.execWithEnv(`${cmd} import ${params}`)
9b474844 122 })
8704acf4 123
9b474844 124 it('Should have imported the video', async function () {
5c0ecc34
C
125 if (areHttpImportTestsDisabled()) return
126
9b474844 127 this.timeout(60000)
1a12f66d 128
9b474844 129 await waitJobs([ server ])
1a12f66d 130
89d241a7 131 const { total, data } = await server.videos.list()
d23dd9fb 132 expect(total).to.equal(2)
1205823f 133
d23dd9fb 134 const video = data.find(v => v.name === 'small video - youtube')
9b474844 135 expect(video).to.not.be.undefined
1205823f 136
89d241a7 137 const videoDetails = await server.videos.get({ id: video.id })
9b474844
C
138 expect(videoDetails.channel.name).to.equal('user_channel')
139 expect(videoDetails.support).to.equal('super support text')
140 expect(videoDetails.nsfw).to.be.false
1205823f 141
9b474844 142 // So we can reimport it
89d241a7 143 await server.videos.remove({ token: userAccessToken, id: video.id })
9b474844 144 })
1205823f 145
9b474844 146 it('Should import and override some imported attributes', async function () {
5c0ecc34
C
147 if (areHttpImportTestsDisabled()) return
148
9b474844 149 this.timeout(60000)
1205823f 150
6910f20f
C
151 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
152 `--channel-name user_channel --video-name toto --nsfw --support support`
329619b3 153 await cliCommand.execWithEnv(`${cmd} import ${params}`)
1205823f 154
9b474844 155 await waitJobs([ server ])
1205823f 156
9b474844 157 {
89d241a7 158 const { total, data } = await server.videos.list()
d23dd9fb 159 expect(total).to.equal(2)
1205823f 160
d23dd9fb 161 const video = data.find(v => v.name === 'toto')
9b474844
C
162 expect(video).to.not.be.undefined
163
89d241a7 164 const videoDetails = await server.videos.get({ id: video.id })
9b474844
C
165 expect(videoDetails.channel.name).to.equal('user_channel')
166 expect(videoDetails.support).to.equal('support')
167 expect(videoDetails.nsfw).to.be.true
168 expect(videoDetails.commentsEnabled).to.be.true
169 }
170 })
1a12f66d
C
171 })
172
9b474844
C
173 describe('Admin auth', function () {
174
175 it('Should remove the auth user', async function () {
329619b3 176 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
9b474844 177
329619b3 178 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
9b474844
C
179 expect(stdout).to.contain('no instance selected')
180 })
181
182 it('Should add the admin user', async function () {
329619b3 183 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
9b474844
C
184 })
185 })
186
187 describe('Manage plugins', function () {
188
189 it('Should install a plugin', async function () {
190 this.timeout(60000)
191
329619b3 192 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
9b474844
C
193 })
194
353f8bc0
C
195 it('Should have registered settings', async function () {
196 await testHelloWorldRegisteredSettings(server)
197 })
198
9b474844 199 it('Should list installed plugins', async function () {
329619b3 200 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
1a12f66d 201
9b474844
C
202 expect(res).to.contain('peertube-plugin-hello-world')
203 })
1a12f66d 204
9b474844 205 it('Should uninstall the plugin', async function () {
329619b3 206 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
1a12f66d 207
9b474844
C
208 expect(res).to.not.contain('peertube-plugin-hello-world')
209 })
8704acf4
RK
210 })
211
26fcf2ef 212 describe('Manage video redundancies', function () {
254d3579 213 let anotherServer: PeerTubeServer
26fcf2ef 214 let video1Server2: number
254d3579 215 let servers: PeerTubeServer[]
26fcf2ef
C
216
217 before(async function () {
218 this.timeout(120000)
219
254d3579 220 anotherServer = await createSingleServer(2)
26fcf2ef
C
221 await setAccessTokensToServers([ anotherServer ])
222
223 await doubleFollow(server, anotherServer)
224
225 servers = [ server, anotherServer ]
226 await waitJobs(servers)
227
89d241a7 228 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
26fcf2ef
C
229 await waitJobs(servers)
230
89d241a7 231 video1Server2 = await server.videos.getId({ uuid })
26fcf2ef
C
232 })
233
234 it('Should add a redundancy', async function () {
235 this.timeout(60000)
236
26fcf2ef 237 const params = `add --video ${video1Server2}`
329619b3 238 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
26fcf2ef
C
239
240 await waitJobs(servers)
241 })
242
243 it('Should list redundancies', async function () {
244 this.timeout(60000)
245
246 {
a1587156 247 const params = 'list-my-redundancies'
329619b3 248 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
26fcf2ef
C
249
250 expect(stdout).to.contain('super video')
251 expect(stdout).to.contain(`localhost:${server.port}`)
252 }
253 })
254
255 it('Should remove a redundancy', async function () {
256 this.timeout(60000)
257
26fcf2ef 258 const params = `remove --video ${video1Server2}`
329619b3 259 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
26fcf2ef
C
260
261 await waitJobs(servers)
262
263 {
a1587156 264 const params = 'list-my-redundancies'
329619b3 265 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
26fcf2ef
C
266
267 expect(stdout).to.not.contain('super video')
268 }
269 })
e669ff58
C
270
271 after(async function () {
272 this.timeout(10000)
273
274 await cleanupTests([ anotherServer ])
275 })
26fcf2ef
C
276 })
277
8704acf4 278 after(async function () {
e5cb43e0
C
279 this.timeout(10000)
280
7c3b7976 281 await cleanupTests([ server ])
8704acf4
RK
282 })
283})