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,
21 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23 describe('Test video imports API validator', function () {
24 const path = '/api/v1/videos/imports'
25 let server: ServerInfo
26 let userAccessToken = ''
27 let accountName: string
29 let channelUUID: string
31 // ---------------------------------------------------------------
33 before(async function () {
38 server = await runServer(1)
40 await setAccessTokensToServers([ server ])
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser(server.url, server.accessToken, username, password)
45 userAccessToken = await userLogin(server, { username, password })
48 const res = await getMyUserInformation(server.url, server.accessToken)
49 channelId = res.body.videoChannels[ 0 ].id
50 channelUUID = res.body.videoChannels[ 0 ].uuid
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: 'https://youtu.be/msX3jv1XdvM',
81 name: 'my super name',
86 commentsEnabled: true,
87 waitTranscoding: true,
88 description: 'my super description',
89 support: 'my super support text',
90 tags: [ 'tag1', 'tag2' ],
91 privacy: VideoPrivacy.PUBLIC,
96 it('Should fail with nothing', async function () {
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
101 it('Should fail with a long name', async function () {
102 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
104 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
107 it('Should fail with a bad category', async function () {
108 const fields = immutableAssign(baseCorrectParams, { category: 125 })
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
113 it('Should fail with a bad licence', async function () {
114 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
119 it('Should fail with a bad language', async function () {
120 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
125 it('Should fail with a long description', async function () {
126 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
131 it('Should fail with a long support text', async function () {
132 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
137 it('Should fail without a channel', async function () {
138 const fields = omit(baseCorrectParams, 'channelId')
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
143 it('Should fail with a bad channel', async function () {
144 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
149 it('Should fail with another user channel', async function () {
152 password: 'fake_password'
154 await createUser(server.url, server.accessToken, user.username, user.password)
156 const accessTokenUser = await userLogin(server, user)
157 const res = await getMyUserInformation(server.url, accessTokenUser)
158 const customChannelId = res.body.videoChannels[0].id
160 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
162 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
165 it('Should fail with too many tags', async function () {
166 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
168 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
171 it('Should fail with a tag length too low', async function () {
172 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
177 it('Should fail with a tag length too big', async function () {
178 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
183 it('Should fail with an incorrect thumbnail file', async function () {
184 const fields = baseCorrectParams
186 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
189 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
192 it('Should fail with a big thumbnail file', async function () {
193 const fields = baseCorrectParams
195 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
198 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
201 it('Should fail with an incorrect preview file', async function () {
202 const fields = baseCorrectParams
204 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
210 it('Should fail with a big preview file', async function () {
211 const fields = baseCorrectParams
213 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
219 it('Should succeed with the correct parameters', async function () {
222 const fields = baseCorrectParams
225 await makePostBodyRequest({
228 token: server.accessToken,
230 statusCodeExpected: 200
235 it('Should forbid importing')
238 after(async function () {
239 killallServers([ server ])
241 // Keep the logs if the test failed