1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
21 setAccessTokensToServers,
24 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
25 import { User } from '../../../../shared/models/users'
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
34 let videoChannelUUID: string
36 // ---------------------------------------------------------------
38 before(async function () {
43 server = await runServer(1)
45 await setAccessTokensToServers([ server ])
49 password: 'fake_password'
53 await createUser(server.url, server.accessToken, user.username, user.password)
54 accessTokenUser = await userLogin(server, user)
58 const res = await getMyUserInformation(server.url, server.accessToken)
59 const user: User = res.body
60 videoChannelUUID = user.videoChannels[0].uuid
64 describe('When listing a video channels', function () {
65 it('Should fail with a bad start pagination', async function () {
66 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
69 it('Should fail with a bad count pagination', async function () {
70 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
73 it('Should fail with an incorrect sort', async function () {
74 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
78 describe('When listing account video channels', function () {
79 it('Should fail with a unknown account', async function () {
80 await getAccountVideoChannelsList(server.url, 'unknown', 404)
84 describe('When adding a video channel', function () {
85 const baseCorrectParams = {
87 description: 'super description',
88 support: 'super support text'
91 it('Should fail with a non authenticated user', async function () {
92 await makePostBodyRequest({
94 path: videoChannelPath,
96 fields: baseCorrectParams,
97 statusCodeExpected: 401
101 it('Should fail with nothing', async function () {
103 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
106 it('Should fail without a name', async function () {
107 const fields = omit(baseCorrectParams, 'displayName')
108 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
111 it('Should fail with a long name', async function () {
112 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
113 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
116 it('Should fail with a long description', async function () {
117 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
118 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
121 it('Should fail with a long support text', async function () {
122 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
123 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
126 it('Should succeed with the correct parameters', async function () {
127 await makePostBodyRequest({
129 path: videoChannelPath,
130 token: server.accessToken,
131 fields: baseCorrectParams,
132 statusCodeExpected: 200
137 describe('When updating a video channel', function () {
138 const baseCorrectParams = {
139 displayName: 'hello',
140 description: 'super description'
144 before(async function () {
145 path = videoChannelPath + '/' + videoChannelUUID
148 it('Should fail with a non authenticated user', async function () {
149 await makePutBodyRequest({
153 fields: baseCorrectParams,
154 statusCodeExpected: 401
158 it('Should fail with another authenticated user', async function () {
159 await makePutBodyRequest({
162 token: accessTokenUser,
163 fields: baseCorrectParams,
164 statusCodeExpected: 403
168 it('Should fail with a long name', async function () {
169 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
170 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
173 it('Should fail with a long description', async function () {
174 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
175 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
178 it('Should fail with a long support text', async function () {
179 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
180 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
183 it('Should succeed with the correct parameters', async function () {
184 await makePutBodyRequest({
187 token: server.accessToken,
188 fields: baseCorrectParams,
189 statusCodeExpected: 204
194 describe('When updating video channel avatar', function () {
197 before(async function () {
198 path = videoChannelPath + '/' + videoChannelUUID
201 it('Should fail with an incorrect input file', async function () {
204 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
206 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
209 it('Should fail with a big file', async function () {
212 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
214 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
217 it('Should fail with an unauthenticated user', async function () {
220 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
222 await makeUploadRequest({
224 path: path + '/avatar/pick',
227 statusCodeExpected: 401
231 it('Should succeed with the correct params', async function () {
234 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
236 await makeUploadRequest({
238 path: path + '/avatar/pick',
239 token: server.accessToken,
242 statusCodeExpected: 200
247 describe('When getting a video channel', function () {
248 it('Should return the list of the video channels with nothing', async function () {
249 const res = await makeGetRequest({
251 path: videoChannelPath,
252 statusCodeExpected: 200
255 expect(res.body.data).to.be.an('array')
258 it('Should fail without a correct uuid', async function () {
259 await makeGetRequest({
261 path: videoChannelPath + '/coucou',
262 statusCodeExpected: 400
266 it('Should return 404 with an incorrect video channel', async function () {
267 await makeGetRequest({
269 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
270 statusCodeExpected: 404
274 it('Should succeed with the correct parameters', async function () {
275 await makeGetRequest({
277 path: videoChannelPath + '/' + videoChannelUUID,
278 statusCodeExpected: 200
283 describe('When deleting a video channel', function () {
284 it('Should fail with a non authenticated user', async function () {
285 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
288 it('Should fail with another authenticated user', async function () {
289 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
292 it('Should fail with an unknown video channel id', async function () {
293 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
296 it('Should succeed with the correct parameters', async function () {
297 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
300 it('Should fail to delete the last user video channel', async function () {
301 const res = await getVideoChannelsList(server.url, 0, 1)
302 const lastVideoChannelUUID = res.body.data[0].uuid
304 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
308 after(async function () {
309 killallServers([ server ])
311 // Keep the logs if the test failed