]>
Commit | Line | Data |
---|---|---|
5d08a6a7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import { omit } from 'lodash' | |
4 | import 'mocha' | |
5 | import { join } from 'path' | |
6 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | |
7 | import { | |
8 | createUser, | |
9 | flushTests, | |
10 | getMyUserInformation, | |
11 | immutableAssign, | |
12 | killallServers, | |
13 | makeGetRequest, | |
14 | makePostBodyRequest, | |
15 | makeUploadRequest, | |
16 | runServer, | |
17 | ServerInfo, | |
18 | setAccessTokensToServers, | |
590fb506 | 19 | updateCustomSubConfig, |
5d08a6a7 C |
20 | userLogin |
21 | } from '../../utils' | |
22 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | |
187501f8 | 23 | import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports' |
5d08a6a7 C |
24 | |
25 | describe('Test video imports API validator', function () { | |
26 | const path = '/api/v1/videos/imports' | |
27 | let server: ServerInfo | |
28 | let userAccessToken = '' | |
29 | let accountName: string | |
30 | let channelId: number | |
5d08a6a7 C |
31 | |
32 | // --------------------------------------------------------------- | |
33 | ||
34 | before(async function () { | |
35 | this.timeout(30000) | |
36 | ||
37 | await flushTests() | |
38 | ||
39 | server = await runServer(1) | |
40 | ||
41 | await setAccessTokensToServers([ server ]) | |
42 | ||
43 | const username = 'user1' | |
44 | const password = 'my super password' | |
45 | await createUser(server.url, server.accessToken, username, password) | |
46 | userAccessToken = await userLogin(server, { username, password }) | |
47 | ||
48 | { | |
49 | const res = await getMyUserInformation(server.url, server.accessToken) | |
50 | channelId = res.body.videoChannels[ 0 ].id | |
5d08a6a7 C |
51 | accountName = res.body.account.name + '@' + res.body.account.host |
52 | } | |
53 | }) | |
54 | ||
55 | describe('When listing my video imports', function () { | |
56 | const myPath = '/api/v1/users/me/videos/imports' | |
57 | ||
58 | it('Should fail with a bad start pagination', async function () { | |
59 | await checkBadStartPagination(server.url, myPath, server.accessToken) | |
60 | }) | |
61 | ||
62 | it('Should fail with a bad count pagination', async function () { | |
63 | await checkBadCountPagination(server.url, myPath, server.accessToken) | |
64 | }) | |
65 | ||
66 | it('Should fail with an incorrect sort', async function () { | |
67 | await checkBadSortPagination(server.url, myPath, server.accessToken) | |
68 | }) | |
69 | ||
70 | it('Should success with the correct parameters', async function () { | |
71 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) | |
72 | }) | |
73 | }) | |
74 | ||
75 | describe('When adding a video import', function () { | |
76 | let baseCorrectParams | |
77 | ||
78 | before(function () { | |
79 | baseCorrectParams = { | |
590fb506 | 80 | targetUrl: getYoutubeVideoUrl(), |
5d08a6a7 C |
81 | name: 'my super name', |
82 | category: 5, | |
83 | licence: 1, | |
84 | language: 'pt', | |
85 | nsfw: false, | |
86 | commentsEnabled: true, | |
7f2cfe3a | 87 | downloadEnabled: true, |
5d08a6a7 C |
88 | waitTranscoding: true, |
89 | description: 'my super description', | |
90 | support: 'my super support text', | |
91 | tags: [ 'tag1', 'tag2' ], | |
92 | privacy: VideoPrivacy.PUBLIC, | |
93 | channelId: channelId | |
94 | } | |
95 | }) | |
96 | ||
97 | it('Should fail with nothing', async function () { | |
98 | const fields = {} | |
99 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
100 | }) | |
101 | ||
590fb506 C |
102 | it('Should fail without a target url', async function () { |
103 | const fields = omit(baseCorrectParams, 'targetUrl') | |
104 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) | |
105 | }) | |
106 | ||
107 | it('Should fail with a bad target url', async function () { | |
108 | const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) | |
109 | ||
110 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
111 | }) | |
112 | ||
5d08a6a7 C |
113 | it('Should fail with a long name', async function () { |
114 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | |
115 | ||
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
117 | }) | |
118 | ||
119 | it('Should fail with a bad category', async function () { | |
120 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | |
121 | ||
122 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
123 | }) | |
124 | ||
125 | it('Should fail with a bad licence', async function () { | |
126 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | |
127 | ||
128 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
129 | }) | |
130 | ||
131 | it('Should fail with a bad language', async function () { | |
132 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | |
133 | ||
134 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
135 | }) | |
136 | ||
137 | it('Should fail with a long description', async function () { | |
138 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | |
139 | ||
140 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
141 | }) | |
142 | ||
143 | it('Should fail with a long support text', async function () { | |
144 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) | |
145 | ||
146 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
147 | }) | |
148 | ||
149 | it('Should fail without a channel', async function () { | |
150 | const fields = omit(baseCorrectParams, 'channelId') | |
151 | ||
152 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
153 | }) | |
154 | ||
155 | it('Should fail with a bad channel', async function () { | |
156 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
157 | ||
158 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
159 | }) | |
160 | ||
161 | it('Should fail with another user channel', async function () { | |
162 | const user = { | |
163 | username: 'fake', | |
164 | password: 'fake_password' | |
165 | } | |
166 | await createUser(server.url, server.accessToken, user.username, user.password) | |
167 | ||
168 | const accessTokenUser = await userLogin(server, user) | |
169 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
170 | const customChannelId = res.body.videoChannels[0].id | |
171 | ||
172 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | |
173 | ||
174 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | |
175 | }) | |
176 | ||
177 | it('Should fail with too many tags', async function () { | |
178 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | |
179 | ||
180 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
181 | }) | |
182 | ||
183 | it('Should fail with a tag length too low', async function () { | |
184 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | |
185 | ||
186 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
187 | }) | |
188 | ||
189 | it('Should fail with a tag length too big', async function () { | |
190 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | |
191 | ||
192 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
193 | }) | |
194 | ||
195 | it('Should fail with an incorrect thumbnail file', async function () { | |
196 | const fields = baseCorrectParams | |
197 | const attaches = { | |
198 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
199 | } | |
200 | ||
201 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
202 | }) | |
203 | ||
204 | it('Should fail with a big thumbnail file', async function () { | |
205 | const fields = baseCorrectParams | |
206 | const attaches = { | |
207 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
208 | } | |
209 | ||
210 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
211 | }) | |
212 | ||
213 | it('Should fail with an incorrect preview file', async function () { | |
214 | const fields = baseCorrectParams | |
215 | const attaches = { | |
216 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | |
217 | } | |
218 | ||
219 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
220 | }) | |
221 | ||
222 | it('Should fail with a big preview file', async function () { | |
223 | const fields = baseCorrectParams | |
224 | const attaches = { | |
225 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
226 | } | |
227 | ||
228 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
229 | }) | |
230 | ||
187501f8 C |
231 | it('Should fail with an invalid torrent file', async function () { |
232 | const fields = omit(baseCorrectParams, 'targetUrl') | |
233 | const attaches = { | |
234 | 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | |
235 | } | |
236 | ||
237 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | |
238 | }) | |
239 | ||
240 | it('Should fail with an invalid magnet URI', async function () { | |
241 | let fields = omit(baseCorrectParams, 'targetUrl') | |
242 | fields = immutableAssign(fields, { magnetUri: 'blabla' }) | |
243 | ||
244 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
245 | }) | |
246 | ||
5d08a6a7 | 247 | it('Should succeed with the correct parameters', async function () { |
13b6dc1f | 248 | this.timeout(30000) |
5d08a6a7 | 249 | |
5d08a6a7 C |
250 | { |
251 | await makePostBodyRequest({ | |
252 | url: server.url, | |
253 | path, | |
254 | token: server.accessToken, | |
590fb506 | 255 | fields: baseCorrectParams, |
5d08a6a7 C |
256 | statusCodeExpected: 200 |
257 | }) | |
258 | } | |
259 | }) | |
260 | ||
187501f8 | 261 | it('Should forbid to import http videos', async function () { |
590fb506 C |
262 | await updateCustomSubConfig(server.url, server.accessToken, { |
263 | import: { | |
264 | videos: { | |
265 | http: { | |
266 | enabled: false | |
187501f8 C |
267 | }, |
268 | torrent: { | |
269 | enabled: true | |
590fb506 C |
270 | } |
271 | } | |
272 | } | |
273 | }) | |
274 | ||
275 | await makePostBodyRequest({ | |
276 | url: server.url, | |
277 | path, | |
278 | token: server.accessToken, | |
279 | fields: baseCorrectParams, | |
280 | statusCodeExpected: 409 | |
281 | }) | |
282 | }) | |
187501f8 C |
283 | |
284 | it('Should forbid to import torrent videos', async function () { | |
285 | await updateCustomSubConfig(server.url, server.accessToken, { | |
286 | import: { | |
287 | videos: { | |
288 | http: { | |
289 | enabled: true | |
290 | }, | |
291 | torrent: { | |
292 | enabled: false | |
293 | } | |
294 | } | |
295 | } | |
296 | }) | |
297 | ||
298 | let fields = omit(baseCorrectParams, 'targetUrl') | |
299 | fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) | |
300 | ||
301 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) | |
302 | ||
303 | fields = omit(fields, 'magnetUri') | |
304 | const attaches = { | |
3e17515e | 305 | 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') |
187501f8 C |
306 | } |
307 | ||
308 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) | |
309 | }) | |
5d08a6a7 C |
310 | }) |
311 | ||
312 | after(async function () { | |
313 | killallServers([ server ]) | |
314 | ||
315 | // Keep the logs if the test failed | |
316 | if (this['ok']) { | |
317 | await flushTests() | |
318 | } | |
319 | }) | |
320 | }) |