1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { join } from 'path'
16 setAccessTokensToServers,
17 updateCustomSubConfig,
19 } from '../../../../shared/extra-utils'
21 checkBadCountPagination,
22 checkBadSortPagination,
23 checkBadStartPagination
24 } from '../../../../shared/extra-utils/requests/check-api-params'
25 import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
26 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
27 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
29 describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports'
31 let server: ServerInfo
32 let userAccessToken = ''
35 // ---------------------------------------------------------------
37 before(async function () {
40 server = await flushAndRunServer(1)
42 await setAccessTokensToServers([ server ])
44 const username = 'user1'
45 const password = 'my super password'
46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
47 userAccessToken = await userLogin(server, { username, password })
50 const res = await getMyUserInformation(server.url, server.accessToken)
51 channelId = res.body.videoChannels[0].id
55 describe('When listing my video imports', function () {
56 const myPath = '/api/v1/users/me/videos/imports'
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, myPath, server.accessToken)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myPath, server.accessToken)
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, myPath, server.accessToken)
70 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
75 describe('When adding a video import', function () {
80 targetUrl: getGoodVideoUrl(),
81 name: 'my super name',
86 commentsEnabled: true,
87 downloadEnabled: true,
88 waitTranscoding: true,
89 description: 'my super description',
90 support: 'my super support text',
91 tags: [ 'tag1', 'tag2' ],
92 privacy: VideoPrivacy.PUBLIC,
97 it('Should fail with nothing', async function () {
99 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
102 it('Should fail without a target url', async function () {
103 const fields = omit(baseCorrectParams, 'targetUrl')
104 await makePostBodyRequest({
107 token: server.accessToken,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
113 it('Should fail with a bad target url', async function () {
114 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
119 it('Should fail with a long name', async function () {
120 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
125 it('Should fail with a bad category', async function () {
126 const fields = immutableAssign(baseCorrectParams, { category: 125 })
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
131 it('Should fail with a bad licence', async function () {
132 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
137 it('Should fail with a bad language', async function () {
138 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
143 it('Should fail with a long description', async function () {
144 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
149 it('Should fail with a long support text', async function () {
150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
155 it('Should fail without a channel', async function () {
156 const fields = omit(baseCorrectParams, 'channelId')
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
161 it('Should fail with a bad channel', async function () {
162 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
167 it('Should fail with another user channel', async function () {
170 password: 'fake_password'
172 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
174 const accessTokenUser = await userLogin(server, user)
175 const res = await getMyUserInformation(server.url, accessTokenUser)
176 const customChannelId = res.body.videoChannels[0].id
178 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
183 it('Should fail with too many tags', async function () {
184 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
189 it('Should fail with a tag length too low', async function () {
190 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
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' ] })
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
201 it('Should fail with an incorrect thumbnail file', async function () {
202 const fields = baseCorrectParams
204 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
210 it('Should fail with a big thumbnail file', async function () {
211 const fields = baseCorrectParams
213 thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
219 it('Should fail with an incorrect preview file', async function () {
220 const fields = baseCorrectParams
222 previewfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
225 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
228 it('Should fail with a big preview file', async function () {
229 const fields = baseCorrectParams
231 previewfile: join(__dirname, '..', '..', 'fixtures', 'preview-big.png')
234 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
237 it('Should fail with an invalid torrent file', async function () {
238 const fields = omit(baseCorrectParams, 'targetUrl')
240 torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
243 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
246 it('Should fail with an invalid magnet URI', async function () {
247 let fields = omit(baseCorrectParams, 'targetUrl')
248 fields = immutableAssign(fields, { magnetUri: 'blabla' })
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
253 it('Should succeed with the correct parameters', async function () {
256 await makePostBodyRequest({
259 token: server.accessToken,
260 fields: baseCorrectParams,
261 statusCodeExpected: HttpStatusCode.OK_200
265 it('Should forbid to import http videos', async function () {
266 await updateCustomSubConfig(server.url, server.accessToken, {
279 await makePostBodyRequest({
282 token: server.accessToken,
283 fields: baseCorrectParams,
284 statusCodeExpected: HttpStatusCode.CONFLICT_409
288 it('Should forbid to import torrent videos', async function () {
289 await updateCustomSubConfig(server.url, server.accessToken, {
302 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
305 await makePostBodyRequest({
308 token: server.accessToken,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409
313 fields = omit(fields, 'magnetUri')
315 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
318 await makeUploadRequest({
321 token: server.accessToken,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409
329 after(async function () {
330 await cleanupTests([ server ])