1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { join } from 'path'
6 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
18 setAccessTokensToServers,
19 updateCustomSubConfig,
22 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23 import { getMagnetURI, getYoutubeVideoUrl } from '../../utils/videos/video-imports'
25 describe('Test video imports API validator', function () {
26 const path = '/api/v1/videos/imports'
27 let server: ServerInfo
28 let userAccessToken = ''
29 let accountName: string
31 let channelUUID: string
33 // ---------------------------------------------------------------
35 before(async function () {
40 server = await runServer(1)
42 await setAccessTokensToServers([ server ])
44 const username = 'user1'
45 const password = 'my super password'
46 await createUser(server.url, server.accessToken, username, password)
47 userAccessToken = await userLogin(server, { username, password })
50 const res = await getMyUserInformation(server.url, server.accessToken)
51 channelId = res.body.videoChannels[ 0 ].id
52 channelUUID = res.body.videoChannels[ 0 ].uuid
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 waitTranscoding: true,
90 description: 'my super description',
91 support: 'my super support text',
92 tags: [ 'tag1', 'tag2' ],
93 privacy: VideoPrivacy.PUBLIC,
98 it('Should fail with nothing', async function () {
100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
103 it('Should fail without a target url', async function () {
104 const fields = omit(baseCorrectParams, 'targetUrl')
105 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
108 it('Should fail with a bad target url', async function () {
109 const fields = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
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 = immutableAssign(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(server.url, server.accessToken, user.username, user.password)
169 const accessTokenUser = await userLogin(server, user)
170 const res = await getMyUserInformation(server.url, accessTokenUser)
171 const customChannelId = res.body.videoChannels[0].id
173 const fields = immutableAssign(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 = immutableAssign(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 = immutableAssign(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 = immutableAssign(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': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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': join(__dirname, '..', '..', 'fixtures', 'avatar-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': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
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': join(__dirname, '..', '..', 'fixtures', 'avatar-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': join(__dirname, '..', '..', 'fixtures', '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 = immutableAssign(fields, { magnetUri: 'blabla' })
245 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
248 it('Should succeed with the correct parameters', async function () {
252 await makePostBodyRequest({
255 token: server.accessToken,
256 fields: baseCorrectParams,
257 statusCodeExpected: 200
262 it('Should forbid to import http videos', async function () {
263 await updateCustomSubConfig(server.url, server.accessToken, {
276 await makePostBodyRequest({
279 token: server.accessToken,
280 fields: baseCorrectParams,
281 statusCodeExpected: 409
285 it('Should forbid to import torrent videos', async function () {
286 await updateCustomSubConfig(server.url, server.accessToken, {
299 let fields = omit(baseCorrectParams, 'targetUrl')
300 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
302 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
304 fields = omit(fields, 'magnetUri')
306 'torrentfile': join(__dirname, '..', '..', 'fixtures', '60fps_small-240p.torrent')
309 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
313 after(async function () {
314 killallServers([ server ])
316 // Keep the logs if the test failed