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