]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-imports.ts
More robust actor image lazy load
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-imports.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5d08a6a7 2
5d08a6a7 3import 'mocha'
b488ba1e 4import { omit } from 'lodash'
5d08a6a7 5import { join } from 'path'
5d08a6a7 6import {
7c3b7976 7 cleanupTests,
5d08a6a7 8 createUser,
7c3b7976 9 flushAndRunServer,
5d08a6a7
C
10 getMyUserInformation,
11 immutableAssign,
5d08a6a7
C
12 makeGetRequest,
13 makePostBodyRequest,
14 makeUploadRequest,
5d08a6a7
C
15 ServerInfo,
16 setAccessTokensToServers,
590fb506 17 updateCustomSubConfig,
5d08a6a7 18 userLogin
94565d52 19} from '../../../../shared/extra-utils'
9639bd17 20import {
21 checkBadCountPagination,
22 checkBadSortPagination,
23 checkBadStartPagination
94565d52 24} from '../../../../shared/extra-utils/requests/check-api-params'
b488ba1e
C
25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
2d53be02 27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5d08a6a7
C
28
29describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports'
31 let server: ServerInfo
32 let userAccessToken = ''
5d08a6a7 33 let channelId: number
5d08a6a7
C
34
35 // ---------------------------------------------------------------
36
37 before(async function () {
38 this.timeout(30000)
39
210feb6c 40 server = await flushAndRunServer(1)
5d08a6a7
C
41
42 await setAccessTokensToServers([ server ])
43
44 const username = 'user1'
45 const password = 'my super password'
1eddc9a7 46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
5d08a6a7
C
47 userAccessToken = await userLogin(server, { username, password })
48
49 {
50 const res = await getMyUserInformation(server.url, server.accessToken)
a1587156 51 channelId = res.body.videoChannels[0].id
5d08a6a7
C
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 () {
2d53be02 71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
5d08a6a7
C
72 })
73 })
74
75 describe('When adding a video import', function () {
76 let baseCorrectParams
77
78 before(function () {
79 baseCorrectParams = {
b488ba1e 80 targetUrl: getGoodVideoUrl(),
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,
c8861d5d 93 channelId
5d08a6a7
C
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')
2d53be02
RK
104 await makePostBodyRequest({
105 url: server.url,
106 path,
107 token: server.accessToken,
108 fields,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
110 })
590fb506
C
111 })
112
113 it('Should fail with a bad target url', async function () {
114 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
115
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 })
118
5d08a6a7
C
119 it('Should fail with a long name', async function () {
120 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
121
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 })
124
125 it('Should fail with a bad category', async function () {
126 const fields = immutableAssign(baseCorrectParams, { category: 125 })
127
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a bad licence', async function () {
132 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
133
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 })
136
137 it('Should fail with a bad language', async function () {
138 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
139
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 })
142
143 it('Should fail with a long description', async function () {
144 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
145
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 })
148
149 it('Should fail with a long support text', async function () {
d23e6a1c 150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
5d08a6a7
C
151
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 })
154
155 it('Should fail without a channel', async function () {
156 const fields = omit(baseCorrectParams, 'channelId')
157
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
159 })
160
161 it('Should fail with a bad channel', async function () {
162 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
163
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
165 })
166
167 it('Should fail with another user channel', async function () {
168 const user = {
169 username: 'fake',
170 password: 'fake_password'
171 }
1eddc9a7 172 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
5d08a6a7
C
173
174 const accessTokenUser = await userLogin(server, user)
175 const res = await getMyUserInformation(server.url, accessTokenUser)
176 const customChannelId = res.body.videoChannels[0].id
177
178 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
179
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
181 })
182
183 it('Should fail with too many tags', async function () {
184 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
185
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 })
188
189 it('Should fail with a tag length too low', async function () {
190 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
191
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 })
194
195 it('Should fail with a tag length too big', async function () {
196 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
197
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 })
200
201 it('Should fail with an incorrect thumbnail file', async function () {
202 const fields = baseCorrectParams
203 const attaches = {
e9cb361c 204 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
5d08a6a7
C
205 }
206
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 })
209
210 it('Should fail with a big thumbnail file', async function () {
211 const fields = baseCorrectParams
212 const attaches = {
e9cb361c 213 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
5d08a6a7
C
214 }
215
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 })
218
219 it('Should fail with an incorrect preview file', async function () {
220 const fields = baseCorrectParams
221 const attaches = {
e9cb361c 222 previewfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
5d08a6a7
C
223 }
224
225 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
226 })
227
228 it('Should fail with a big preview file', async function () {
229 const fields = baseCorrectParams
230 const attaches = {
e9cb361c 231 previewfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
5d08a6a7
C
232 }
233
234 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
235 })
236
187501f8
C
237 it('Should fail with an invalid torrent file', async function () {
238 const fields = omit(baseCorrectParams, 'targetUrl')
239 const attaches = {
a1587156 240 torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
187501f8
C
241 }
242
243 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
244 })
245
246 it('Should fail with an invalid magnet URI', async function () {
247 let fields = omit(baseCorrectParams, 'targetUrl')
248 fields = immutableAssign(fields, { magnetUri: 'blabla' })
249
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
251 })
252
5d08a6a7 253 it('Should succeed with the correct parameters', async function () {
13b6dc1f 254 this.timeout(30000)
5d08a6a7 255
b488ba1e
C
256 await makePostBodyRequest({
257 url: server.url,
258 path,
259 token: server.accessToken,
260 fields: baseCorrectParams,
2d53be02 261 statusCodeExpected: HttpStatusCode.OK_200
b488ba1e 262 })
5d08a6a7
C
263 })
264
187501f8 265 it('Should forbid to import http videos', async function () {
590fb506
C
266 await updateCustomSubConfig(server.url, server.accessToken, {
267 import: {
268 videos: {
269 http: {
270 enabled: false
187501f8
C
271 },
272 torrent: {
273 enabled: true
590fb506
C
274 }
275 }
276 }
277 })
278
279 await makePostBodyRequest({
280 url: server.url,
281 path,
282 token: server.accessToken,
283 fields: baseCorrectParams,
2d53be02 284 statusCodeExpected: HttpStatusCode.CONFLICT_409
590fb506
C
285 })
286 })
187501f8
C
287
288 it('Should forbid to import torrent videos', async function () {
289 await updateCustomSubConfig(server.url, server.accessToken, {
290 import: {
291 videos: {
292 http: {
293 enabled: true
294 },
295 torrent: {
296 enabled: false
297 }
298 }
299 }
300 })
301
302 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
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 = {
a1587156 315 torrentfile: join(__dirname, '..', '..', 'fixtures', '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})