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