1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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'
27 import { VideoChannelUpdate } from '../../../../shared/models/videos'
28 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 const expect = chai.expect
32 describe('Test video channels API validator', function () {
33 const videoChannelPath = '/api/v1/video-channels'
34 let server: ServerInfo
35 let accessTokenUser: string
37 // ---------------------------------------------------------------
39 before(async function () {
42 server = await flushAndRunServer(1)
44 await setAccessTokensToServers([ server ])
48 password: 'fake_password'
52 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: 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 const accountChannelPath = '/api/v1/accounts/fake/video-channels'
74 it('Should fail with a bad start pagination', async function () {
75 await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
78 it('Should fail with a bad count pagination', async function () {
79 await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
82 it('Should fail with an incorrect sort', async function () {
83 await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
86 it('Should fail with a unknown account', async function () {
87 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 })
90 it('Should succeed with the correct parameters', async function () {
91 await makeGetRequest({
93 path: accountChannelPath,
94 statusCodeExpected: HttpStatusCode.OK_200
99 describe('When adding a video channel', function () {
100 const baseCorrectParams = {
101 name: 'super_channel',
102 displayName: 'hello',
103 description: 'super description',
104 support: 'super support text'
107 it('Should fail with a non authenticated user', async function () {
108 await makePostBodyRequest({
110 path: videoChannelPath,
112 fields: baseCorrectParams,
113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
117 it('Should fail with nothing', async function () {
119 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
122 it('Should fail without a name', async function () {
123 const fields = omit(baseCorrectParams, 'name')
124 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
127 it('Should fail with a bad name', async function () {
128 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
129 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
132 it('Should fail without a name', async function () {
133 const fields = omit(baseCorrectParams, 'displayName')
134 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
137 it('Should fail with a long name', async function () {
138 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
139 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
142 it('Should fail with a long description', async function () {
143 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
144 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
147 it('Should fail with a long support text', async function () {
148 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
149 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
152 it('Should succeed with the correct parameters', async function () {
153 await makePostBodyRequest({
155 path: videoChannelPath,
156 token: server.accessToken,
157 fields: baseCorrectParams,
158 statusCodeExpected: HttpStatusCode.OK_200
162 it('Should fail when adding a channel with the same username', async function () {
163 await makePostBodyRequest({
165 path: videoChannelPath,
166 token: server.accessToken,
167 fields: baseCorrectParams,
168 statusCodeExpected: HttpStatusCode.CONFLICT_409
173 describe('When updating a video channel', function () {
174 const baseCorrectParams: VideoChannelUpdate = {
175 displayName: 'hello',
176 description: 'super description',
178 bulkVideosSupportUpdate: false
182 before(async function () {
183 path = videoChannelPath + '/super_channel'
186 it('Should fail with a non authenticated user', async function () {
187 await makePutBodyRequest({
191 fields: baseCorrectParams,
192 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
196 it('Should fail with another authenticated user', async function () {
197 await makePutBodyRequest({
200 token: accessTokenUser,
201 fields: baseCorrectParams,
202 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
206 it('Should fail with a long name', async function () {
207 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
208 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
211 it('Should fail with a long description', async function () {
212 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
213 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
216 it('Should fail with a long support text', async function () {
217 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
218 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
222 const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' })
223 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
226 it('Should succeed with the correct parameters', async function () {
227 await makePutBodyRequest({
230 token: server.accessToken,
231 fields: baseCorrectParams,
232 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
237 describe('When updating video channel avatar/banner', function () {
238 const types = [ 'avatar', 'banner' ]
241 before(async function () {
242 path = videoChannelPath + '/super_channel'
245 it('Should fail with an incorrect input file', async function () {
246 for (const type of types) {
249 [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
252 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
256 it('Should fail with a big file', async function () {
257 for (const type of types) {
260 [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
262 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
266 it('Should fail with an unauthenticated user', async function () {
267 for (const type of types) {
270 [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
272 await makeUploadRequest({
274 path: `${path}/${type}/pick`,
277 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
282 it('Should succeed with the correct params', async function () {
283 for (const type of types) {
286 [type + 'file']: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
288 await makeUploadRequest({
290 path: `${path}/${type}/pick`,
291 token: server.accessToken,
294 statusCodeExpected: HttpStatusCode.OK_200
300 describe('When getting a video channel', function () {
301 it('Should return the list of the video channels with nothing', async function () {
302 const res = await makeGetRequest({
304 path: videoChannelPath,
305 statusCodeExpected: HttpStatusCode.OK_200
308 expect(res.body.data).to.be.an('array')
311 it('Should return 404 with an incorrect video channel', async function () {
312 await makeGetRequest({
314 path: videoChannelPath + '/super_channel2',
315 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
319 it('Should succeed with the correct parameters', async function () {
320 await makeGetRequest({
322 path: videoChannelPath + '/super_channel',
323 statusCodeExpected: HttpStatusCode.OK_200
328 describe('When deleting a video channel', function () {
329 it('Should fail with a non authenticated user', async function () {
330 await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401)
333 it('Should fail with another authenticated user', async function () {
334 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403)
337 it('Should fail with an unknown video channel id', async function () {
338 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404)
341 it('Should succeed with the correct parameters', async function () {
342 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
345 it('Should fail to delete the last user video channel', async function () {
346 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409)
350 after(async function () {
351 await cleanupTests([ server ])