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 videos API validator', function () {
29 const videoChannelPath = '/api/v1/video-channels'
30 const accountPath = '/api/v1/accounts/'
31 let server: ServerInfo
32 let accessTokenUser: string
33 let accountUUID: 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 accountUUID = user.account.uuid
61 videoChannelUUID = user.videoChannels[0].uuid
65 describe('When listing a video channels', function () {
66 it('Should fail with a bad start pagination', async function () {
67 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
70 it('Should fail with a bad count pagination', async function () {
71 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
74 it('Should fail with an incorrect sort', async function () {
75 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
79 describe('When listing account video channels', function () {
80 it('Should fail with bad account', async function () {
81 await getAccountVideoChannelsList(server.url, 'hello', 400)
84 it('Should fail with a unknown account', async function () {
85 await getAccountVideoChannelsList(server.url, 154, 404)
89 describe('When adding a video channel', function () {
90 const baseCorrectParams = {
92 description: 'super description',
93 support: 'super support text'
97 before(async function () {
98 path = accountPath + accountUUID + '/video-channels'
101 it('Should fail with a non authenticated user', async function () {
102 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
105 it('Should fail with nothing', async function () {
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
110 it('Should fail without name', async function () {
111 const fields = omit(baseCorrectParams, 'name')
112 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 it('Should fail with a long name', async function () {
116 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should fail with a long description', async function () {
121 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
125 it('Should fail with a long support text', async function () {
126 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
130 it('Should succeed with the correct parameters', async function () {
131 await makePostBodyRequest({
134 token: server.accessToken,
135 fields: baseCorrectParams,
136 statusCodeExpected: 200
141 describe('When updating a video channel', function () {
142 const baseCorrectParams = {
144 description: 'super description'
148 before(async function () {
149 path = accountPath + accountUUID + '/video-channels/' + videoChannelUUID
152 it('Should fail with a non authenticated user', async function () {
153 await makePutBodyRequest({
157 fields: baseCorrectParams,
158 statusCodeExpected: 401
162 it('Should fail with another authenticated user', async function () {
163 await makePutBodyRequest({
166 token: accessTokenUser,
167 fields: baseCorrectParams,
168 statusCodeExpected: 403
172 it('Should fail with a long name', async function () {
173 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
174 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
177 it('Should fail with a long description', async function () {
178 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
179 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
182 it('Should fail with a long support text', async function () {
183 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
184 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 it('Should succeed with the correct parameters', async function () {
188 await makePutBodyRequest({
191 token: server.accessToken,
192 fields: baseCorrectParams,
193 statusCodeExpected: 204
198 describe('When getting a video channel', function () {
201 before(async function () {
202 basePath = accountPath + accountUUID + '/video-channels'
205 it('Should return the list of the video channels with nothing', async function () {
206 const res = await makeGetRequest({
209 statusCodeExpected: 200
212 expect(res.body.data).to.be.an('array')
215 it('Should fail without a correct uuid', async function () {
216 await makeGetRequest({
218 path: basePath + '/coucou',
219 statusCodeExpected: 400
223 it('Should return 404 with an incorrect video channel', async function () {
224 await makeGetRequest({
226 path: basePath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
227 statusCodeExpected: 404
231 it('Should succeed with the correct parameters', async function () {
232 await makeGetRequest({
234 path: basePath + '/' + videoChannelUUID,
235 statusCodeExpected: 200
240 describe('When deleting a video channel', function () {
241 it('Should fail with a non authenticated user', async function () {
242 await deleteVideoChannel(server.url, 'coucou', accountUUID, videoChannelUUID, 401)
245 it('Should fail with another authenticated user', async function () {
246 await deleteVideoChannel(server.url, accessTokenUser, accountUUID, videoChannelUUID, 403)
249 it('Should fail with an unknown account id', async function () {
250 await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelUUID, 404)
253 it('Should fail with an unknown video channel id', async function () {
254 await deleteVideoChannel(server.url, server.accessToken, accountUUID,454554, 404)
257 it('Should succeed with the correct parameters', async function () {
258 await deleteVideoChannel(server.url, server.accessToken, accountUUID, videoChannelUUID)
261 it('Should fail to delete the last user video channel', async function () {
262 const res = await getVideoChannelsList(server.url, 0, 1)
263 const lastVideoChannelUUID = res.body.data[0].uuid
265 await deleteVideoChannel(server.url, server.accessToken, accountUUID, lastVideoChannelUUID, 409)
269 after(async function () {
270 killallServers([ server ])
272 // Keep the logs if the test failed