1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
11 getAccountVideoChannelsList,
18 setAccessTokensToServers,
20 } from '../../../../shared/extra-utils'
22 checkBadCountPagination,
23 checkBadSortPagination,
24 checkBadStartPagination
25 } from '../../../../shared/extra-utils/requests/check-api-params'
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 () {
40 server = await flushAndRunServer(1)
42 await setAccessTokensToServers([ server ])
46 password: 'fake_password'
50 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
51 accessTokenUser = await userLogin(server, user)
55 describe('When listing a video channels', function () {
56 it('Should fail with a bad start pagination', async function () {
57 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
60 it('Should fail with a bad count pagination', async function () {
61 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
64 it('Should fail with an incorrect sort', async function () {
65 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
69 describe('When listing account video channels', function () {
70 it('Should fail with a unknown account', async function () {
71 await getAccountVideoChannelsList(server.url, 'unknown', 404)
75 describe('When adding a video channel', function () {
76 const baseCorrectParams = {
77 name: 'super_channel',
79 description: 'super description',
80 support: 'super support text'
83 it('Should fail with a non authenticated user', async function () {
84 await makePostBodyRequest({
86 path: videoChannelPath,
88 fields: baseCorrectParams,
89 statusCodeExpected: 401
93 it('Should fail with nothing', async function () {
95 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
98 it('Should fail without a name', async function () {
99 const fields = omit(baseCorrectParams, 'name')
100 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
103 it('Should fail with a bad name', async function () {
104 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
105 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
108 it('Should fail without a name', async function () {
109 const fields = omit(baseCorrectParams, 'displayName')
110 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
113 it('Should fail with a long name', async function () {
114 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
115 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
118 it('Should fail with a long description', async function () {
119 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
120 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
123 it('Should fail with a long support text', async function () {
124 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
125 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
128 it('Should succeed with the correct parameters', async function () {
129 await makePostBodyRequest({
131 path: videoChannelPath,
132 token: server.accessToken,
133 fields: baseCorrectParams,
134 statusCodeExpected: 200
138 it('Should fail when adding a channel with the same username', async function () {
139 await makePostBodyRequest({
141 path: videoChannelPath,
142 token: server.accessToken,
143 fields: baseCorrectParams,
144 statusCodeExpected: 409
149 describe('When updating a video channel', function () {
150 const baseCorrectParams = {
151 displayName: 'hello',
152 description: 'super description'
156 before(async function () {
157 path = videoChannelPath + '/super_channel'
160 it('Should fail with a non authenticated user', async function () {
161 await makePutBodyRequest({
165 fields: baseCorrectParams,
166 statusCodeExpected: 401
170 it('Should fail with another authenticated user', async function () {
171 await makePutBodyRequest({
174 token: accessTokenUser,
175 fields: baseCorrectParams,
176 statusCodeExpected: 403
180 it('Should fail with a long name', async function () {
181 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
182 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
185 it('Should fail with a long description', async function () {
186 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
187 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
190 it('Should fail with a long support text', async function () {
191 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
192 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
195 it('Should succeed with the correct parameters', async function () {
196 await makePutBodyRequest({
199 token: server.accessToken,
200 fields: baseCorrectParams,
201 statusCodeExpected: 204
206 describe('When updating video channel avatar', function () {
209 before(async function () {
210 path = videoChannelPath + '/super_channel'
213 it('Should fail with an incorrect input file', async function () {
216 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
218 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
221 it('Should fail with a big file', async function () {
224 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
226 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
229 it('Should fail with an unauthenticated user', async function () {
232 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
234 await makeUploadRequest({
236 path: path + '/avatar/pick',
239 statusCodeExpected: 401
243 it('Should succeed with the correct params', async function () {
246 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
248 await makeUploadRequest({
250 path: path + '/avatar/pick',
251 token: server.accessToken,
254 statusCodeExpected: 200
259 describe('When getting a video channel', function () {
260 it('Should return the list of the video channels with nothing', async function () {
261 const res = await makeGetRequest({
263 path: videoChannelPath,
264 statusCodeExpected: 200
267 expect(res.body.data).to.be.an('array')
270 it('Should return 404 with an incorrect video channel', async function () {
271 await makeGetRequest({
273 path: videoChannelPath + '/super_channel2',
274 statusCodeExpected: 404
278 it('Should succeed with the correct parameters', async function () {
279 await makeGetRequest({
281 path: videoChannelPath + '/super_channel',
282 statusCodeExpected: 200
287 describe('When deleting a video channel', function () {
288 it('Should fail with a non authenticated user', async function () {
289 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
292 it('Should fail with another authenticated user', async function () {
293 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
296 it('Should fail with an unknown video channel id', async function () {
297 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
300 it('Should succeed with the correct parameters', async function () {
301 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
304 it('Should fail to delete the last user video channel', async function () {
305 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
309 after(async function () {
310 await cleanupTests([ server ])