1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
6 buildAbsoluteFixturePath,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
17 setAccessTokensToServers
18 } from '@shared/extra-utils'
19 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
21 describe('Test video imports API validator', function () {
22 const path = '/api/v1/videos/imports'
23 let server: PeerTubeServer
24 let userAccessToken = ''
27 // ---------------------------------------------------------------
29 before(async function () {
32 server = await createSingleServer(1)
34 await setAccessTokensToServers([ server ])
36 const username = 'user1'
37 const password = 'my super password'
38 await server.users.create({ username: username, password: password })
39 userAccessToken = await server.login.getAccessToken({ username, password })
42 const { videoChannels } = await server.users.getMyInfo()
43 channelId = videoChannels[0].id
47 describe('When listing my video imports', function () {
48 const myPath = '/api/v1/users/me/videos/imports'
50 it('Should fail with a bad start pagination', async function () {
51 await checkBadStartPagination(server.url, myPath, server.accessToken)
54 it('Should fail with a bad count pagination', async function () {
55 await checkBadCountPagination(server.url, myPath, server.accessToken)
58 it('Should fail with an incorrect sort', async function () {
59 await checkBadSortPagination(server.url, myPath, server.accessToken)
62 it('Should success with the correct parameters', async function () {
63 await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
67 describe('When adding a video import', function () {
72 targetUrl: FIXTURE_URLS.goodVideo,
73 name: 'my super name',
78 commentsEnabled: true,
79 downloadEnabled: true,
80 waitTranscoding: true,
81 description: 'my super description',
82 support: 'my super support text',
83 tags: [ 'tag1', 'tag2' ],
84 privacy: VideoPrivacy.PUBLIC,
89 it('Should fail with nothing', async function () {
91 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
94 it('Should fail without a target url', async function () {
95 const fields = omit(baseCorrectParams, 'targetUrl')
96 await makePostBodyRequest({
99 token: server.accessToken,
101 expectedStatus: HttpStatusCode.BAD_REQUEST_400
105 it('Should fail with a bad target url', async function () {
106 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 it('Should fail with a long name', async function () {
112 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 it('Should fail with a bad category', async function () {
118 const fields = { ...baseCorrectParams, category: 125 }
120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 it('Should fail with a bad licence', async function () {
124 const fields = { ...baseCorrectParams, licence: 125 }
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 it('Should fail with a bad language', async function () {
130 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 it('Should fail with a long description', async function () {
136 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 it('Should fail with a long support text', async function () {
142 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 it('Should fail without a channel', async function () {
148 const fields = omit(baseCorrectParams, 'channelId')
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 it('Should fail with a bad channel', async function () {
154 const fields = { ...baseCorrectParams, channelId: 545454 }
156 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
159 it('Should fail with another user channel', async function () {
162 password: 'fake_password'
164 await server.users.create({ username: user.username, password: user.password })
166 const accessTokenUser = await server.login.getAccessToken(user)
167 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
168 const customChannelId = videoChannels[0].id
170 const fields = { ...baseCorrectParams, channelId: customChannelId }
172 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
175 it('Should fail with too many tags', async function () {
176 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
178 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 it('Should fail with a tag length too low', async function () {
182 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 it('Should fail with a tag length too big', async function () {
188 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 it('Should fail with an incorrect thumbnail file', async function () {
194 const fields = baseCorrectParams
196 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
199 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
202 it('Should fail with a big thumbnail file', async function () {
203 const fields = baseCorrectParams
205 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
208 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
211 it('Should fail with an incorrect preview file', async function () {
212 const fields = baseCorrectParams
214 previewfile: buildAbsoluteFixturePath('video_short.mp4')
217 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
220 it('Should fail with a big preview file', async function () {
221 const fields = baseCorrectParams
223 previewfile: buildAbsoluteFixturePath('preview-big.png')
226 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
229 it('Should fail with an invalid torrent file', async function () {
230 const fields = omit(baseCorrectParams, 'targetUrl')
232 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
235 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
238 it('Should fail with an invalid magnet URI', async function () {
239 let fields = omit(baseCorrectParams, 'targetUrl')
240 fields = { ...fields, magnetUri: 'blabla' }
242 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
245 it('Should succeed with the correct parameters', async function () {
248 await makePostBodyRequest({
251 token: server.accessToken,
252 fields: baseCorrectParams,
253 expectedStatus: HttpStatusCode.OK_200
257 it('Should forbid to import http videos', async function () {
258 await server.config.updateCustomSubConfig({
273 await makePostBodyRequest({
276 token: server.accessToken,
277 fields: baseCorrectParams,
278 expectedStatus: HttpStatusCode.CONFLICT_409
282 it('Should forbid to import torrent videos', async function () {
283 await server.config.updateCustomSubConfig({
298 let fields = omit(baseCorrectParams, 'targetUrl')
299 fields = { ...fields, magnetUri: FIXTURE_URLS.magnet }
301 await makePostBodyRequest({
304 token: server.accessToken,
306 expectedStatus: HttpStatusCode.CONFLICT_409
309 fields = omit(fields, 'magnetUri')
311 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
314 await makeUploadRequest({
317 token: server.accessToken,
320 expectedStatus: HttpStatusCode.CONFLICT_409
325 after(async function () {
326 await cleanupTests([ server ])