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'
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 let accountName: string
35 // ---------------------------------------------------------------
37 before(async function () {
40 server = await flushAndRunServer(1)
42 await setAccessTokensToServers([ server ])
44 const username = 'user1'
45 const password = 'my super password'
46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: 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 accountName = res.body.account.name + '@' + res.body.account.host
56 describe('When listing my video imports', function () {
57 const myPath = '/api/v1/users/me/videos/imports'
59 it('Should fail with a bad start pagination', async function () {
60 await checkBadStartPagination(server.url, myPath, server.accessToken)
63 it('Should fail with a bad count pagination', async function () {
64 await checkBadCountPagination(server.url, myPath, server.accessToken)
67 it('Should fail with an incorrect sort', async function () {
68 await checkBadSortPagination(server.url, myPath, server.accessToken)
71 it('Should success with the correct parameters', async function () {
72 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
76 describe('When adding a video import', function () {
81 targetUrl: getYoutubeVideoUrl(),
82 name: 'my super name',
87 commentsEnabled: true,
88 downloadEnabled: 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(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 = 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({ url: server.url, accessToken: server.accessToken, username: user.username, password: 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', 'video-720p.torrent')
309 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
313 after(async function () {
314 await cleanupTests([ server ])