1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
13 setAccessTokensToServers,
19 describe('Test video abuses API validators', function () {
20 let server: ServerInfo
21 let userAccessToken = ''
23 // ---------------------------------------------------------------
25 before(async function () {
30 server = await runServer(1)
32 await setAccessTokensToServers([ server ])
34 const username = 'user1'
35 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password)
38 userAccessToken = await getUserAccessToken(server, { username, password })
41 const videoAttributes = {}
42 await uploadVideo(server.url, server.accessToken, videoAttributes)
44 const res = await getVideosList(server.url)
45 const videos = res.body.data
46 server.video = videos[0]
49 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse'
52 it('Should fail with a bad start pagination', async function () {
53 await request(server.url)
55 .query({ start: 'hello' })
56 .set('Authorization', 'Bearer ' + server.accessToken)
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')
66 .set('Authorization', 'Bearer ' + server.accessToken)
70 it('Should fail with an incorrect sort', async function () {
71 await request(server.url)
73 .query({ sort: 'hello' })
74 .set('Accept', 'application/json')
75 .set('Authorization', 'Bearer ' + server.accessToken)
79 it('Should fail with a non authenticated user', async function () {
80 await request(server.url)
82 .query({ sort: 'hello' })
83 .set('Accept', 'application/json')
87 it('Should fail with a non admin user', async function () {
88 await request(server.url)
90 .query({ sort: 'hello' })
91 .set('Accept', 'application/json')
92 .set('Authorization', 'Bearer ' + userAccessToken)
97 describe('When reporting a video abuse', function () {
98 const basePath = '/api/v1/videos/'
100 it('Should fail with nothing', async function () {
101 const path = basePath + server.video.id + '/abuse'
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
106 it('Should fail with a wrong video', async function () {
107 const wrongPath = '/api/v1/videos/blabla/abuse'
109 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
112 it('Should fail with a non authenticated user', async function () {
114 const path = basePath + server.video.id + '/abuse'
115 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
118 it('Should fail with a reason too short', async function () {
122 const path = basePath + server.video.id + '/abuse'
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 it('Should fail with a reason too big', async function () {
128 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
129 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
130 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
131 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
133 const path = basePath + server.video.id + '/abuse'
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
138 after(async function () {
139 killallServers([ server ])
141 // Keep the logs if the test failed