1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
21 setAccessTokensToServers,
24 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
25 import { User } from '../../../../shared/models/users'
26 import { join } from 'path'
28 const expect = chai.expect
30 describe('Test video channels API validator', function () {
31 const videoChannelPath = '/api/v1/video-channels'
32 let server: ServerInfo
33 let accessTokenUser: string
35 // ---------------------------------------------------------------
37 before(async function () {
42 server = await runServer(1)
44 await setAccessTokensToServers([ server ])
48 password: 'fake_password'
52 await createUser(server.url, server.accessToken, user.username, user.password)
53 accessTokenUser = await userLogin(server, user)
57 describe('When listing a video channels', function () {
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
71 describe('When listing account video channels', function () {
72 it('Should fail with a unknown account', async function () {
73 await getAccountVideoChannelsList(server.url, 'unknown', 404)
77 describe('When adding a video channel', function () {
78 const baseCorrectParams = {
79 name: 'super_channel',
81 description: 'super description',
82 support: 'super support text'
85 it('Should fail with a non authenticated user', async function () {
86 await makePostBodyRequest({
88 path: videoChannelPath,
90 fields: baseCorrectParams,
91 statusCodeExpected: 401
95 it('Should fail with nothing', async function () {
97 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
100 it('Should fail without a name', async function () {
101 const fields = omit(baseCorrectParams, 'name')
102 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
105 it('Should fail with a bad name', async function () {
106 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
107 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
110 it('Should fail without a name', async function () {
111 const fields = omit(baseCorrectParams, 'displayName')
112 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
115 it('Should fail with a long name', async function () {
116 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
117 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
120 it('Should fail with a long description', async function () {
121 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
122 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
125 it('Should fail with a long support text', async function () {
126 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
127 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
130 it('Should succeed with the correct parameters', async function () {
131 await makePostBodyRequest({
133 path: videoChannelPath,
134 token: server.accessToken,
135 fields: baseCorrectParams,
136 statusCodeExpected: 200
140 it('Should fail when adding a channel with the same username', async function () {
141 await makePostBodyRequest({
143 path: videoChannelPath,
144 token: server.accessToken,
145 fields: baseCorrectParams,
146 statusCodeExpected: 409
151 describe('When updating a video channel', function () {
152 const baseCorrectParams = {
153 displayName: 'hello',
154 description: 'super description'
158 before(async function () {
159 path = videoChannelPath + '/super_channel'
162 it('Should fail with a non authenticated user', async function () {
163 await makePutBodyRequest({
167 fields: baseCorrectParams,
168 statusCodeExpected: 401
172 it('Should fail with another authenticated user', async function () {
173 await makePutBodyRequest({
176 token: accessTokenUser,
177 fields: baseCorrectParams,
178 statusCodeExpected: 403
182 it('Should fail with a long name', async function () {
183 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
184 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 it('Should fail with a long description', async function () {
188 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
189 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
192 it('Should fail with a long support text', async function () {
193 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
194 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
197 it('Should succeed with the correct parameters', async function () {
198 await makePutBodyRequest({
201 token: server.accessToken,
202 fields: baseCorrectParams,
203 statusCodeExpected: 204
208 describe('When updating video channel avatar', function () {
211 before(async function () {
212 path = videoChannelPath + '/super_channel'
215 it('Should fail with an incorrect input file', async function () {
218 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
220 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
223 it('Should fail with a big file', async function () {
226 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
228 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
231 it('Should fail with an unauthenticated user', async function () {
234 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
236 await makeUploadRequest({
238 path: path + '/avatar/pick',
241 statusCodeExpected: 401
245 it('Should succeed with the correct params', async function () {
248 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
250 await makeUploadRequest({
252 path: path + '/avatar/pick',
253 token: server.accessToken,
256 statusCodeExpected: 200
261 describe('When getting a video channel', function () {
262 it('Should return the list of the video channels with nothing', async function () {
263 const res = await makeGetRequest({
265 path: videoChannelPath,
266 statusCodeExpected: 200
269 expect(res.body.data).to.be.an('array')
272 it('Should return 404 with an incorrect video channel', async function () {
273 await makeGetRequest({
275 path: videoChannelPath + '/super_channel2',
276 statusCodeExpected: 404
280 it('Should succeed with the correct parameters', async function () {
281 await makeGetRequest({
283 path: videoChannelPath + '/super_channel',
284 statusCodeExpected: 200
289 describe('When deleting a video channel', function () {
290 it('Should fail with a non authenticated user', async function () {
291 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
294 it('Should fail with another authenticated user', async function () {
295 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
298 it('Should fail with an unknown video channel id', async function () {
299 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
302 it('Should succeed with the correct parameters', async function () {
303 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
306 it('Should fail to delete the last user video channel', async function () {
307 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
311 after(async function () {
312 killallServers([ server ])
314 // Keep the logs if the test failed