1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { omit } from 'lodash'
6 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8 buildAbsoluteFixturePath,
19 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26 } from '../../../../shared/extra-utils/requests/check-api-params'
27 import { VideoChannelUpdate } from '../../../../shared/models/videos'
29 const expect = chai.expect
31 describe('Test video channels API validator', function () {
32 const videoChannelPath = '/api/v1/video-channels'
33 let server: ServerInfo
34 let accessTokenUser: string
35 let command: ChannelsCommand
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)
56 command = server.channelsCommand
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 const accountChannelPath = '/api/v1/accounts/fake/video-channels'
76 it('Should fail with a bad start pagination', async function () {
77 await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
80 it('Should fail with a bad count pagination', async function () {
81 await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
84 it('Should fail with an incorrect sort', async function () {
85 await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
88 it('Should fail with a unknown account', async function () {
89 await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
92 it('Should succeed with the correct parameters', async function () {
93 await makeGetRequest({
95 path: accountChannelPath,
96 statusCodeExpected: HttpStatusCode.OK_200
101 describe('When adding a video channel', function () {
102 const baseCorrectParams = {
103 name: 'super_channel',
104 displayName: 'hello',
105 description: 'super description',
106 support: 'super support text'
109 it('Should fail with a non authenticated user', async function () {
110 await makePostBodyRequest({
112 path: videoChannelPath,
114 fields: baseCorrectParams,
115 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
119 it('Should fail with nothing', async function () {
121 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
124 it('Should fail without a name', async function () {
125 const fields = omit(baseCorrectParams, 'name')
126 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
129 it('Should fail with a bad name', async function () {
130 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
131 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
134 it('Should fail without a name', async function () {
135 const fields = omit(baseCorrectParams, 'displayName')
136 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
139 it('Should fail with a long name', async function () {
140 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
141 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
144 it('Should fail with a long description', async function () {
145 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
146 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
149 it('Should fail with a long support text', async function () {
150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
151 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
154 it('Should succeed with the correct parameters', async function () {
155 await makePostBodyRequest({
157 path: videoChannelPath,
158 token: server.accessToken,
159 fields: baseCorrectParams,
160 statusCodeExpected: HttpStatusCode.OK_200
164 it('Should fail when adding a channel with the same username', async function () {
165 await makePostBodyRequest({
167 path: videoChannelPath,
168 token: server.accessToken,
169 fields: baseCorrectParams,
170 statusCodeExpected: HttpStatusCode.CONFLICT_409
175 describe('When updating a video channel', function () {
176 const baseCorrectParams: VideoChannelUpdate = {
177 displayName: 'hello',
178 description: 'super description',
180 bulkVideosSupportUpdate: false
184 before(async function () {
185 path = videoChannelPath + '/super_channel'
188 it('Should fail with a non authenticated user', async function () {
189 await makePutBodyRequest({
193 fields: baseCorrectParams,
194 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
198 it('Should fail with another authenticated user', async function () {
199 await makePutBodyRequest({
202 token: accessTokenUser,
203 fields: baseCorrectParams,
204 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
208 it('Should fail with a long name', async function () {
209 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
210 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
213 it('Should fail with a long description', async function () {
214 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
215 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 it('Should fail with a long support text', async function () {
219 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
220 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
224 const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' })
225 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
228 it('Should succeed with the correct parameters', async function () {
229 await makePutBodyRequest({
232 token: server.accessToken,
233 fields: baseCorrectParams,
234 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
239 describe('When updating video channel avatar/banner', function () {
240 const types = [ 'avatar', 'banner' ]
243 before(async function () {
244 path = videoChannelPath + '/super_channel'
247 it('Should fail with an incorrect input file', async function () {
248 for (const type of types) {
251 [type + 'file']: buildAbsoluteFixturePath('video_short.mp4')
254 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
258 it('Should fail with a big file', async function () {
259 for (const type of types) {
262 [type + 'file']: buildAbsoluteFixturePath('avatar-big.png')
264 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
268 it('Should fail with an unauthenticated user', async function () {
269 for (const type of types) {
272 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
274 await makeUploadRequest({
276 path: `${path}/${type}/pick`,
279 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
284 it('Should succeed with the correct params', async function () {
285 for (const type of types) {
288 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
290 await makeUploadRequest({
292 path: `${path}/${type}/pick`,
293 token: server.accessToken,
296 statusCodeExpected: HttpStatusCode.OK_200
302 describe('When getting a video channel', function () {
303 it('Should return the list of the video channels with nothing', async function () {
304 const res = await makeGetRequest({
306 path: videoChannelPath,
307 statusCodeExpected: HttpStatusCode.OK_200
310 expect(res.body.data).to.be.an('array')
313 it('Should return 404 with an incorrect video channel', async function () {
314 await makeGetRequest({
316 path: videoChannelPath + '/super_channel2',
317 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
321 it('Should succeed with the correct parameters', async function () {
322 await makeGetRequest({
324 path: videoChannelPath + '/super_channel',
325 statusCodeExpected: HttpStatusCode.OK_200
330 describe('When deleting a video channel', function () {
331 it('Should fail with a non authenticated user', async function () {
332 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
335 it('Should fail with another authenticated user', async function () {
336 await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
339 it('Should fail with an unknown video channel id', async function () {
340 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
343 it('Should succeed with the correct parameters', async function () {
344 await command.delete({ channelName: 'super_channel' })
347 it('Should fail to delete the last user video channel', async function () {
348 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
352 after(async function () {
353 await cleanupTests([ server ])