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 downloadEnabled: true,
92 waitTranscoding: true,
93 description: 'my super description',
94 support: 'my super support text',
95 tags: [ 'tag1', 'tag2' ],
96 privacy: VideoPrivacy.PUBLIC,
101 it('Should fail with nothing', async function () {
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
106 it('Should fail without a target url', async function () {
107 const fields = omit(baseCorrectParams, 'targetUrl')
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
111 it('Should fail with a bad target url', async function () {
112 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 it('Should fail with a long name', async function () {
118 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 it('Should fail with a bad category', async function () {
124 const fields = immutableAssign(baseCorrectParams, { category: 125 })
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 it('Should fail with a bad licence', async function () {
130 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 it('Should fail with a bad language', async function () {
136 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 it('Should fail with a long description', async function () {
142 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 it('Should fail with a long support text', async function () {
148 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 it('Should fail without a channel', async function () {
154 const fields = omit(baseCorrectParams, 'channelId')
156 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
159 it('Should fail with a bad channel', async function () {
160 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
162 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
165 it('Should fail with another user channel', async function () {
168 password: 'fake_password'
170 await createUser(server.url, server.accessToken, user.username, user.password)
172 const accessTokenUser = await userLogin(server, user)
173 const res = await getMyUserInformation(server.url, accessTokenUser)
174 const customChannelId = res.body.videoChannels[0].id
176 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
178 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
181 it('Should fail with too many tags', async function () {
182 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 it('Should fail with a tag length too low', async function () {
188 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 it('Should fail with a tag length too big', async function () {
194 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
196 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 it('Should fail with an incorrect thumbnail file', async function () {
200 const fields = baseCorrectParams
202 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
205 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 it('Should fail with a big thumbnail file', async function () {
209 const fields = baseCorrectParams
211 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
214 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 it('Should fail with an incorrect preview file', async function () {
218 const fields = baseCorrectParams
220 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
223 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
226 it('Should fail with a big preview file', async function () {
227 const fields = baseCorrectParams
229 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
232 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
235 it('Should fail with an invalid torrent file', async function () {
236 const fields = omit(baseCorrectParams, 'targetUrl')
238 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
241 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
244 it('Should fail with an invalid magnet URI', async function () {
245 let fields = omit(baseCorrectParams, 'targetUrl')
246 fields = immutableAssign(fields, { magnetUri: 'blabla' })
248 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
251 it('Should succeed with the correct parameters', async function () {
255 await makePostBodyRequest({
258 token: server.accessToken,
259 fields: baseCorrectParams,
260 statusCodeExpected: 200
265 it('Should forbid to import http videos', async function () {
266 await updateCustomSubConfig(server.url, server.accessToken, {
279 await makePostBodyRequest({
282 token: server.accessToken,
283 fields: baseCorrectParams,
284 statusCodeExpected: 409
288 it('Should forbid to import torrent videos', async function () {
289 await updateCustomSubConfig(server.url, server.accessToken, {
302 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
305 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
307 fields = omit(fields, 'magnetUri')
309 'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
312 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
316 after(async function () {
317 killallServers([ server ])
319 // Keep the logs if the test failed