1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { HttpStatusCode } from '@shared/core-utils'
7 buildAbsoluteFixturePath,
8 checkBadCountPagination,
9 checkBadSortPagination,
10 checkBadStartPagination,
20 setAccessTokensToServers,
22 } from '@shared/extra-utils'
23 import { VideoPrivacy } from '@shared/models'
25 describe('Test video imports API validator', function () {
26 const path = '/api/v1/videos/imports'
27 let server: ServerInfo
28 let userAccessToken = ''
31 // ---------------------------------------------------------------
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
40 const username = 'user1'
41 const password = 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
43 userAccessToken = await userLogin(server, { username, password })
46 const res = await getMyUserInformation(server.url, server.accessToken)
47 channelId = res.body.videoChannels[0].id
51 describe('When listing my video imports', function () {
52 const myPath = '/api/v1/users/me/videos/imports'
54 it('Should fail with a bad start pagination', async function () {
55 await checkBadStartPagination(server.url, myPath, server.accessToken)
58 it('Should fail with a bad count pagination', async function () {
59 await checkBadCountPagination(server.url, myPath, server.accessToken)
62 it('Should fail with an incorrect sort', async function () {
63 await checkBadSortPagination(server.url, myPath, server.accessToken)
66 it('Should success with the correct parameters', async function () {
67 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
71 describe('When adding a video import', function () {
76 targetUrl: ImportsCommand.getGoodVideoUrl(),
77 name: 'my super name',
82 commentsEnabled: true,
83 downloadEnabled: true,
84 waitTranscoding: true,
85 description: 'my super description',
86 support: 'my super support text',
87 tags: [ 'tag1', 'tag2' ],
88 privacy: VideoPrivacy.PUBLIC,
93 it('Should fail with nothing', async function () {
95 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
98 it('Should fail without a target url', async function () {
99 const fields = omit(baseCorrectParams, 'targetUrl')
100 await makePostBodyRequest({
103 token: server.accessToken,
105 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
109 it('Should fail with a bad target url', async function () {
110 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
112 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 it('Should fail with a long name', async function () {
116 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
118 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
121 it('Should fail with a bad category', async function () {
122 const fields = { ...baseCorrectParams, category: 125 }
124 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
127 it('Should fail with a bad licence', async function () {
128 const fields = { ...baseCorrectParams, licence: 125 }
130 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
133 it('Should fail with a bad language', async function () {
134 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
136 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
139 it('Should fail with a long description', async function () {
140 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 it('Should fail with a long support text', async function () {
146 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
148 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
151 it('Should fail without a channel', async function () {
152 const fields = omit(baseCorrectParams, 'channelId')
154 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
157 it('Should fail with a bad channel', async function () {
158 const fields = { ...baseCorrectParams, channelId: 545454 }
160 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
163 it('Should fail with another user channel', async function () {
166 password: 'fake_password'
168 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
170 const accessTokenUser = await userLogin(server, user)
171 const res = await getMyUserInformation(server.url, accessTokenUser)
172 const customChannelId = res.body.videoChannels[0].id
174 const fields = { ...baseCorrectParams, channelId: customChannelId }
176 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
179 it('Should fail with too many tags', async function () {
180 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
182 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
185 it('Should fail with a tag length too low', async function () {
186 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
188 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
191 it('Should fail with a tag length too big', async function () {
192 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
194 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
197 it('Should fail with an incorrect thumbnail file', async function () {
198 const fields = baseCorrectParams
200 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
203 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
206 it('Should fail with a big thumbnail file', async function () {
207 const fields = baseCorrectParams
209 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
212 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
215 it('Should fail with an incorrect preview file', async function () {
216 const fields = baseCorrectParams
218 previewfile: buildAbsoluteFixturePath('video_short.mp4')
221 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
224 it('Should fail with a big preview file', async function () {
225 const fields = baseCorrectParams
227 previewfile: buildAbsoluteFixturePath('preview-big.png')
230 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
233 it('Should fail with an invalid torrent file', async function () {
234 const fields = omit(baseCorrectParams, 'targetUrl')
236 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
239 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
242 it('Should fail with an invalid magnet URI', async function () {
243 let fields = omit(baseCorrectParams, 'targetUrl')
244 fields = { ...fields, magnetUri: 'blabla' }
246 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
249 it('Should succeed with the correct parameters', async function () {
252 await makePostBodyRequest({
255 token: server.accessToken,
256 fields: baseCorrectParams,
257 statusCodeExpected: HttpStatusCode.OK_200
261 it('Should forbid to import http videos', async function () {
262 await server.configCommand.updateCustomSubConfig({
277 await makePostBodyRequest({
280 token: server.accessToken,
281 fields: baseCorrectParams,
282 statusCodeExpected: HttpStatusCode.CONFLICT_409
286 it('Should forbid to import torrent videos', async function () {
287 await server.configCommand.updateCustomSubConfig({
302 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() }
305 await makePostBodyRequest({
308 token: server.accessToken,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409
313 fields = omit(fields, 'magnetUri')
315 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
318 await makeUploadRequest({
321 token: server.accessToken,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409
329 after(async function () {
330 await cleanupTests([ server ])