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,
21 } from '../../../../shared/utils'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26 } from '../../../../shared/utils/requests/check-api-params'
27 import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/utils/videos/video-imports'
29 describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports'
31 let server: ServerInfo
32 let userAccessToken = ''
33 let accountName: string
36 // ---------------------------------------------------------------
38 before(async function () {
43 server = await runServer(1)
45 await setAccessTokensToServers([ server ])
47 const username = 'user1'
48 const password = 'my super password'
49 await createUser(server.url, server.accessToken, username, password)
50 userAccessToken = await userLogin(server, { username, password })
53 const res = await getMyUserInformation(server.url, server.accessToken)
54 channelId = res.body.videoChannels[ 0 ].id
55 accountName = res.body.account.name + '@' + res.body.account.host
59 describe('When listing my video imports', function () {
60 const myPath = '/api/v1/users/me/videos/imports'
62 it('Should fail with a bad start pagination', async function () {
63 await checkBadStartPagination(server.url, myPath, server.accessToken)
66 it('Should fail with a bad count pagination', async function () {
67 await checkBadCountPagination(server.url, myPath, server.accessToken)
70 it('Should fail with an incorrect sort', async function () {
71 await checkBadSortPagination(server.url, myPath, server.accessToken)
74 it('Should success with the correct parameters', async function () {
75 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
79 describe('When adding a video import', function () {
84 targetUrl: getYoutubeVideoUrl(),
85 name: 'my super name',
90 commentsEnabled: true,
91 waitTranscoding: true,
92 description: 'my super description',
93 support: 'my super support text',
94 tags: [ 'tag1', 'tag2' ],
95 privacy: VideoPrivacy.PUBLIC,
100 it('Should fail with nothing', async function () {
102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
105 it('Should fail without a target url', async function () {
106 const fields = omit(baseCorrectParams, 'targetUrl')
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
110 it('Should fail with a bad target url', async function () {
111 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
116 it('Should fail with a long name', async function () {
117 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
122 it('Should fail with a bad category', async function () {
123 const fields = immutableAssign(baseCorrectParams, { category: 125 })
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
128 it('Should fail with a bad licence', async function () {
129 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
134 it('Should fail with a bad language', async function () {
135 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
140 it('Should fail with a long description', async function () {
141 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
146 it('Should fail with a long support text', async function () {
147 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
149 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
152 it('Should fail without a channel', async function () {
153 const fields = omit(baseCorrectParams, 'channelId')
155 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
158 it('Should fail with a bad channel', async function () {
159 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
161 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
164 it('Should fail with another user channel', async function () {
167 password: 'fake_password'
169 await createUser(server.url, server.accessToken, user.username, user.password)
171 const accessTokenUser = await userLogin(server, user)
172 const res = await getMyUserInformation(server.url, accessTokenUser)
173 const customChannelId = res.body.videoChannels[0].id
175 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
177 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
180 it('Should fail with too many tags', async function () {
181 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
183 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
186 it('Should fail with a tag length too low', async function () {
187 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
189 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
192 it('Should fail with a tag length too big', async function () {
193 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
195 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
198 it('Should fail with an incorrect thumbnail file', async function () {
199 const fields = baseCorrectParams
201 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
204 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
207 it('Should fail with a big thumbnail file', async function () {
208 const fields = baseCorrectParams
210 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
213 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
216 it('Should fail with an incorrect preview file', async function () {
217 const fields = baseCorrectParams
219 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
222 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
225 it('Should fail with a big preview file', async function () {
226 const fields = baseCorrectParams
228 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
231 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
234 it('Should fail with an invalid torrent file', async function () {
235 const fields = omit(baseCorrectParams, 'targetUrl')
237 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
240 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
243 it('Should fail with an invalid magnet URI', async function () {
244 let fields = omit(baseCorrectParams, 'targetUrl')
245 fields = immutableAssign(fields, { magnetUri: 'blabla' })
247 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
250 it('Should succeed with the correct parameters', async function () {
254 await makePostBodyRequest({
257 token: server.accessToken,
258 fields: baseCorrectParams,
259 statusCodeExpected: 200
264 it('Should forbid to import http videos', async function () {
265 await updateCustomSubConfig(server.url, server.accessToken, {
278 await makePostBodyRequest({
281 token: server.accessToken,
282 fields: baseCorrectParams,
283 statusCodeExpected: 409
287 it('Should forbid to import torrent videos', async function () {
288 await updateCustomSubConfig(server.url, server.accessToken, {
301 let fields = omit(baseCorrectParams, 'targetUrl')
302 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
304 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
306 fields = omit(fields, 'magnetUri')
308 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
311 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
315 after(async function () {
316 killallServers([ server ])
318 // Keep the logs if the test failed