]>
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 | ||
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 | ||
1a12f66d C |
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 | ||
1205823f | 87 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` |
1a12f66d C |
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 | |
1205823f C |
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') | |
1a12f66d C |
104 | }) |
105 | ||
106 | it('Should import a video', async function () { | |
107 | this.timeout(60000) | |
108 | ||
109 | const env = getEnvCli(server) | |
110 | ||
1205823f | 111 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` |
1a12f66d C |
112 | |
113 | await execCLI(`${env} ${cmd} import ${params}`) | |
8704acf4 RK |
114 | }) |
115 | ||
1a12f66d | 116 | it('Should have imported the video', async function () { |
8704acf4 RK |
117 | this.timeout(60000) |
118 | ||
1a12f66d C |
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') | |
1a12f66d | 127 | expect(video).to.not.be.undefined |
1205823f C |
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 | } | |
1a12f66d C |
162 | }) |
163 | ||
164 | it('Should remove the auth user', async function () { | |
8704acf4 | 165 | const env = getEnvCli(server) |
1a12f66d C |
166 | |
167 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | |
168 | ||
169 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
170 | ||
171 | expect(stdout).to.contain('no instance selected') | |
8704acf4 RK |
172 | }) |
173 | ||
174 | after(async function () { | |
e5cb43e0 C |
175 | this.timeout(10000) |
176 | ||
7c3b7976 | 177 | await cleanupTests([ server ]) |
8704acf4 RK |
178 | }) |
179 | }) |