1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { omit } from 'lodash'
5 import { join } from 'path'
6 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
17 setAccessTokensToServers,
18 updateCustomSubConfig,
20 } from '../../../../shared/extra-utils'
22 checkBadCountPagination,
23 checkBadSortPagination,
24 checkBadStartPagination
25 } from '../../../../shared/extra-utils/requests/check-api-params'
26 import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
28 describe('Test video imports API validator', function () {
29 const path = '/api/v1/videos/imports'
30 let server: ServerInfo
31 let userAccessToken = ''
32 // eslint-disable-next-line @typescript-eslint/no-unused-vars
33 let accountName: string
36 // ---------------------------------------------------------------
38 before(async function () {
41 server = await flushAndRunServer(1)
43 await setAccessTokensToServers([ server ])
45 const username = 'user1'
46 const password = 'my super password'
47 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
48 userAccessToken = await userLogin(server, { username, password })
51 const res = await getMyUserInformation(server.url, server.accessToken)
52 channelId = res.body.videoChannels[0].id
53 accountName = res.body.account.name + '@' + res.body.account.host
57 describe('When listing my video imports', function () {
58 const myPath = '/api/v1/users/me/videos/imports'
60 it('Should fail with a bad start pagination', async function () {
61 await checkBadStartPagination(server.url, myPath, server.accessToken)
64 it('Should fail with a bad count pagination', async function () {
65 await checkBadCountPagination(server.url, myPath, server.accessToken)
68 it('Should fail with an incorrect sort', async function () {
69 await checkBadSortPagination(server.url, myPath, server.accessToken)
72 it('Should success with the correct parameters', async function () {
73 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
77 describe('When adding a video import', function () {
82 targetUrl: getYoutubeVideoUrl(),
83 name: 'my super name',
88 commentsEnabled: true,
89 downloadEnabled: true,
90 waitTranscoding: true,
91 description: 'my super description',
92 support: 'my super support text',
93 tags: [ 'tag1', 'tag2' ],
94 privacy: VideoPrivacy.PUBLIC,
99 it('Should fail with nothing', async function () {
101 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
104 it('Should fail without a target url', async function () {
105 const fields = omit(baseCorrectParams, 'targetUrl')
106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
109 it('Should fail with a bad target url', async function () {
110 const fields = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-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: join(__dirname, '..', '..', 'fixtures', '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 = immutableAssign(fields, { magnetUri: 'blabla' })
246 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
249 it('Should succeed with the correct parameters', async function () {
253 await makePostBodyRequest({
256 token: server.accessToken,
257 fields: baseCorrectParams,
258 statusCodeExpected: 200
263 it('Should forbid to import http videos', async function () {
264 await updateCustomSubConfig(server.url, server.accessToken, {
277 await makePostBodyRequest({
280 token: server.accessToken,
281 fields: baseCorrectParams,
282 statusCodeExpected: 409
286 it('Should forbid to import torrent videos', async function () {
287 await updateCustomSubConfig(server.url, server.accessToken, {
300 let fields = omit(baseCorrectParams, 'targetUrl')
301 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
303 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
305 fields = omit(fields, 'magnetUri')
307 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
310 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
314 after(async function () {
315 await cleanupTests([ server ])