1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
21 setAccessTokensToServers,
23 } from '../../../../shared/utils'
25 checkBadCountPagination,
26 checkBadSortPagination,
27 checkBadStartPagination
28 } from '../../../../shared/utils/requests/check-api-params'
29 import { User } from '../../../../shared/models/users'
30 import { join } from 'path'
32 const expect = chai.expect
34 describe('Test video channels API validator', function () {
35 const videoChannelPath = '/api/v1/video-channels'
36 let server: ServerInfo
37 let accessTokenUser: string
39 // ---------------------------------------------------------------
41 before(async function () {
46 server = await runServer(1)
48 await setAccessTokensToServers([ server ])
52 password: 'fake_password'
56 await createUser(server.url, server.accessToken, user.username, user.password)
57 accessTokenUser = await userLogin(server, user)
61 describe('When listing a video channels', function () {
62 it('Should fail with a bad start pagination', async function () {
63 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
66 it('Should fail with a bad count pagination', async function () {
67 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
70 it('Should fail with an incorrect sort', async function () {
71 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
75 describe('When listing account video channels', function () {
76 it('Should fail with a unknown account', async function () {
77 await getAccountVideoChannelsList(server.url, 'unknown', 404)
81 describe('When adding a video channel', function () {
82 const baseCorrectParams = {
83 name: 'super_channel',
85 description: 'super description',
86 support: 'super support text'
89 it('Should fail with a non authenticated user', async function () {
90 await makePostBodyRequest({
92 path: videoChannelPath,
94 fields: baseCorrectParams,
95 statusCodeExpected: 401
99 it('Should fail with nothing', async function () {
101 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
104 it('Should fail without a name', async function () {
105 const fields = omit(baseCorrectParams, 'name')
106 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
109 it('Should fail with a bad name', async function () {
110 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
111 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
114 it('Should fail without a name', async function () {
115 const fields = omit(baseCorrectParams, 'displayName')
116 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
119 it('Should fail with a long name', async function () {
120 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
121 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
124 it('Should fail with a long description', async function () {
125 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
126 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
129 it('Should fail with a long support text', async function () {
130 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
131 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
134 it('Should succeed with the correct parameters', async function () {
135 await makePostBodyRequest({
137 path: videoChannelPath,
138 token: server.accessToken,
139 fields: baseCorrectParams,
140 statusCodeExpected: 200
144 it('Should fail when adding a channel with the same username', async function () {
145 await makePostBodyRequest({
147 path: videoChannelPath,
148 token: server.accessToken,
149 fields: baseCorrectParams,
150 statusCodeExpected: 409
155 describe('When updating a video channel', function () {
156 const baseCorrectParams = {
157 displayName: 'hello',
158 description: 'super description'
162 before(async function () {
163 path = videoChannelPath + '/super_channel'
166 it('Should fail with a non authenticated user', async function () {
167 await makePutBodyRequest({
171 fields: baseCorrectParams,
172 statusCodeExpected: 401
176 it('Should fail with another authenticated user', async function () {
177 await makePutBodyRequest({
180 token: accessTokenUser,
181 fields: baseCorrectParams,
182 statusCodeExpected: 403
186 it('Should fail with a long name', async function () {
187 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
188 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
191 it('Should fail with a long description', async function () {
192 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
193 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
196 it('Should fail with a long support text', async function () {
197 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
198 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
201 it('Should succeed with the correct parameters', async function () {
202 await makePutBodyRequest({
205 token: server.accessToken,
206 fields: baseCorrectParams,
207 statusCodeExpected: 204
212 describe('When updating video channel avatar', function () {
215 before(async function () {
216 path = videoChannelPath + '/super_channel'
219 it('Should fail with an incorrect input file', async function () {
222 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
224 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
227 it('Should fail with a big file', async function () {
230 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
232 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
235 it('Should fail with an unauthenticated user', async function () {
238 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
240 await makeUploadRequest({
242 path: path + '/avatar/pick',
245 statusCodeExpected: 401
249 it('Should succeed with the correct params', async function () {
252 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
254 await makeUploadRequest({
256 path: path + '/avatar/pick',
257 token: server.accessToken,
260 statusCodeExpected: 200
265 describe('When getting a video channel', function () {
266 it('Should return the list of the video channels with nothing', async function () {
267 const res = await makeGetRequest({
269 path: videoChannelPath,
270 statusCodeExpected: 200
273 expect(res.body.data).to.be.an('array')
276 it('Should return 404 with an incorrect video channel', async function () {
277 await makeGetRequest({
279 path: videoChannelPath + '/super_channel2',
280 statusCodeExpected: 404
284 it('Should succeed with the correct parameters', async function () {
285 await makeGetRequest({
287 path: videoChannelPath + '/super_channel',
288 statusCodeExpected: 200
293 describe('When deleting a video channel', function () {
294 it('Should fail with a non authenticated user', async function () {
295 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
298 it('Should fail with another authenticated user', async function () {
299 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
302 it('Should fail with an unknown video channel id', async function () {
303 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
306 it('Should succeed with the correct parameters', async function () {
307 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
310 it('Should fail to delete the last user video channel', async function () {
311 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
315 after(async function () {
316 killallServers([ server ])
318 // Keep the logs if the test failed