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
32 // ---------------------------------------------------------------
34 before(async function () {
39 server = await runServer(1)
41 await setAccessTokensToServers([ server ])
43 const username = 'user1'
44 const password = 'my super password'
45 await createUser(server.url, server.accessToken, username, password)
46 userAccessToken = await userLogin(server, { username, password })
49 const res = await getMyUserInformation(server.url, server.accessToken)
50 channelId = res.body.videoChannels[ 0 ].id
51 accountName = res.body.account.name + '@' + res.body.account.host
55 describe('When listing my video imports', function () {
56 const myPath = '/api/v1/users/me/videos/imports'
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, myPath, server.accessToken)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myPath, server.accessToken)
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, myPath, server.accessToken)
70 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
75 describe('When adding a video import', function () {
80 targetUrl: getYoutubeVideoUrl(),
81 name: 'my super name',
86 commentsEnabled: true,
87 downloadEnabled: true,
88 waitTranscoding: true,
89 description: 'my super description',
90 support: 'my super support text',
91 tags: [ 'tag1', 'tag2' ],
92 privacy: VideoPrivacy.PUBLIC,
97 it('Should fail with nothing', async function () {
99 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
102 it('Should fail without a target url', async function () {
103 const fields = omit(baseCorrectParams, 'targetUrl')
104 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
107 it('Should fail with a bad target url', async function () {
108 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
113 it('Should fail with a long name', async function () {
114 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
119 it('Should fail with a bad category', async function () {
120 const fields = immutableAssign(baseCorrectParams, { category: 125 })
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
125 it('Should fail with a bad licence', async function () {
126 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
131 it('Should fail with a bad language', async function () {
132 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
137 it('Should fail with a long description', async function () {
138 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
143 it('Should fail with a long support text', async function () {
144 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
149 it('Should fail without a channel', async function () {
150 const fields = omit(baseCorrectParams, 'channelId')
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
155 it('Should fail with a bad channel', async function () {
156 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
161 it('Should fail with another user channel', async function () {
164 password: 'fake_password'
166 await createUser(server.url, server.accessToken, user.username, user.password)
168 const accessTokenUser = await userLogin(server, user)
169 const res = await getMyUserInformation(server.url, accessTokenUser)
170 const customChannelId = res.body.videoChannels[0].id
172 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
174 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
177 it('Should fail with too many tags', async function () {
178 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
183 it('Should fail with a tag length too low', async function () {
184 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
189 it('Should fail with a tag length too big', async function () {
190 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
195 it('Should fail with an incorrect thumbnail file', async function () {
196 const fields = baseCorrectParams
198 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
201 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
204 it('Should fail with a big thumbnail file', async function () {
205 const fields = baseCorrectParams
207 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
210 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
213 it('Should fail with an incorrect preview file', async function () {
214 const fields = baseCorrectParams
216 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
219 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
222 it('Should fail with a big preview file', async function () {
223 const fields = baseCorrectParams
225 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
228 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
231 it('Should fail with an invalid torrent file', async function () {
232 const fields = omit(baseCorrectParams, 'targetUrl')
234 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
237 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
240 it('Should fail with an invalid magnet URI', async function () {
241 let fields = omit(baseCorrectParams, 'targetUrl')
242 fields = immutableAssign(fields, { magnetUri: 'blabla' })
244 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
247 it('Should succeed with the correct parameters', async function () {
251 await makePostBodyRequest({
254 token: server.accessToken,
255 fields: baseCorrectParams,
256 statusCodeExpected: 200
261 it('Should forbid to import http videos', async function () {
262 await updateCustomSubConfig(server.url, server.accessToken, {
275 await makePostBodyRequest({
278 token: server.accessToken,
279 fields: baseCorrectParams,
280 statusCodeExpected: 409
284 it('Should forbid to import torrent videos', async function () {
285 await updateCustomSubConfig(server.url, server.accessToken, {
298 let fields = omit(baseCorrectParams, 'targetUrl')
299 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
301 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
303 fields = omit(fields, 'magnetUri')
305 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
308 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
312 after(async function () {
313 killallServers([ server ])
315 // Keep the logs if the test failed