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
21 } from '@shared/extra-utils'
22 import { VideoPrivacy } from '@shared/models'
24 describe('Test video imports API validator', function () {
25 const path = '/api/v1/videos/imports'
26 let server: ServerInfo
27 let userAccessToken = ''
30 // ---------------------------------------------------------------
32 before(async function () {
35 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
39 const username = 'user1'
40 const password = 'my super password'
41 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
42 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
45 const res = await getMyUserInformation(server.url, server.accessToken)
46 channelId = res.body.videoChannels[0].id
50 describe('When listing my video imports', function () {
51 const myPath = '/api/v1/users/me/videos/imports'
53 it('Should fail with a bad start pagination', async function () {
54 await checkBadStartPagination(server.url, myPath, server.accessToken)
57 it('Should fail with a bad count pagination', async function () {
58 await checkBadCountPagination(server.url, myPath, server.accessToken)
61 it('Should fail with an incorrect sort', async function () {
62 await checkBadSortPagination(server.url, myPath, server.accessToken)
65 it('Should success with the correct parameters', async function () {
66 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
70 describe('When adding a video import', function () {
75 targetUrl: ImportsCommand.getGoodVideoUrl(),
76 name: 'my super name',
81 commentsEnabled: true,
82 downloadEnabled: true,
83 waitTranscoding: true,
84 description: 'my super description',
85 support: 'my super support text',
86 tags: [ 'tag1', 'tag2' ],
87 privacy: VideoPrivacy.PUBLIC,
92 it('Should fail with nothing', async function () {
94 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
97 it('Should fail without a target url', async function () {
98 const fields = omit(baseCorrectParams, 'targetUrl')
99 await makePostBodyRequest({
102 token: server.accessToken,
104 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
108 it('Should fail with a bad target url', async function () {
109 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 it('Should fail with a long name', async function () {
115 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should fail with a bad category', async function () {
121 const fields = { ...baseCorrectParams, category: 125 }
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 it('Should fail with a bad licence', async function () {
127 const fields = { ...baseCorrectParams, licence: 125 }
129 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
132 it('Should fail with a bad language', async function () {
133 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
135 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 it('Should fail with a long description', async function () {
139 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
141 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
144 it('Should fail with a long support text', async function () {
145 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
147 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
150 it('Should fail without a channel', async function () {
151 const fields = omit(baseCorrectParams, 'channelId')
153 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
156 it('Should fail with a bad channel', async function () {
157 const fields = { ...baseCorrectParams, channelId: 545454 }
159 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
162 it('Should fail with another user channel', async function () {
165 password: 'fake_password'
167 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
169 const accessTokenUser = await server.loginCommand.getAccessToken(user)
170 const res = await getMyUserInformation(server.url, accessTokenUser)
171 const customChannelId = res.body.videoChannels[0].id
173 const fields = { ...baseCorrectParams, channelId: customChannelId }
175 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
178 it('Should fail with too many tags', async function () {
179 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
181 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
184 it('Should fail with a tag length too low', async function () {
185 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
187 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
190 it('Should fail with a tag length too big', async function () {
191 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
196 it('Should fail with an incorrect thumbnail file', async function () {
197 const fields = baseCorrectParams
199 thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
202 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
205 it('Should fail with a big thumbnail file', async function () {
206 const fields = baseCorrectParams
208 thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
211 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
214 it('Should fail with an incorrect preview file', async function () {
215 const fields = baseCorrectParams
217 previewfile: buildAbsoluteFixturePath('video_short.mp4')
220 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
223 it('Should fail with a big preview file', async function () {
224 const fields = baseCorrectParams
226 previewfile: buildAbsoluteFixturePath('preview-big.png')
229 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
232 it('Should fail with an invalid torrent file', async function () {
233 const fields = omit(baseCorrectParams, 'targetUrl')
235 torrentfile: buildAbsoluteFixturePath('avatar-big.png')
238 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
241 it('Should fail with an invalid magnet URI', async function () {
242 let fields = omit(baseCorrectParams, 'targetUrl')
243 fields = { ...fields, magnetUri: 'blabla' }
245 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
248 it('Should succeed with the correct parameters', async function () {
251 await makePostBodyRequest({
254 token: server.accessToken,
255 fields: baseCorrectParams,
256 statusCodeExpected: HttpStatusCode.OK_200
260 it('Should forbid to import http videos', async function () {
261 await server.configCommand.updateCustomSubConfig({
276 await makePostBodyRequest({
279 token: server.accessToken,
280 fields: baseCorrectParams,
281 statusCodeExpected: HttpStatusCode.CONFLICT_409
285 it('Should forbid to import torrent videos', async function () {
286 await server.configCommand.updateCustomSubConfig({
301 let fields = omit(baseCorrectParams, 'targetUrl')
302 fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() }
304 await makePostBodyRequest({
307 token: server.accessToken,
309 statusCodeExpected: HttpStatusCode.CONFLICT_409
312 fields = omit(fields, 'magnetUri')
314 torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
317 await makeUploadRequest({
320 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.CONFLICT_409
328 after(async function () {
329 await cleanupTests([ server ])