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 const accountChannelPath = '/api/v1/accounts/fake/video-channels'
72 it('Should fail with a bad start pagination', async function () {
73 await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
76 it('Should fail with a bad count pagination', async function () {
77 await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
80 it('Should fail with an incorrect sort', async function () {
81 await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
84 it('Should fail with a unknown account', async function () {
85 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 })
88 it('Should succeed with the correct parameters', async function () {
89 await makeGetRequest({
91 path: accountChannelPath,
92 statusCodeExpected: 200
97 describe('When adding a video channel', function () {
98 const baseCorrectParams = {
99 name: 'super_channel',
100 displayName: 'hello',
101 description: 'super description',
102 support: 'super support text'
105 it('Should fail with a non authenticated user', async function () {
106 await makePostBodyRequest({
108 path: videoChannelPath,
110 fields: baseCorrectParams,
111 statusCodeExpected: 401
115 it('Should fail with nothing', async function () {
117 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
120 it('Should fail without a name', async function () {
121 const fields = omit(baseCorrectParams, 'name')
122 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
125 it('Should fail with a bad name', async function () {
126 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
127 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
130 it('Should fail without a name', async function () {
131 const fields = omit(baseCorrectParams, 'displayName')
132 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
135 it('Should fail with a long name', async function () {
136 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
137 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
140 it('Should fail with a long description', async function () {
141 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
142 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
145 it('Should fail with a long support text', async function () {
146 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
147 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
150 it('Should succeed with the correct parameters', async function () {
151 await makePostBodyRequest({
153 path: videoChannelPath,
154 token: server.accessToken,
155 fields: baseCorrectParams,
156 statusCodeExpected: 200
160 it('Should fail when adding a channel with the same username', async function () {
161 await makePostBodyRequest({
163 path: videoChannelPath,
164 token: server.accessToken,
165 fields: baseCorrectParams,
166 statusCodeExpected: 409
171 describe('When updating a video channel', function () {
172 const baseCorrectParams = {
173 displayName: 'hello',
174 description: 'super description'
178 before(async function () {
179 path = videoChannelPath + '/super_channel'
182 it('Should fail with a non authenticated user', async function () {
183 await makePutBodyRequest({
187 fields: baseCorrectParams,
188 statusCodeExpected: 401
192 it('Should fail with another authenticated user', async function () {
193 await makePutBodyRequest({
196 token: accessTokenUser,
197 fields: baseCorrectParams,
198 statusCodeExpected: 403
202 it('Should fail with a long name', async function () {
203 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
204 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
207 it('Should fail with a long description', async function () {
208 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
209 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
212 it('Should fail with a long support text', async function () {
213 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
214 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 it('Should succeed with the correct parameters', async function () {
218 await makePutBodyRequest({
221 token: server.accessToken,
222 fields: baseCorrectParams,
223 statusCodeExpected: 204
228 describe('When updating video channel avatar', function () {
231 before(async function () {
232 path = videoChannelPath + '/super_channel'
235 it('Should fail with an incorrect input file', async function () {
238 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
240 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
243 it('Should fail with a big file', async function () {
246 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
248 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
251 it('Should fail with an unauthenticated user', async function () {
254 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
256 await makeUploadRequest({
258 path: path + '/avatar/pick',
261 statusCodeExpected: 401
265 it('Should succeed with the correct params', async function () {
268 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
270 await makeUploadRequest({
272 path: path + '/avatar/pick',
273 token: server.accessToken,
276 statusCodeExpected: 200
281 describe('When getting a video channel', function () {
282 it('Should return the list of the video channels with nothing', async function () {
283 const res = await makeGetRequest({
285 path: videoChannelPath,
286 statusCodeExpected: 200
289 expect(res.body.data).to.be.an('array')
292 it('Should return 404 with an incorrect video channel', async function () {
293 await makeGetRequest({
295 path: videoChannelPath + '/super_channel2',
296 statusCodeExpected: 404
300 it('Should succeed with the correct parameters', async function () {
301 await makeGetRequest({
303 path: videoChannelPath + '/super_channel',
304 statusCodeExpected: 200
309 describe('When deleting a video channel', function () {
310 it('Should fail with a non authenticated user', async function () {
311 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
314 it('Should fail with another authenticated user', async function () {
315 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
318 it('Should fail with an unknown video channel id', async function () {
319 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
322 it('Should succeed with the correct parameters', async function () {
323 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
326 it('Should fail to delete the last user video channel', async function () {
327 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
331 after(async function () {
332 await cleanupTests([ server ])