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 { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports'
24 import { VideoPrivacy } from '@shared/models'
26 describe('Test video imports API validator', function () {
27 const path = '/api/v1/videos/imports'
28 let server: ServerInfo
29 let userAccessToken = ''
32 // ---------------------------------------------------------------
34 before(async function () {
37 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
44 userAccessToken = await userLogin(server, { username, password })
47 const res = await getMyUserInformation(server.url, server.accessToken)
48 channelId = res.body.videoChannels[0].id
52 describe('When listing my video imports', function () {
53 const myPath = '/api/v1/users/me/videos/imports'
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, myPath, server.accessToken)
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, myPath, server.accessToken)
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, myPath, server.accessToken)
67 it('Should success with the correct parameters', async function () {
68 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
72 describe('When adding a video import', function () {
77 targetUrl: getGoodVideoUrl(),
78 name: 'my super name',
83 commentsEnabled: true,
84 downloadEnabled: true,
85 waitTranscoding: true,
86 description: 'my super description',
87 support: 'my super support text',
88 tags: [ 'tag1', 'tag2' ],
89 privacy: VideoPrivacy.PUBLIC,
94 it('Should fail with nothing', async function () {
96 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 it('Should fail without a target url', async function () {
100 const fields = omit(baseCorrectParams, 'targetUrl')
101 await makePostBodyRequest({
104 token: server.accessToken,
106 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
110 it('Should fail with a bad target url', async function () {
111 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
116 it('Should fail with a long name', async function () {
117 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
122 it('Should fail with a bad category', async function () {
123 const fields = immutableAssign(baseCorrectParams, { category: 125 })
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
128 it('Should fail with a bad licence', async function () {
129 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
134 it('Should fail with a bad language', async function () {
135 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
140 it('Should fail with a long description', async function () {
141 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
146 it('Should fail with a long support text', async function () {
147 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
149 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
152 it('Should fail without a channel', async function () {
153 const fields = omit(baseCorrectParams, 'channelId')
155 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
158 it('Should fail with a bad channel', async function () {
159 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
161 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
164 it('Should fail with another user channel', async function () {
167 password: 'fake_password'
169 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
171 const accessTokenUser = await userLogin(server, user)
172 const res = await getMyUserInformation(server.url, accessTokenUser)
173 const customChannelId = res.body.videoChannels[0].id
175 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
177 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
180 it('Should fail with too many tags', async function () {
181 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
183 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
186 it('Should fail with a tag length too low', async function () {
187 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
189 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
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' ] })
195 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
198 it('Should fail with an incorrect thumbnail file', async function () {
199 const fields = baseCorrectParams
201 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
204 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
207 it('Should fail with a big thumbnail file', async function () {
208 const fields = baseCorrectParams
210 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
213 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
216 it('Should fail with an incorrect preview file', async function () {
217 const fields = baseCorrectParams
219 previewfile: buildAbsoluteFixturePath('video_short.mp4')
222 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
225 it('Should fail with a big preview file', async function () {
226 const fields = baseCorrectParams
228 previewfile: buildAbsoluteFixturePath('preview-big.png')
231 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
234 it('Should fail with an invalid torrent file', async function () {
235 const fields = omit(baseCorrectParams, 'targetUrl')
237 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
240 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
243 it('Should fail with an invalid magnet URI', async function () {
244 let fields = omit(baseCorrectParams, 'targetUrl')
245 fields = immutableAssign(fields, { magnetUri: 'blabla' })
247 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
250 it('Should succeed with the correct parameters', async function () {
253 await makePostBodyRequest({
256 token: server.accessToken,
257 fields: baseCorrectParams,
258 statusCodeExpected: HttpStatusCode.OK_200
262 it('Should forbid to import http videos', async function () {
263 await server.configCommand.updateCustomSubConfig({
278 await makePostBodyRequest({
281 token: server.accessToken,
282 fields: baseCorrectParams,
283 statusCodeExpected: HttpStatusCode.CONFLICT_409
287 it('Should forbid to import torrent videos', async function () {
288 await server.configCommand.updateCustomSubConfig({
303 let fields = omit(baseCorrectParams, 'targetUrl')
304 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
306 await makePostBodyRequest({
309 token: server.accessToken,
311 statusCodeExpected: HttpStatusCode.CONFLICT_409
314 fields = omit(fields, 'magnetUri')
316 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
319 await makeUploadRequest({
322 token: server.accessToken,
325 statusCodeExpected: HttpStatusCode.CONFLICT_409
330 after(async function () {
331 await cleanupTests([ server ])