1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
7 createUser, deleteVideoChannel, flushTests, getAccountVideoChannelsList, getVideoChannelsList, immutableAssign, killallServers,
8 makeGetRequest, makePostBodyRequest, makePutBodyRequest, runServer, ServerInfo, setAccessTokensToServers, userLogin
10 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
12 const expect = chai.expect
14 describe('Test videos API validator', function () {
15 const path = '/api/v1/videos/channels'
16 let server: ServerInfo
17 let accessTokenUser: string
19 // ---------------------------------------------------------------
21 before(async function () {
26 server = await runServer(1)
28 await setAccessTokensToServers([ server ])
32 password: 'fake_password'
34 await createUser(server.url, server.accessToken, user.username, user.password)
35 accessTokenUser = await userLogin(server, user)
38 describe('When listing a video channels', function () {
39 it('Should fail with a bad start pagination', async function () {
40 await checkBadStartPagination(server.url, path, server.accessToken)
43 it('Should fail with a bad count pagination', async function () {
44 await checkBadCountPagination(server.url, path, server.accessToken)
47 it('Should fail with an incorrect sort', async function () {
48 await checkBadSortPagination(server.url, path, server.accessToken)
52 describe('When listing account video channels', function () {
53 it('Should fail with bad account', async function () {
54 await getAccountVideoChannelsList(server.url, 'hello', 400)
57 it('Should fail with a unknown account', async function () {
58 await getAccountVideoChannelsList(server.url, 154, 404)
62 describe('When adding a video channel', function () {
63 const baseCorrectParams = {
65 description: 'super description'
68 it('Should fail with a non authenticated user', async function () {
69 await makePostBodyRequest({ url: server.url, path, token: 'none', fields: baseCorrectParams, statusCodeExpected: 401 })
72 it('Should fail with nothing', async function () {
74 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
77 it('Should fail without name', async function () {
78 const fields = omit(baseCorrectParams, 'name')
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
82 it('Should fail with a long name', async function () {
83 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
87 it('Should fail with a long description', async function () {
88 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
89 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
92 it('Should succeed with the correct parameters', async function () {
93 await makePostBodyRequest({
96 token: server.accessToken,
97 fields: baseCorrectParams,
98 statusCodeExpected: 204
103 describe('When updating a video channel', function () {
104 const baseCorrectParams = {
106 description: 'super description'
111 before(async function () {
112 const res = await getVideoChannelsList(server.url, 0, 1)
113 videoChannelId = res.body.data[0].id
116 it('Should fail with a non authenticated user', async function () {
117 await makePutBodyRequest({
119 path: path + '/' + videoChannelId,
121 fields: baseCorrectParams,
122 statusCodeExpected: 401
126 it('Should fail with another authenticated user', async function () {
127 await makePutBodyRequest({
129 path: path + '/' + videoChannelId,
130 token: accessTokenUser,
131 fields: baseCorrectParams,
132 statusCodeExpected: 403
136 it('Should fail with a long name', async function () {
137 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(25) })
138 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
141 it('Should fail with a long description', async function () {
142 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(60) })
143 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
146 it('Should succeed with the correct parameters', async function () {
147 await makePutBodyRequest({
149 path: path + '/' + videoChannelId,
150 token: server.accessToken,
151 fields: baseCorrectParams,
152 statusCodeExpected: 204
157 describe('When getting a video channel', function () {
158 let videoChannelId: number
160 before(async function () {
161 const res = await getVideoChannelsList(server.url, 0, 1)
162 videoChannelId = res.body.data[0].id
165 it('Should return the list of the video channels with nothing', async function () {
166 const res = await makeGetRequest({
169 statusCodeExpected: 200
172 expect(res.body.data).to.be.an('array')
175 it('Should fail without a correct uuid', async function () {
176 await makeGetRequest({
178 path: path + '/coucou',
179 statusCodeExpected: 400
183 it('Should return 404 with an incorrect video channel', async function () {
184 await makeGetRequest({
186 path: path + '/4da6fde3-88f7-4d16-b119-108df5630b06',
187 statusCodeExpected: 404
191 it('Should succeed with the correct parameters', async function () {
192 await makeGetRequest({
194 path: path + '/' + videoChannelId,
195 statusCodeExpected: 200
200 describe('When deleting a video channel', function () {
201 let videoChannelId: number
203 before(async function () {
204 const res = await getVideoChannelsList(server.url, 0, 1)
205 videoChannelId = res.body.data[0].id
208 it('Should fail with a non authenticated user', async function () {
209 await deleteVideoChannel(server.url, 'coucou', videoChannelId, 401)
212 it('Should fail with another authenticated user', async function () {
213 await deleteVideoChannel(server.url, accessTokenUser, videoChannelId, 403)
216 it('Should fail with an unknown id', async function () {
217 await deleteVideoChannel(server.url, server.accessToken, 454554, 404)
220 it('Should succeed with the correct parameters', async function () {
221 await deleteVideoChannel(server.url, server.accessToken, videoChannelId)
224 it('Should fail to delete the last user video channel', async function () {
225 const res = await getVideoChannelsList(server.url, 0, 1)
226 videoChannelId = res.body.data[0].id
228 await deleteVideoChannel(server.url, server.accessToken, videoChannelId, 409)
232 after(async function () {
233 killallServers([ server ])
235 // Keep the logs if the test failed