1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
4 import { join } from 'path'
6 import * as chai from 'chai'
7 const expect = chai.expect
14 setAccessTokensToServers,
23 describe('Test videos API validator', function () {
24 const path = '/api/v1/videos/channels'
25 let server: ServerInfo
27 let accessTokenUser: string
29 // ---------------------------------------------------------------
31 before(async function () {
36 server = await runServer(1)
38 await setAccessTokensToServers([ server ])
40 const res = await getMyUserInformation(server.url, server.accessToken)
41 channelId = res.body.videoChannels[0].id
45 password: 'fake_password'
47 await createUser(server.url, server.accessToken, user.username, user.password)
49 accessTokenUser = await getUserAccessToken(server, user)
52 describe('When listing a video channels', function () {
53 it('Should fail with a bad start pagination', async function () {
54 await request(server.url)
56 .query({ start: 'hello' })
57 .set('Accept', 'application/json')
61 it('Should fail with a bad count pagination', async function () {
62 await request(server.url)
64 .query({ count: 'hello' })
65 .set('Accept', 'application/json')
69 it('Should fail with an incorrect sort', async function () {
70 await request(server.url)
72 .query({ sort: 'hello' })
73 .set('Accept', 'application/json')
78 describe('When listing author video channels', function () {
79 it('Should fail with bad author', async function () {
80 const path = '/api/v1/videos/authors/hello/channels'
82 await request(server.url)
84 .set('Accept', 'application/json')
88 it('Should fail with a unknown author', async function () {
89 const path = '/api/v1/videos/authors/156/channels'
91 await request(server.url)
93 .set('Accept', 'application/json')
98 describe('When adding a video channel', function () {
100 it('Should fail with a non authenticated user', async function () {
103 description: 'super description'
105 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
108 it('Should fail with nothing', async function () {
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
113 it('Should fail without name', async function () {
115 description: 'super description'
117 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 it('Should fail with a long name', async function () {
122 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
123 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
124 description: 'super description'
126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 it('Should fail with a long description', async function () {
132 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
133 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
134 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
135 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
137 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
140 it('Should succeed with the correct parameters', async function () {
143 description: 'super description'
145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
149 describe('When updating a video channel', function () {
152 before(async function () {
153 const res = await getVideoChannelsList(server.url, 0, 1)
154 videoChannelId = res.body.data[0].id
157 it('Should fail with a non authenticated user', async function () {
160 description: 'super description'
162 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
165 it('Should fail with another authenticated user', async function () {
168 description: 'super description'
170 await makePutBodyRequest({
172 path: path + '/' + videoChannelId,
173 token: accessTokenUser,
175 statusCodeExpected: 403
179 it('Should fail with a long name', async function () {
181 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
182 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
183 description: 'super description'
185 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
188 it('Should fail with a long description', async function () {
191 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
192 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
193 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
194 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
196 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
199 it('Should succeed with the correct parameters', async function () {
202 description: 'super description 2'
204 await makePutBodyRequest({
206 path: path + '/' + videoChannelId,
207 token: server.accessToken,
209 statusCodeExpected: 204
214 describe('When getting a video channel', function () {
215 let videoChannelId: number
217 before(async function () {
218 const res = await getVideoChannelsList(server.url, 0, 1)
219 videoChannelId = res.body.data[0].id
222 it('Should return the list of the video channels with nothing', async function () {
223 const res = await request(server.url)
225 .set('Accept', 'application/json')
227 .expect('Content-Type', /json/)
229 expect(res.body.data).to.be.an('array')
232 it('Should fail without a correct uuid', async function () {
233 await request(server.url)
234 .get(path + '/coucou')
235 .set('Accept', 'application/json')
239 it('Should return 404 with an incorrect video channel', async function () {
240 await request(server.url)
241 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06')
242 .set('Accept', 'application/json')
246 it('Should succeed with the correct parameters', async function () {
247 await request(server.url)
248 .get(path + '/' + videoChannelId)
249 .set('Accept', 'application/json')
254 describe('When deleting a video channel', function () {
255 let videoChannelId: number
257 before(async function () {
258 const res = await getVideoChannelsList(server.url, 0, 1)
259 videoChannelId = res.body.data[0].id
262 it('Should fail with a non authenticated user', async function () {
263 await request(server.url)
264 .delete(path + '/' + videoChannelId)
265 .set('Authorization', 'Bearer coucou')
269 it('Should fail with another authenticated user', async function () {
270 await request(server.url)
271 .delete(path + '/' + videoChannelId)
272 .set('Authorization', 'Bearer ' + accessTokenUser)
276 it('Should fail with an unknown id', async function () {
277 await request(server.url)
278 .delete(path + '/454554')
279 .set('Authorization', 'Bearer ' + server.accessToken)
283 it('Should succeed with the correct parameters', async function () {
284 await request(server.url)
285 .delete(path + '/' + videoChannelId)
286 .set('Authorization', 'Bearer ' + server.accessToken)
290 it('Should fail to delete the last user video channel', async function () {
291 const res = await getVideoChannelsList(server.url, 0, 1)
292 videoChannelId = res.body.data[0].id
294 await request(server.url)
295 .delete(path + '/' + videoChannelId)
296 .set('Authorization', 'Bearer ' + server.accessToken)
302 after(async function () {
303 killallServers([ server ])
305 // Keep the logs if the test failed