1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
20 setAccessTokensToServers,
23 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
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 a unknown account', async function () {
78 await getAccountVideoChannelsList(server.url, 'unknown', 404)
82 describe('When adding a video channel', function () {
83 const baseCorrectParams = {
85 description: 'super description',
86 support: 'super support text'
89 it('Should fail with a non authenticated user', async function () {
90 await makePostBodyRequest({
92 path: videoChannelPath,
94 fields: baseCorrectParams,
95 statusCodeExpected: 401
99 it('Should fail with nothing', async function () {
101 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
104 it('Should fail without a name', async function () {
105 const fields = omit(baseCorrectParams, 'displayName')
106 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
109 it('Should fail with a long name', async function () {
110 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
111 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
114 it('Should fail with a long description', async function () {
115 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
116 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
119 it('Should fail with a long support text', async function () {
120 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
121 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
124 it('Should succeed with the correct parameters', async function () {
125 await makePostBodyRequest({
127 path: videoChannelPath,
128 token: server.accessToken,
129 fields: baseCorrectParams,
130 statusCodeExpected: 200
135 describe('When updating a video channel', function () {
136 const baseCorrectParams = {
137 displayName: 'hello',
138 description: 'super description'
142 before(async function () {
143 path = videoChannelPath + '/' + videoChannelUUID
146 it('Should fail with a non authenticated user', async function () {
147 await makePutBodyRequest({
151 fields: baseCorrectParams,
152 statusCodeExpected: 401
156 it('Should fail with another authenticated user', async function () {
157 await makePutBodyRequest({
160 token: accessTokenUser,
161 fields: baseCorrectParams,
162 statusCodeExpected: 403
166 it('Should fail with a long name', async function () {
167 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
168 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
171 it('Should fail with a long description', async function () {
172 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
173 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
176 it('Should fail with a long support text', async function () {
177 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
178 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 it('Should succeed with the correct parameters', async function () {
182 await makePutBodyRequest({
185 token: server.accessToken,
186 fields: baseCorrectParams,
187 statusCodeExpected: 204
192 describe('When getting a video channel', function () {
193 it('Should return the list of the video channels with nothing', async function () {
194 const res = await makeGetRequest({
196 path: videoChannelPath,
197 statusCodeExpected: 200
200 expect(res.body.data).to.be.an('array')
203 it('Should fail without a correct uuid', async function () {
204 await makeGetRequest({
206 path: videoChannelPath + '/coucou',
207 statusCodeExpected: 400
211 it('Should return 404 with an incorrect video channel', async function () {
212 await makeGetRequest({
214 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
215 statusCodeExpected: 404
219 it('Should succeed with the correct parameters', async function () {
220 await makeGetRequest({
222 path: videoChannelPath + '/' + videoChannelUUID,
223 statusCodeExpected: 200
228 describe('When deleting a video channel', function () {
229 it('Should fail with a non authenticated user', async function () {
230 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
233 it('Should fail with another authenticated user', async function () {
234 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
237 it('Should fail with an unknown video channel id', async function () {
238 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
241 it('Should succeed with the correct parameters', async function () {
242 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
245 it('Should fail to delete the last user video channel', async function () {
246 const res = await getVideoChannelsList(server.url, 0, 1)
247 const lastVideoChannelUUID = res.body.data[0].uuid
249 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
253 after(async function () {
254 killallServers([ server ])
256 // Keep the logs if the test failed