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,
22 describe('Test videos API validator', function () {
23 const path = '/api/v1/videos/channels'
24 let server: ServerInfo
26 let accessTokenUser: string
28 // ---------------------------------------------------------------
30 before(async function () {
35 server = await runServer(1)
37 await setAccessTokensToServers([ server ])
39 const res = await getMyUserInformation(server.url, server.accessToken)
40 channelId = res.body.videoChannels[0].id
44 password: 'fake_password'
46 await createUser(server.url, server.accessToken, user.username, user.password)
48 accessTokenUser = await getUserAccessToken(server, user)
51 describe('When listing a video channels', function () {
52 it('Should fail with a bad start pagination', async function () {
53 await request(server.url)
55 .query({ start: 'hello' })
56 .set('Accept', 'application/json')
60 it('Should fail with a bad count pagination', async function () {
61 await request(server.url)
63 .query({ count: 'hello' })
64 .set('Accept', 'application/json')
68 it('Should fail with an incorrect sort', async function () {
69 await request(server.url)
71 .query({ sort: 'hello' })
72 .set('Accept', 'application/json')
77 describe('When listing author video channels', function () {
78 it('Should fail with bad author', async function () {
79 const path = '/api/v1/videos/authors/hello/channels'
81 await request(server.url)
83 .set('Accept', 'application/json')
87 it('Should fail with a unknown author', async function () {
88 const path = '/api/v1/videos/authors/156/channels'
90 await request(server.url)
92 .set('Accept', 'application/json')
97 describe('When adding a video channel', function () {
99 it('Should fail with a non authenticated user', async function () {
102 description: 'super description'
104 await makePostBodyRequest({ url: server.url, path, token: 'none', fields, statusCodeExpected: 401 })
107 it('Should fail with nothing', async function () {
109 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 it('Should fail without name', async function () {
114 description: 'super description'
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
119 it('Should fail with a long name', async function () {
121 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
122 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
123 description: 'super description'
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
128 it('Should fail with a long description', async function () {
131 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
132 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
133 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
134 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
136 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
139 it('Should succeed with the correct parameters', async function () {
142 description: 'super description'
144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
148 describe('When updating a video channel', function () {
151 before(async function () {
152 const res = await getVideoChannelsList(server.url, 0, 1)
153 videoChannelId = res.body.data[0].id
156 it('Should fail with a non authenticated user', async function () {
159 description: 'super description'
161 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
164 it('Should fail with another authenticated user', async function () {
167 description: 'super description'
169 await makePutBodyRequest({
171 path: path + '/' + videoChannelId,
172 token: accessTokenUser,
174 statusCodeExpected: 403
178 it('Should fail with a long name', async function () {
180 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
181 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
182 description: 'super description'
184 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
187 it('Should fail with a long description', async function () {
190 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
191 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
192 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
193 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
195 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
198 it('Should succeed with the correct parameters', async function () {
201 description: 'super description 2'
203 await makePutBodyRequest({
205 path: path + '/' + videoChannelId,
206 token: server.accessToken,
208 statusCodeExpected: 204
213 describe('When getting a video channel', function () {
214 let videoChannelId: number
216 before(async function () {
217 const res = await getVideoChannelsList(server.url, 0, 1)
218 videoChannelId = res.body.data[0].id
221 it('Should return the list of the video channels with nothing', async function () {
222 const res = await request(server.url)
224 .set('Accept', 'application/json')
226 .expect('Content-Type', /json/)
228 expect(res.body.data).to.be.an('array')
231 it('Should fail without a correct uuid', async function () {
232 await request(server.url)
233 .get(path + '/coucou')
234 .set('Accept', 'application/json')
238 it('Should return 404 with an incorrect video channel', async function () {
239 await request(server.url)
240 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06')
241 .set('Accept', 'application/json')
245 it('Should succeed with the correct parameters', async function () {
246 await request(server.url)
247 .get(path + '/' + videoChannelId)
248 .set('Accept', 'application/json')
253 describe('When deleting a video channel', function () {
254 let videoChannelId: number
256 before(async function () {
257 const res = await getVideoChannelsList(server.url, 0, 1)
258 videoChannelId = res.body.data[0].id
261 it('Should fail with a non authenticated user', async function () {
262 await request(server.url)
263 .delete(path + '/' + videoChannelId)
264 .set('Authorization', 'Bearer coucou')
268 it('Should fail with another authenticated user', async function () {
269 await request(server.url)
270 .delete(path + '/' + videoChannelId)
271 .set('Authorization', 'Bearer ' + accessTokenUser)
275 it('Should fail with an unknown id', async function () {
276 await request(server.url)
277 .delete(path + '/454554')
278 .set('Authorization', 'Bearer ' + server.accessToken)
282 it('Should succeed with the correct parameters', async function () {
283 await request(server.url)
284 .delete(path + '/' + videoChannelId)
285 .set('Authorization', 'Bearer ' + server.accessToken)
289 it('Should fail to delete the last user video channel', async function () {
290 const res = await getVideoChannelsList(server.url, 0, 1)
291 videoChannelId = res.body.data[0].id
293 await request(server.url)
294 .delete(path + '/' + videoChannelId)
295 .set('Authorization', 'Bearer ' + server.accessToken)
301 after(async function () {
302 killallServers([ server ])
304 // Keep the logs if the test failed