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,
18 setAccessTokensToServers
19 } from '@shared/extra-utils'
20 import { VideoPrivacy } from '@shared/models'
22 describe('Test video imports API validator', function () {
23 const path = '/api/v1/videos/imports'
24 let server: PeerTubeServer
25 let userAccessToken = ''
28 // ---------------------------------------------------------------
30 before(async function () {
33 server = await createSingleServer(1)
35 await setAccessTokensToServers([ server ])
37 const username = 'user1'
38 const password = 'my super password'
39 await server.users.create({ username: username, password: password })
40 userAccessToken = await server.login.getAccessToken({ username, password })
43 const { videoChannels } = await server.users.getMyInfo()
44 channelId = videoChannels[0].id
48 describe('When listing my video imports', function () {
49 const myPath = '/api/v1/users/me/videos/imports'
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, myPath, server.accessToken)
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, myPath, server.accessToken)
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, myPath, server.accessToken)
63 it('Should success with the correct parameters', async function () {
64 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
68 describe('When adding a video import', function () {
73 targetUrl: FIXTURE_URLS.goodVideo,
74 name: 'my super name',
79 commentsEnabled: true,
80 downloadEnabled: true,
81 waitTranscoding: true,
82 description: 'my super description',
83 support: 'my super support text',
84 tags: [ 'tag1', 'tag2' ],
85 privacy: VideoPrivacy.PUBLIC,
90 it('Should fail with nothing', async function () {
92 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
95 it('Should fail without a target url', async function () {
96 const fields = omit(baseCorrectParams, 'targetUrl')
97 await makePostBodyRequest({
100 token: server.accessToken,
102 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
106 it('Should fail with a bad target url', async function () {
107 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 it('Should fail with a long name', async function () {
113 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
115 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
118 it('Should fail with a bad category', async function () {
119 const fields = { ...baseCorrectParams, category: 125 }
121 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 it('Should fail with a bad licence', async function () {
125 const fields = { ...baseCorrectParams, licence: 125 }
127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
130 it('Should fail with a bad language', async function () {
131 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
136 it('Should fail with a long description', async function () {
137 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
142 it('Should fail with a long support text', async function () {
143 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
148 it('Should fail without a channel', async function () {
149 const fields = omit(baseCorrectParams, 'channelId')
151 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
154 it('Should fail with a bad channel', async function () {
155 const fields = { ...baseCorrectParams, channelId: 545454 }
157 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
160 it('Should fail with another user channel', async function () {
163 password: 'fake_password'
165 await server.users.create({ username: user.username, password: user.password })
167 const accessTokenUser = await server.login.getAccessToken(user)
168 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
169 const customChannelId = videoChannels[0].id
171 const fields = { ...baseCorrectParams, channelId: customChannelId }
173 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
176 it('Should fail with too many tags', async function () {
177 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
179 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
182 it('Should fail with a tag length too low', async function () {
183 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
185 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
188 it('Should fail with a tag length too big', async function () {
189 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
191 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
194 it('Should fail with an incorrect thumbnail file', async function () {
195 const fields = baseCorrectParams
197 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
200 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
203 it('Should fail with a big thumbnail file', async function () {
204 const fields = baseCorrectParams
206 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
209 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
212 it('Should fail with an incorrect preview file', async function () {
213 const fields = baseCorrectParams
215 previewfile: buildAbsoluteFixturePath('video_short.mp4')
218 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
221 it('Should fail with a big preview file', async function () {
222 const fields = baseCorrectParams
224 previewfile: buildAbsoluteFixturePath('preview-big.png')
227 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
230 it('Should fail with an invalid torrent file', async function () {
231 const fields = omit(baseCorrectParams, 'targetUrl')
233 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
236 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
239 it('Should fail with an invalid magnet URI', async function () {
240 let fields = omit(baseCorrectParams, 'targetUrl')
241 fields = { ...fields, magnetUri: 'blabla' }
243 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
246 it('Should succeed with the correct parameters', async function () {
249 await makePostBodyRequest({
252 token: server.accessToken,
253 fields: baseCorrectParams,
254 statusCodeExpected: HttpStatusCode.OK_200
258 it('Should forbid to import http videos', async function () {
259 await server.config.updateCustomSubConfig({
274 await makePostBodyRequest({
277 token: server.accessToken,
278 fields: baseCorrectParams,
279 statusCodeExpected: HttpStatusCode.CONFLICT_409
283 it('Should forbid to import torrent videos', async function () {
284 await server.config.updateCustomSubConfig({
299 let fields = omit(baseCorrectParams, 'targetUrl')
300 fields = { ...fields, magnetUri: FIXTURE_URLS.magnet }
302 await makePostBodyRequest({
305 token: server.accessToken,
307 statusCodeExpected: HttpStatusCode.CONFLICT_409
310 fields = omit(fields, 'magnetUri')
312 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
315 await makeUploadRequest({
318 token: server.accessToken,
321 statusCodeExpected: HttpStatusCode.CONFLICT_409
326 after(async function () {
327 await cleanupTests([ server ])