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 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
123 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
124 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
125 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
126 description: 'super description'
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
131 it('Should fail with a long description', async function () {
134 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
135 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
136 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
137 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
142 it('Should succeed with the correct parameters', async function () {
145 description: 'super description'
147 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
151 describe('When updating a video channel', function () {
154 before(async function () {
155 const res = await getVideoChannelsList(server.url, 0, 1)
156 videoChannelId = res.body.data[0].id
159 it('Should fail with a non authenticated user', async function () {
162 description: 'super description'
164 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: 'hi', fields, statusCodeExpected: 401 })
167 it('Should fail with another authenticated user', async function () {
170 description: 'super description'
172 await makePutBodyRequest({
174 path: path + '/' + videoChannelId,
175 token: accessTokenUser,
177 statusCodeExpected: 403
181 it('Should fail with a long name', async function () {
183 name: 'hello tooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
184 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
185 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
186 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
187 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long',
188 description: 'super description'
190 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
193 it('Should fail with a long description', async function () {
196 description: 'super toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
197 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo0' +
198 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' +
199 'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo long description'
201 await makePutBodyRequest({ url: server.url, path: path + '/' + videoChannelId, token: server.accessToken, fields })
204 it('Should succeed with the correct parameters', async function () {
207 description: 'super description 2'
209 await makePutBodyRequest({
211 path: path + '/' + videoChannelId,
212 token: server.accessToken,
214 statusCodeExpected: 204
219 describe('When getting a video channel', function () {
220 let videoChannelId: number
222 before(async function () {
223 const res = await getVideoChannelsList(server.url, 0, 1)
224 videoChannelId = res.body.data[0].id
227 it('Should return the list of the video channels with nothing', async function () {
228 const res = await request(server.url)
230 .set('Accept', 'application/json')
232 .expect('Content-Type', /json/)
234 expect(res.body.data).to.be.an('array')
237 it('Should fail without a correct uuid', async function () {
238 await request(server.url)
239 .get(path + '/coucou')
240 .set('Accept', 'application/json')
244 it('Should return 404 with an incorrect video channel', async function () {
245 await request(server.url)
246 .get(path + '/4da6fde3-88f7-4d16-b119-108df5630b06')
247 .set('Accept', 'application/json')
251 it('Should succeed with the correct parameters', async function () {
252 await request(server.url)
253 .get(path + '/' + videoChannelId)
254 .set('Accept', 'application/json')
259 describe('When deleting a video channel', function () {
260 let videoChannelId: number
262 before(async function () {
263 const res = await getVideoChannelsList(server.url, 0, 1)
264 videoChannelId = res.body.data[0].id
267 it('Should fail with a non authenticated user', async function () {
268 await request(server.url)
269 .delete(path + '/' + videoChannelId)
270 .set('Authorization', 'Bearer coucou')
274 it('Should fail with another authenticated user', async function () {
275 await request(server.url)
276 .delete(path + '/' + videoChannelId)
277 .set('Authorization', 'Bearer ' + accessTokenUser)
281 it('Should fail with an unknown id', async function () {
282 await request(server.url)
283 .delete(path + '/454554')
284 .set('Authorization', 'Bearer ' + server.accessToken)
288 it('Should succeed with the correct parameters', async function () {
289 await request(server.url)
290 .delete(path + '/' + videoChannelId)
291 .set('Authorization', 'Bearer ' + server.accessToken)
295 it('Should fail to delete the last user video channel', async function () {
296 const res = await getVideoChannelsList(server.url, 0, 1)
297 videoChannelId = res.body.data[0].id
299 await request(server.url)
300 .delete(path + '/' + videoChannelId)
301 .set('Authorization', 'Bearer ' + server.accessToken)
307 after(async function () {
308 killallServers([ server ])
310 // Keep the logs if the test failed