1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList, getMyUserInformation,
19 setAccessTokensToServers,
22 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23 import { getAccountsList } from '../../utils/users/accounts'
24 import { User } from '../../../../shared/models/users'
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 videoChannelUUID: string
34 // ---------------------------------------------------------------
36 before(async function () {
41 server = await runServer(1)
43 await setAccessTokensToServers([ server ])
47 password: 'fake_password'
51 await createUser(server.url, server.accessToken, user.username, user.password)
52 accessTokenUser = await userLogin(server, user)
56 const res = await getMyUserInformation(server.url, server.accessToken)
57 const user: User = res.body
58 videoChannelUUID = user.videoChannels[0].uuid
62 describe('When listing a video channels', function () {
63 it('Should fail with a bad start pagination', async function () {
64 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
67 it('Should fail with a bad count pagination', async function () {
68 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
71 it('Should fail with an incorrect sort', async function () {
72 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
76 describe('When listing account video channels', function () {
77 it('Should fail with bad account', async function () {
78 await getAccountVideoChannelsList(server.url, 'hello', 400)
81 it('Should fail with a unknown account', async function () {
82 await getAccountVideoChannelsList(server.url, 154, 404)
86 describe('When adding a video channel', function () {
87 const baseCorrectParams = {
89 description: 'super description',
90 support: 'super support text'
93 it('Should fail with a non authenticated user', async function () {
94 await makePostBodyRequest({
96 path: videoChannelPath,
98 fields: baseCorrectParams,
99 statusCodeExpected: 401
103 it('Should fail with nothing', async function () {
105 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
108 it('Should fail without a name', async function () {
109 const fields = omit(baseCorrectParams, 'displayName')
110 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
113 it('Should fail with a long name', async function () {
114 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
115 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
118 it('Should fail with a long description', async function () {
119 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
120 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
123 it('Should fail with a long support text', async function () {
124 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
125 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
128 it('Should succeed with the correct parameters', async function () {
129 await makePostBodyRequest({
131 path: videoChannelPath,
132 token: server.accessToken,
133 fields: baseCorrectParams,
134 statusCodeExpected: 200
139 describe('When updating a video channel', function () {
140 const baseCorrectParams = {
141 displayName: 'hello',
142 description: 'super description'
146 before(async function () {
147 path = videoChannelPath + '/' + videoChannelUUID
150 it('Should fail with a non authenticated user', async function () {
151 await makePutBodyRequest({
155 fields: baseCorrectParams,
156 statusCodeExpected: 401
160 it('Should fail with another authenticated user', async function () {
161 await makePutBodyRequest({
164 token: accessTokenUser,
165 fields: baseCorrectParams,
166 statusCodeExpected: 403
170 it('Should fail with a long name', async function () {
171 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
172 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
175 it('Should fail with a long description', async function () {
176 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
177 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
180 it('Should fail with a long support text', async function () {
181 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
182 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
185 it('Should succeed with the correct parameters', async function () {
186 await makePutBodyRequest({
189 token: server.accessToken,
190 fields: baseCorrectParams,
191 statusCodeExpected: 204
196 describe('When getting a video channel', function () {
197 it('Should return the list of the video channels with nothing', async function () {
198 const res = await makeGetRequest({
200 path: videoChannelPath,
201 statusCodeExpected: 200
204 expect(res.body.data).to.be.an('array')
207 it('Should fail without a correct uuid', async function () {
208 await makeGetRequest({
210 path: videoChannelPath + '/coucou',
211 statusCodeExpected: 400
215 it('Should return 404 with an incorrect video channel', async function () {
216 await makeGetRequest({
218 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
219 statusCodeExpected: 404
223 it('Should succeed with the correct parameters', async function () {
224 await makeGetRequest({
226 path: videoChannelPath + '/' + videoChannelUUID,
227 statusCodeExpected: 200
232 describe('When deleting a video channel', function () {
233 it('Should fail with a non authenticated user', async function () {
234 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
237 it('Should fail with another authenticated user', async function () {
238 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
241 it('Should fail with an unknown video channel id', async function () {
242 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
245 it('Should succeed with the correct parameters', async function () {
246 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
249 it('Should fail to delete the last user video channel', async function () {
250 const res = await getVideoChannelsList(server.url, 0, 1)
251 const lastVideoChannelUUID = res.body.data[0].uuid
253 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
257 after(async function () {
258 killallServers([ server ])
260 // Keep the logs if the test failed