]>
Commit | Line | Data |
---|---|---|
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 | describe('Authentication and instance selection', function () { | |
47 | ||
48 | it('Should display no selected instance', async function () { | |
49 | this.timeout(60000) | |
50 | ||
51 | const env = getEnvCli(server) | |
52 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
53 | ||
54 | expect(stdout).to.contain('no instance selected') | |
55 | }) | |
56 | ||
57 | it('Should add a user', async function () { | |
58 | this.timeout(60000) | |
59 | ||
60 | const env = getEnvCli(server) | |
61 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | |
62 | }) | |
63 | ||
64 | it('Should default to this user', async function () { | |
65 | this.timeout(60000) | |
66 | ||
67 | const env = getEnvCli(server) | |
68 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
69 | ||
70 | expect(stdout).to.contain(`instance ${server.url} selected`) | |
71 | }) | |
72 | ||
73 | it('Should remember the user', async function () { | |
74 | this.timeout(60000) | |
75 | ||
76 | const env = getEnvCli(server) | |
77 | const stdout = await execCLI(`${env} ${cmd} auth list`) | |
78 | ||
79 | expect(stdout).to.contain(server.url) | |
80 | }) | |
81 | }) | |
82 | ||
83 | describe('Video upload/import', function () { | |
84 | ||
85 | it('Should upload a video', async function () { | |
86 | this.timeout(60000) | |
87 | ||
88 | const env = getEnvCli(server) | |
89 | ||
90 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') | |
91 | ||
92 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` | |
93 | ||
94 | await execCLI(`${env} ${cmd} upload ${params}`) | |
95 | }) | |
96 | ||
97 | it('Should have the video uploaded', async function () { | |
98 | const res = await getVideosList(server.url) | |
99 | ||
100 | expect(res.body.total).to.equal(1) | |
101 | ||
102 | const videos: Video[] = res.body.data | |
103 | ||
104 | const video: VideoDetails = (await getVideo(server.url, videos[ 0 ].uuid)).body | |
105 | ||
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 | }) | |
110 | ||
111 | it('Should import a video', async function () { | |
112 | this.timeout(60000) | |
113 | ||
114 | const env = getEnvCli(server) | |
115 | ||
116 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` | |
117 | ||
118 | await execCLI(`${env} ${cmd} import ${params}`) | |
119 | }) | |
120 | ||
121 | it('Should have imported the video', async function () { | |
122 | this.timeout(60000) | |
123 | ||
124 | await waitJobs([ server ]) | |
125 | ||
126 | const res = await getVideosList(server.url) | |
127 | ||
128 | expect(res.body.total).to.equal(2) | |
129 | ||
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 | |
133 | ||
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 | |
138 | ||
139 | // So we can reimport it | |
140 | await removeVideo(server.url, userAccessToken, video.id) | |
141 | }) | |
142 | ||
143 | it('Should import and override some imported attributes', async function () { | |
144 | this.timeout(60000) | |
145 | ||
146 | const env = getEnvCli(server) | |
147 | ||
148 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` | |
149 | ||
150 | await execCLI(`${env} ${cmd} import ${params}`) | |
151 | ||
152 | await waitJobs([ server ]) | |
153 | ||
154 | { | |
155 | const res = await getVideosList(server.url) | |
156 | expect(res.body.total).to.equal(2) | |
157 | ||
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 | }) | |
169 | }) | |
170 | ||
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`) | |
201 | ||
202 | expect(res).to.contain('peertube-plugin-hello-world') | |
203 | }) | |
204 | ||
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`) | |
208 | ||
209 | expect(res).to.not.contain('peertube-plugin-hello-world') | |
210 | }) | |
211 | }) | |
212 | ||
213 | after(async function () { | |
214 | this.timeout(10000) | |
215 | ||
216 | await cleanupTests([ server ]) | |
217 | }) | |
218 | }) |