1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
21 setAccessTokensToServers,
23 } from '../../../../shared/extra-utils'
25 checkBadCountPagination,
26 checkBadSortPagination,
27 checkBadStartPagination
28 } from '../../../../shared/extra-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 () {
44 server = await flushAndRunServer(1)
46 await setAccessTokensToServers([ server ])
50 password: 'fake_password'
54 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
55 accessTokenUser = await userLogin(server, user)
59 describe('When listing a video channels', function () {
60 it('Should fail with a bad start pagination', async function () {
61 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
64 it('Should fail with a bad count pagination', async function () {
65 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
68 it('Should fail with an incorrect sort', async function () {
69 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
73 describe('When listing account video channels', function () {
74 it('Should fail with a unknown account', async function () {
75 await getAccountVideoChannelsList(server.url, 'unknown', 404)
79 describe('When adding a video channel', function () {
80 const baseCorrectParams = {
81 name: 'super_channel',
83 description: 'super description',
84 support: 'super support text'
87 it('Should fail with a non authenticated user', async function () {
88 await makePostBodyRequest({
90 path: videoChannelPath,
92 fields: baseCorrectParams,
93 statusCodeExpected: 401
97 it('Should fail with nothing', async function () {
99 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
102 it('Should fail without a name', async function () {
103 const fields = omit(baseCorrectParams, 'name')
104 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
107 it('Should fail with a bad name', async function () {
108 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
109 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
112 it('Should fail without a name', async function () {
113 const fields = omit(baseCorrectParams, 'displayName')
114 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
117 it('Should fail with a long name', async function () {
118 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
119 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
122 it('Should fail with a long description', async function () {
123 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
124 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
127 it('Should fail with a long support text', async function () {
128 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
129 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
132 it('Should succeed with the correct parameters', async function () {
133 await makePostBodyRequest({
135 path: videoChannelPath,
136 token: server.accessToken,
137 fields: baseCorrectParams,
138 statusCodeExpected: 200
142 it('Should fail when adding a channel with the same username', async function () {
143 await makePostBodyRequest({
145 path: videoChannelPath,
146 token: server.accessToken,
147 fields: baseCorrectParams,
148 statusCodeExpected: 409
153 describe('When updating a video channel', function () {
154 const baseCorrectParams = {
155 displayName: 'hello',
156 description: 'super description'
160 before(async function () {
161 path = videoChannelPath + '/super_channel'
164 it('Should fail with a non authenticated user', async function () {
165 await makePutBodyRequest({
169 fields: baseCorrectParams,
170 statusCodeExpected: 401
174 it('Should fail with another authenticated user', async function () {
175 await makePutBodyRequest({
178 token: accessTokenUser,
179 fields: baseCorrectParams,
180 statusCodeExpected: 403
184 it('Should fail with a long name', async function () {
185 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
186 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
189 it('Should fail with a long description', async function () {
190 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
191 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
194 it('Should fail with a long support text', async function () {
195 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
196 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 it('Should succeed with the correct parameters', async function () {
200 await makePutBodyRequest({
203 token: server.accessToken,
204 fields: baseCorrectParams,
205 statusCodeExpected: 204
210 describe('When updating video channel avatar', function () {
213 before(async function () {
214 path = videoChannelPath + '/super_channel'
217 it('Should fail with an incorrect input file', async function () {
220 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
222 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
225 it('Should fail with a big file', async function () {
228 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
230 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
233 it('Should fail with an unauthenticated user', async function () {
236 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
238 await makeUploadRequest({
240 path: path + '/avatar/pick',
243 statusCodeExpected: 401
247 it('Should succeed with the correct params', async function () {
250 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
252 await makeUploadRequest({
254 path: path + '/avatar/pick',
255 token: server.accessToken,
258 statusCodeExpected: 200
263 describe('When getting a video channel', function () {
264 it('Should return the list of the video channels with nothing', async function () {
265 const res = await makeGetRequest({
267 path: videoChannelPath,
268 statusCodeExpected: 200
271 expect(res.body.data).to.be.an('array')
274 it('Should return 404 with an incorrect video channel', async function () {
275 await makeGetRequest({
277 path: videoChannelPath + '/super_channel2',
278 statusCodeExpected: 404
282 it('Should succeed with the correct parameters', async function () {
283 await makeGetRequest({
285 path: videoChannelPath + '/super_channel',
286 statusCodeExpected: 200
291 describe('When deleting a video channel', function () {
292 it('Should fail with a non authenticated user', async function () {
293 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
296 it('Should fail with another authenticated user', async function () {
297 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
300 it('Should fail with an unknown video channel id', async function () {
301 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
304 it('Should succeed with the correct parameters', async function () {
305 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
308 it('Should fail to delete the last user video channel', async function () {
309 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
314 killallServers([ server ])