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
22 } from '@shared/extra-utils'
23 import { VideoChannelUpdate } from '@shared/models'
25 const expect = chai.expect
27 describe('Test video channels API validator', function () {
28 const videoChannelPath = '/api/v1/video-channels'
29 let server: ServerInfo
30 let accessTokenUser: string
31 let command: ChannelsCommand
33 // ---------------------------------------------------------------
35 before(async function () {
38 server = await flushAndRunServer(1)
40 await setAccessTokensToServers([ server ])
44 password: 'fake_password'
48 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
49 accessTokenUser = await server.loginCommand.getAccessToken(user)
52 command = server.channelsCommand
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 server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
88 it('Should succeed with the correct parameters', async function () {
89 await makeGetRequest({
91 path: accountChannelPath,
92 statusCodeExpected: HttpStatusCode.OK_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: HttpStatusCode.UNAUTHORIZED_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 = { ...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 = { ...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 = { ...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 = { ...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: HttpStatusCode.OK_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: HttpStatusCode.CONFLICT_409
171 describe('When updating a video channel', function () {
172 const baseCorrectParams: VideoChannelUpdate = {
173 displayName: 'hello',
174 description: 'super description',
176 bulkVideosSupportUpdate: false
180 before(async function () {
181 path = videoChannelPath + '/super_channel'
184 it('Should fail with a non authenticated user', async function () {
185 await makePutBodyRequest({
189 fields: baseCorrectParams,
190 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
194 it('Should fail with another authenticated user', async function () {
195 await makePutBodyRequest({
198 token: accessTokenUser,
199 fields: baseCorrectParams,
200 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
204 it('Should fail with a long name', async function () {
205 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
206 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
209 it('Should fail with a long description', async function () {
210 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
211 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
214 it('Should fail with a long support text', async function () {
215 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
216 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
219 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
220 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
221 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 it('Should succeed with the correct parameters', async function () {
225 await makePutBodyRequest({
228 token: server.accessToken,
229 fields: baseCorrectParams,
230 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
235 describe('When updating video channel avatar/banner', function () {
236 const types = [ 'avatar', 'banner' ]
239 before(async function () {
240 path = videoChannelPath + '/super_channel'
243 it('Should fail with an incorrect input file', async function () {
244 for (const type of types) {
247 [type + 'file']: buildAbsoluteFixturePath('video_short.mp4')
250 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
254 it('Should fail with a big file', async function () {
255 for (const type of types) {
258 [type + 'file']: buildAbsoluteFixturePath('avatar-big.png')
260 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
264 it('Should fail with an unauthenticated user', async function () {
265 for (const type of types) {
268 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
270 await makeUploadRequest({
272 path: `${path}/${type}/pick`,
275 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
280 it('Should succeed with the correct params', async function () {
281 for (const type of types) {
284 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
286 await makeUploadRequest({
288 path: `${path}/${type}/pick`,
289 token: server.accessToken,
292 statusCodeExpected: HttpStatusCode.OK_200
298 describe('When getting a video channel', function () {
299 it('Should return the list of the video channels with nothing', async function () {
300 const res = await makeGetRequest({
302 path: videoChannelPath,
303 statusCodeExpected: HttpStatusCode.OK_200
306 expect(res.body.data).to.be.an('array')
309 it('Should return 404 with an incorrect video channel', async function () {
310 await makeGetRequest({
312 path: videoChannelPath + '/super_channel2',
313 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
317 it('Should succeed with the correct parameters', async function () {
318 await makeGetRequest({
320 path: videoChannelPath + '/super_channel',
321 statusCodeExpected: HttpStatusCode.OK_200
326 describe('When deleting a video channel', function () {
327 it('Should fail with a non authenticated user', async function () {
328 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
331 it('Should fail with another authenticated user', async function () {
332 await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
335 it('Should fail with an unknown video channel id', async function () {
336 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
339 it('Should succeed with the correct parameters', async function () {
340 await command.delete({ channelName: 'super_channel' })
343 it('Should fail to delete the last user video channel', async function () {
344 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
348 after(async function () {
349 await cleanupTests([ server ])