1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
10 getAccountVideoChannelsList,
19 setAccessTokensToServers,
22 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23 import { getAccountsList } from '../../utils/users/accounts'
25 const expect = chai.expect
27 describe('Test videos API validator', function () {
28 const videoChannelPath = '/api/v1/video-channels'
29 const accountPath = '/api/v1/accounts/'
30 let server: ServerInfo
31 let accessTokenUser: string
33 // ---------------------------------------------------------------
35 before(async function () {
40 server = await runServer(1)
42 await setAccessTokensToServers([ server ])
46 password: 'fake_password'
48 await createUser(server.url, server.accessToken, user.username, user.password)
49 accessTokenUser = await userLogin(server, user)
52 describe('When listing a video channels', function () {
53 it('Should fail with a bad start pagination', async function () {
54 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
57 it('Should fail with a bad count pagination', async function () {
58 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
61 it('Should fail with an incorrect sort', async function () {
62 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
66 describe('When listing account video channels', function () {
67 it('Should fail with bad account', async function () {
68 await getAccountVideoChannelsList(server.url, 'hello', 400)
71 it('Should fail with a unknown account', async function () {
72 await getAccountVideoChannelsList(server.url, 154, 404)
76 describe('When adding a video channel', function () {
79 const baseCorrectParams = {
81 description: 'super description',
82 support: 'super support text'
85 before(async function () {
86 const res = await getAccountsList(server.url)
87 const accountId = res.body.data[0].id
88 path = accountPath + accountId + '/video-channels'
91 it('Should fail with a non authenticated user', async function () {
92 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
95 it('Should fail with nothing', async function () {
97 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
100 it('Should fail without name', async function () {
101 const fields = omit(baseCorrectParams, 'name')
102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
105 it('Should fail with a long name', async function () {
106 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
110 it('Should fail with a long description', async function () {
111 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
112 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
115 it('Should fail with a long support text', async function () {
116 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should succeed with the correct parameters', async function () {
121 await makePostBodyRequest({
124 token: server.accessToken,
125 fields: baseCorrectParams,
126 statusCodeExpected: 200
131 describe('When updating a video channel', function () {
134 const baseCorrectParams = {
136 description: 'super description'
139 before(async function () {
140 const res1 = await getVideoChannelsList(server.url, 0, 1)
141 const videoChannelId = res1.body.data[0].id
143 const res2 = await getAccountsList(server.url)
144 const accountId = res2.body.data[0].id
146 path = accountPath + accountId + '/video-channels/' + videoChannelId
149 it('Should fail with a non authenticated user', async function () {
150 await makePutBodyRequest({
154 fields: baseCorrectParams,
155 statusCodeExpected: 401
159 it('Should fail with another authenticated user', async function () {
160 await makePutBodyRequest({
163 token: accessTokenUser,
164 fields: baseCorrectParams,
165 statusCodeExpected: 403
169 it('Should fail with a long name', async function () {
170 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
171 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
174 it('Should fail with a long description', async function () {
175 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
176 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
179 it('Should fail with a long support text', async function () {
180 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
181 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
184 it('Should succeed with the correct parameters', async function () {
185 await makePutBodyRequest({
188 token: server.accessToken,
189 fields: baseCorrectParams,
190 statusCodeExpected: 204
195 describe('When getting a video channel', function () {
197 let videoChannelId: number
199 before(async function () {
200 const res1 = await getVideoChannelsList(server.url, 0, 1)
201 videoChannelId = res1.body.data[0].id
203 const res2 = await getAccountsList(server.url)
204 const accountId = res2.body.data[0].id
206 basePath = accountPath + accountId + '/video-channels'
209 it('Should return the list of the video channels with nothing', async function () {
210 const res = await makeGetRequest({
213 statusCodeExpected: 200
216 expect(res.body.data).to.be.an('array')
219 it('Should fail without a correct uuid', async function () {
220 await makeGetRequest({
222 path: basePath + '/coucou',
223 statusCodeExpected: 400
227 it('Should return 404 with an incorrect video channel', async function () {
228 await makeGetRequest({
230 path: basePath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
231 statusCodeExpected: 404
235 it('Should succeed with the correct parameters', async function () {
236 await makeGetRequest({
238 path: basePath + '/' + videoChannelId,
239 statusCodeExpected: 200
244 describe('When deleting a video channel', function () {
245 let videoChannelId: number
246 let accountId: number
248 before(async function () {
249 const res1 = await getVideoChannelsList(server.url, 0, 1)
250 videoChannelId = res1.body.data[0].id
252 const res2 = await getAccountsList(server.url)
253 accountId = res2.body.data[0].id
256 it('Should fail with a non authenticated user', async function () {
257 await deleteVideoChannel(server.url, 'coucou', accountId, videoChannelId, 401)
260 it('Should fail with another authenticated user', async function () {
261 await deleteVideoChannel(server.url, accessTokenUser, accountId, videoChannelId, 403)
264 it('Should fail with an unknown account id', async function () {
265 await deleteVideoChannel(server.url, server.accessToken, 454554,videoChannelId, 404)
268 it('Should fail with an unknown video channel id', async function () {
269 await deleteVideoChannel(server.url, server.accessToken, accountId,454554, 404)
272 it('Should succeed with the correct parameters', async function () {
273 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId)
276 it('Should fail to delete the last user video channel', async function () {
277 const res = await getVideoChannelsList(server.url, 0, 1)
278 videoChannelId = res.body.data[0].id
280 await deleteVideoChannel(server.url, server.accessToken, accountId, videoChannelId, 409)
284 after(async function () {
285 killallServers([ server ])
287 // Keep the logs if the test failed