]>
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 C |
14 | getMyUserInformation, |
15 | immutableAssign, | |
6910f20f | 16 | ImportsCommand, |
5d08a6a7 C |
17 | makeGetRequest, |
18 | makePostBodyRequest, | |
19 | makeUploadRequest, | |
5d08a6a7 C |
20 | ServerInfo, |
21 | setAccessTokensToServers, | |
22 | userLogin | |
65e6e260 | 23 | } from '@shared/extra-utils' |
65e6e260 | 24 | import { VideoPrivacy } from '@shared/models' |
5d08a6a7 C |
25 | |
26 | describe('Test video imports API validator', function () { | |
27 | const path = '/api/v1/videos/imports' | |
28 | let server: ServerInfo | |
29 | let userAccessToken = '' | |
5d08a6a7 | 30 | let channelId: number |
5d08a6a7 C |
31 | |
32 | // --------------------------------------------------------------- | |
33 | ||
34 | before(async function () { | |
35 | this.timeout(30000) | |
36 | ||
210feb6c | 37 | server = await flushAndRunServer(1) |
5d08a6a7 C |
38 | |
39 | await setAccessTokensToServers([ server ]) | |
40 | ||
41 | const username = 'user1' | |
42 | const password = 'my super password' | |
1eddc9a7 | 43 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
5d08a6a7 C |
44 | userAccessToken = await userLogin(server, { username, password }) |
45 | ||
46 | { | |
47 | const res = await getMyUserInformation(server.url, server.accessToken) | |
a1587156 | 48 | channelId = res.body.videoChannels[0].id |
5d08a6a7 C |
49 | } |
50 | }) | |
51 | ||
52 | describe('When listing my video imports', function () { | |
53 | const myPath = '/api/v1/users/me/videos/imports' | |
54 | ||
55 | it('Should fail with a bad start pagination', async function () { | |
56 | await checkBadStartPagination(server.url, myPath, server.accessToken) | |
57 | }) | |
58 | ||
59 | it('Should fail with a bad count pagination', async function () { | |
60 | await checkBadCountPagination(server.url, myPath, server.accessToken) | |
61 | }) | |
62 | ||
63 | it('Should fail with an incorrect sort', async function () { | |
64 | await checkBadSortPagination(server.url, myPath, server.accessToken) | |
65 | }) | |
66 | ||
67 | it('Should success with the correct parameters', async function () { | |
2d53be02 | 68 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) |
5d08a6a7 C |
69 | }) |
70 | }) | |
71 | ||
72 | describe('When adding a video import', function () { | |
73 | let baseCorrectParams | |
74 | ||
75 | before(function () { | |
76 | baseCorrectParams = { | |
6910f20f | 77 | targetUrl: ImportsCommand.getGoodVideoUrl(), |
5d08a6a7 C |
78 | name: 'my super name', |
79 | category: 5, | |
80 | licence: 1, | |
81 | language: 'pt', | |
82 | nsfw: false, | |
83 | commentsEnabled: true, | |
7f2cfe3a | 84 | downloadEnabled: true, |
5d08a6a7 C |
85 | waitTranscoding: true, |
86 | description: 'my super description', | |
87 | support: 'my super support text', | |
88 | tags: [ 'tag1', 'tag2' ], | |
89 | privacy: VideoPrivacy.PUBLIC, | |
c8861d5d | 90 | channelId |
5d08a6a7 C |
91 | } |
92 | }) | |
93 | ||
94 | it('Should fail with nothing', async function () { | |
95 | const fields = {} | |
96 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
97 | }) | |
98 | ||
590fb506 C |
99 | it('Should fail without a target url', async function () { |
100 | const fields = omit(baseCorrectParams, 'targetUrl') | |
2d53be02 RK |
101 | await makePostBodyRequest({ |
102 | url: server.url, | |
103 | path, | |
104 | token: server.accessToken, | |
105 | fields, | |
106 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
107 | }) | |
590fb506 C |
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 | } | |
1eddc9a7 | 169 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
5d08a6a7 C |
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 = { | |
3d470a53 | 201 | thumbnailfile: buildAbsoluteFixturePath('video_short.mp4') |
5d08a6a7 C |
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 = { | |
3d470a53 | 210 | thumbnailfile: buildAbsoluteFixturePath('preview-big.png') |
5d08a6a7 C |
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 = { | |
3d470a53 | 219 | previewfile: buildAbsoluteFixturePath('video_short.mp4') |
5d08a6a7 C |
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 = { | |
3d470a53 | 228 | previewfile: buildAbsoluteFixturePath('preview-big.png') |
5d08a6a7 C |
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 = { | |
3d470a53 | 237 | torrentfile: buildAbsoluteFixturePath('avatar-big.png') |
187501f8 C |
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 | |
b488ba1e C |
253 | await makePostBodyRequest({ |
254 | url: server.url, | |
255 | path, | |
256 | token: server.accessToken, | |
257 | fields: baseCorrectParams, | |
2d53be02 | 258 | statusCodeExpected: HttpStatusCode.OK_200 |
b488ba1e | 259 | }) |
5d08a6a7 C |
260 | }) |
261 | ||
187501f8 | 262 | it('Should forbid to import http videos', async function () { |
65e6e260 C |
263 | await server.configCommand.updateCustomSubConfig({ |
264 | newConfig: { | |
265 | import: { | |
266 | videos: { | |
267 | http: { | |
268 | enabled: false | |
269 | }, | |
270 | torrent: { | |
271 | enabled: true | |
272 | } | |
590fb506 C |
273 | } |
274 | } | |
275 | } | |
276 | }) | |
277 | ||
278 | await makePostBodyRequest({ | |
279 | url: server.url, | |
280 | path, | |
281 | token: server.accessToken, | |
282 | fields: baseCorrectParams, | |
2d53be02 | 283 | statusCodeExpected: HttpStatusCode.CONFLICT_409 |
590fb506 C |
284 | }) |
285 | }) | |
187501f8 C |
286 | |
287 | it('Should forbid to import torrent videos', async function () { | |
65e6e260 C |
288 | await server.configCommand.updateCustomSubConfig({ |
289 | newConfig: { | |
290 | import: { | |
291 | videos: { | |
292 | http: { | |
293 | enabled: true | |
294 | }, | |
295 | torrent: { | |
296 | enabled: false | |
297 | } | |
187501f8 C |
298 | } |
299 | } | |
300 | } | |
301 | }) | |
302 | ||
303 | let fields = omit(baseCorrectParams, 'targetUrl') | |
6910f20f | 304 | fields = immutableAssign(fields, { magnetUri: ImportsCommand.getMagnetURI() }) |
187501f8 | 305 | |
2d53be02 RK |
306 | await makePostBodyRequest({ |
307 | url: server.url, | |
308 | path, | |
309 | token: server.accessToken, | |
310 | fields, | |
311 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | |
312 | }) | |
187501f8 C |
313 | |
314 | fields = omit(fields, 'magnetUri') | |
315 | const attaches = { | |
3d470a53 | 316 | torrentfile: buildAbsoluteFixturePath('video-720p.torrent') |
187501f8 C |
317 | } |
318 | ||
2d53be02 RK |
319 | await makeUploadRequest({ |
320 | url: server.url, | |
321 | path, | |
322 | token: server.accessToken, | |
323 | fields, | |
324 | attaches, | |
325 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | |
326 | }) | |
187501f8 | 327 | }) |
5d08a6a7 C |
328 | }) |
329 | ||
7c3b7976 C |
330 | after(async function () { |
331 | await cleanupTests([ server ]) | |
5d08a6a7 C |
332 | }) |
333 | }) |