]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import {
6 addVideoChannel,
7 buildAbsoluteFixturePath,
8 cleanupTests,
9 createUser,
10 execCLI,
11 flushAndRunServer,
12 getEnvCli,
13 getVideo,
14 getVideosList,
15 getVideosListWithToken, removeVideo,
16 ServerInfo,
17 setAccessTokensToServers,
18 userLogin,
19 waitJobs
20 } from '../../../shared/extra-utils'
21 import { Video, VideoDetails } from '../../../shared'
22 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
23
24 describe('Test CLI wrapper', function () {
25 let server: ServerInfo
26 let userAccessToken: string
27
28 const cmd = 'node ./dist/server/tools/peertube.js'
29
30 before(async function () {
31 this.timeout(30000)
32
33 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
35
36 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
37
38 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
39
40 {
41 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
42 await addVideoChannel(server.url, userAccessToken, args)
43 }
44 })
45
46 it('Should display no selected instance', async function () {
47 this.timeout(60000)
48
49 const env = getEnvCli(server)
50 const stdout = await execCLI(`${env} ${cmd} --help`)
51
52 expect(stdout).to.contain('no instance selected')
53 })
54
55 it('Should add a user', async function () {
56 this.timeout(60000)
57
58 const env = getEnvCli(server)
59 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
60 })
61
62 it('Should default to this user', async function () {
63 this.timeout(60000)
64
65 const env = getEnvCli(server)
66 const stdout = await execCLI(`${env} ${cmd} --help`)
67
68 expect(stdout).to.contain(`instance ${server.url} selected`)
69 })
70
71 it('Should remember the user', async function () {
72 this.timeout(60000)
73
74 const env = getEnvCli(server)
75 const stdout = await execCLI(`${env} ${cmd} auth list`)
76
77 expect(stdout).to.contain(server.url)
78 })
79
80 it('Should upload a video', async function () {
81 this.timeout(60000)
82
83 const env = getEnvCli(server)
84
85 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
86
87 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
88
89 await execCLI(`${env} ${cmd} upload ${params}`)
90 })
91
92 it('Should have the video uploaded', async function () {
93 const res = await getVideosList(server.url)
94
95 expect(res.body.total).to.equal(1)
96
97 const videos: Video[] = res.body.data
98
99 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
100
101 expect(video.name).to.equal('test upload')
102 expect(video.support).to.equal('support_text')
103 expect(video.channel.name).to.equal('user_channel')
104 })
105
106 it('Should import a video', async function () {
107 this.timeout(60000)
108
109 const env = getEnvCli(server)
110
111 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
112
113 await execCLI(`${env} ${cmd} import ${params}`)
114 })
115
116 it('Should have imported the video', async function () {
117 this.timeout(60000)
118
119 await waitJobs([ server ])
120
121 const res = await getVideosList(server.url)
122
123 expect(res.body.total).to.equal(2)
124
125 const videos: Video[] = res.body.data
126 const video = videos.find(v => v.name === 'small video - youtube')
127 expect(video).to.not.be.undefined
128
129 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
130 expect(videoDetails.channel.name).to.equal('user_channel')
131 expect(videoDetails.support).to.equal('super support text')
132 expect(videoDetails.nsfw).to.be.false
133
134 // So we can reimport it
135 await removeVideo(server.url, userAccessToken, video.id)
136 })
137
138 it('Should import and override some imported attributes', async function () {
139 this.timeout(60000)
140
141 const env = getEnvCli(server)
142
143 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
144
145 await execCLI(`${env} ${cmd} import ${params}`)
146
147 await waitJobs([ server ])
148
149 {
150 const res = await getVideosList(server.url)
151 expect(res.body.total).to.equal(2)
152
153 const videos: Video[] = res.body.data
154 const video = videos.find(v => v.name === 'toto')
155 expect(video).to.not.be.undefined
156
157 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
158 expect(videoDetails.channel.name).to.equal('user_channel')
159 expect(videoDetails.support).to.equal('support')
160 expect(videoDetails.nsfw).to.be.true
161 expect(videoDetails.commentsEnabled).to.be.true
162 }
163 })
164
165 it('Should remove the auth user', async function () {
166 const env = getEnvCli(server)
167
168 await execCLI(`${env} ${cmd} auth del ${server.url}`)
169
170 const stdout = await execCLI(`${env} ${cmd} --help`)
171
172 expect(stdout).to.contain('no instance selected')
173 })
174
175 after(async function () {
176 this.timeout(10000)
177
178 await cleanupTests([ server ])
179 })
180 })