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'
8 buildAbsoluteFixturePath,
10 checkBadCountPagination,
11 checkBadSortPagination,
12 checkBadStartPagination,
21 setAccessTokensToServers,
23 } from '@shared/extra-utils'
24 import { VideoChannelUpdate } from '@shared/models'
26 const expect = chai.expect
28 describe('Test video channels API validator', function () {
29 const videoChannelPath = '/api/v1/video-channels'
30 let server: ServerInfo
31 let accessTokenUser: string
32 let command: ChannelsCommand
34 // ---------------------------------------------------------------
36 before(async function () {
39 server = await flushAndRunServer(1)
41 await setAccessTokensToServers([ server ])
45 password: 'fake_password'
49 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
50 accessTokenUser = await userLogin(server, user)
53 command = server.channelsCommand
56 describe('When listing a video channels', function () {
57 it('Should fail with a bad start pagination', async function () {
58 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
61 it('Should fail with a bad count pagination', async function () {
62 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
65 it('Should fail with an incorrect sort', async function () {
66 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
70 describe('When listing account video channels', function () {
71 const accountChannelPath = '/api/v1/accounts/fake/video-channels'
73 it('Should fail with a bad start pagination', async function () {
74 await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
77 it('Should fail with a bad count pagination', async function () {
78 await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
81 it('Should fail with an incorrect sort', async function () {
82 await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
85 it('Should fail with a unknown account', async function () {
86 await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
89 it('Should succeed with the correct parameters', async function () {
90 await makeGetRequest({
92 path: accountChannelPath,
93 statusCodeExpected: HttpStatusCode.OK_200
98 describe('When adding a video channel', function () {
99 const baseCorrectParams = {
100 name: 'super_channel',
101 displayName: 'hello',
102 description: 'super description',
103 support: 'super support text'
106 it('Should fail with a non authenticated user', async function () {
107 await makePostBodyRequest({
109 path: videoChannelPath,
111 fields: baseCorrectParams,
112 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
116 it('Should fail with nothing', async function () {
118 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
121 it('Should fail without a name', async function () {
122 const fields = omit(baseCorrectParams, 'name')
123 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
126 it('Should fail with a bad name', async function () {
127 const fields = { ...baseCorrectParams, name: 'super name' }
128 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
131 it('Should fail without a name', async function () {
132 const fields = omit(baseCorrectParams, 'displayName')
133 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
136 it('Should fail with a long name', async function () {
137 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
138 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
141 it('Should fail with a long description', async function () {
142 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
143 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
146 it('Should fail with a long support text', async function () {
147 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
148 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
151 it('Should succeed with the correct parameters', async function () {
152 await makePostBodyRequest({
154 path: videoChannelPath,
155 token: server.accessToken,
156 fields: baseCorrectParams,
157 statusCodeExpected: HttpStatusCode.OK_200
161 it('Should fail when adding a channel with the same username', async function () {
162 await makePostBodyRequest({
164 path: videoChannelPath,
165 token: server.accessToken,
166 fields: baseCorrectParams,
167 statusCodeExpected: HttpStatusCode.CONFLICT_409
172 describe('When updating a video channel', function () {
173 const baseCorrectParams: VideoChannelUpdate = {
174 displayName: 'hello',
175 description: 'super description',
177 bulkVideosSupportUpdate: false
181 before(async function () {
182 path = videoChannelPath + '/super_channel'
185 it('Should fail with a non authenticated user', async function () {
186 await makePutBodyRequest({
190 fields: baseCorrectParams,
191 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
195 it('Should fail with another authenticated user', async function () {
196 await makePutBodyRequest({
199 token: accessTokenUser,
200 fields: baseCorrectParams,
201 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
205 it('Should fail with a long name', async function () {
206 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
207 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
210 it('Should fail with a long description', async function () {
211 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
212 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
215 it('Should fail with a long support text', async function () {
216 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
217 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
220 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
221 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
222 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
225 it('Should succeed with the correct parameters', async function () {
226 await makePutBodyRequest({
229 token: server.accessToken,
230 fields: baseCorrectParams,
231 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
236 describe('When updating video channel avatar/banner', function () {
237 const types = [ 'avatar', 'banner' ]
240 before(async function () {
241 path = videoChannelPath + '/super_channel'
244 it('Should fail with an incorrect input file', async function () {
245 for (const type of types) {
248 [type + 'file']: buildAbsoluteFixturePath('video_short.mp4')
251 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
255 it('Should fail with a big file', async function () {
256 for (const type of types) {
259 [type + 'file']: buildAbsoluteFixturePath('avatar-big.png')
261 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
265 it('Should fail with an unauthenticated user', async function () {
266 for (const type of types) {
269 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
271 await makeUploadRequest({
273 path: `${path}/${type}/pick`,
276 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
281 it('Should succeed with the correct params', async function () {
282 for (const type of types) {
285 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
287 await makeUploadRequest({
289 path: `${path}/${type}/pick`,
290 token: server.accessToken,
293 statusCodeExpected: HttpStatusCode.OK_200
299 describe('When getting a video channel', function () {
300 it('Should return the list of the video channels with nothing', async function () {
301 const res = await makeGetRequest({
303 path: videoChannelPath,
304 statusCodeExpected: HttpStatusCode.OK_200
307 expect(res.body.data).to.be.an('array')
310 it('Should return 404 with an incorrect video channel', async function () {
311 await makeGetRequest({
313 path: videoChannelPath + '/super_channel2',
314 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
318 it('Should succeed with the correct parameters', async function () {
319 await makeGetRequest({
321 path: videoChannelPath + '/super_channel',
322 statusCodeExpected: HttpStatusCode.OK_200
327 describe('When deleting a video channel', function () {
328 it('Should fail with a non authenticated user', async function () {
329 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
332 it('Should fail with another authenticated user', async function () {
333 await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
336 it('Should fail with an unknown video channel id', async function () {
337 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
340 it('Should succeed with the correct parameters', async function () {
341 await command.delete({ channelName: 'super_channel' })
344 it('Should fail to delete the last user video channel', async function () {
345 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
349 after(async function () {
350 await cleanupTests([ server ])