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 = ''
34 // ---------------------------------------------------------------
36 before(async function () {
39 server = await flushAndRunServer(1)
41 await setAccessTokensToServers([ server ])
43 const username = 'user1'
44 const password = 'my super password'
45 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
46 userAccessToken = await userLogin(server, { username, password })
49 const res = await getMyUserInformation(server.url, server.accessToken)
50 channelId = res.body.videoChannels[0].id
54 describe('When listing my video imports', function () {
55 const myPath = '/api/v1/users/me/videos/imports'
57 it('Should fail with a bad start pagination', async function () {
58 await checkBadStartPagination(server.url, myPath, server.accessToken)
61 it('Should fail with a bad count pagination', async function () {
62 await checkBadCountPagination(server.url, myPath, server.accessToken)
65 it('Should fail with an incorrect sort', async function () {
66 await checkBadSortPagination(server.url, myPath, server.accessToken)
69 it('Should success with the correct parameters', async function () {
70 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
74 describe('When adding a video import', function () {
79 targetUrl: getYoutubeVideoUrl(),
80 name: 'my super name',
85 commentsEnabled: true,
86 downloadEnabled: true,
87 waitTranscoding: true,
88 description: 'my super description',
89 support: 'my super support text',
90 tags: [ 'tag1', 'tag2' ],
91 privacy: VideoPrivacy.PUBLIC,
96 it('Should fail with nothing', async function () {
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
101 it('Should fail without a target url', async function () {
102 const fields = omit(baseCorrectParams, 'targetUrl')
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
106 it('Should fail with a bad target url', async function () {
107 const fields = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
167 const accessTokenUser = await userLogin(server, user)
168 const res = await getMyUserInformation(server.url, accessTokenUser)
169 const customChannelId = res.body.videoChannels[0].id
171 const fields = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-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: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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: join(__dirname, '..', '..', 'fixtures', 'avatar-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: join(__dirname, '..', '..', 'fixtures', '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 = immutableAssign(fields, { magnetUri: 'blabla' })
243 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
246 it('Should succeed with the correct parameters', async function () {
250 await makePostBodyRequest({
253 token: server.accessToken,
254 fields: baseCorrectParams,
255 statusCodeExpected: 200
260 it('Should forbid to import http videos', async function () {
261 await updateCustomSubConfig(server.url, server.accessToken, {
274 await makePostBodyRequest({
277 token: server.accessToken,
278 fields: baseCorrectParams,
279 statusCodeExpected: 409
283 it('Should forbid to import torrent videos', async function () {
284 await updateCustomSubConfig(server.url, server.accessToken, {
297 let fields = omit(baseCorrectParams, 'targetUrl')
298 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
300 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
302 fields = omit(fields, 'magnetUri')
304 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
307 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
311 after(async function () {
312 await cleanupTests([ server ])