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