1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
5 import * as chai from 'chai'
6 const expect = chai.expect
13 setAccessTokensToServers,
21 describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/channels'
23 let server: ServerInfo
24 let accessTokenUser: string
26 // ---------------------------------------------------------------
28 before(async function () {
33 server = await runServer(1)
35 await setAccessTokensToServers([ server ])
39 password: 'fake_password'
41 await createUser(server.url, server.accessToken, user.username, user.password)
43 accessTokenUser = await getUserAccessToken(server, user)
46 describe('When listing a video channels', function () {
47 it('Should fail with a bad start pagination', async function () {
48 await request(server.url)
50 .query({ start: 'hello' })
51 .set('Accept', 'application/json')
55 it('Should fail with a bad count pagination', async function () {
56 await request(server.url)
58 .query({ count: 'hello' })
59 .set('Accept', 'application/json')
63 it('Should fail with an incorrect sort', async function () {
64 await request(server.url)
66 .query({ sort: 'hello' })
67 .set('Accept', 'application/json')
72 describe('When listing author video channels', function () {
73 it('Should fail with bad author', async function () {
74 const path = '/api/v1/videos/authors/hello/channels'
76 await request(server.url)
78 .set('Accept', 'application/json')
82 it('Should fail with a unknown author', async function () {
83 const path = '/api/v1/videos/authors/156/channels'
85 await request(server.url)
87 .set('Accept', 'application/json')
92 describe('When adding a video channel', function () {
94 it('Should fail with a non authenticated user', async function () {
97 description: 'super description'
99 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
102 it('Should fail with nothing', async function () {
104 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
107 it('Should fail without name', async function () {
109 description: 'super description'
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 it('Should fail with a long name', async function () {
116 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
117 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
118 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
119 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
120 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
121 description: 'super description'
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 it('Should fail with a long description', async function () {
129 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
130 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
131 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
132 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
137 it('Should succeed with the correct parameters', async function () {
140 description: 'super description'
142 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
146 describe('When updating a video channel', function () {
149 before(async function () {
150 const res = await getVideoChannelsList(server.url, 0, 1)
151 videoChannelId = res.body.data[0].id
154 it('Should fail with a non authenticated user', async function () {
157 description: 'super description'
159 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
162 it('Should fail with another authenticated user', async function () {
165 description: 'super description'
167 await makePutBodyRequest({
169 path: path + '/' + videoChannelId,
170 token: accessTokenUser,
172 statusCodeExpected: 403
176 it('Should fail with a long name', async function () {
178 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
179 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
180 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
181 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
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