1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
13 setAccessTokensToServers,
19 describe('Test video blacklist 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)
37 userAccessToken = await userLogin(server, { username, password })
40 const videoAttributes = {}
41 await uploadVideo(server.url, server.accessToken, videoAttributes)
43 const res = await getVideosList(server.url)
45 const videos = res.body.data
46 server.video = videos[0]
49 describe('When adding a video in blacklist', function () {
50 const basePath = '/api/v1/videos/'
52 it('Should fail with nothing', async function () {
53 const path = basePath + server.video + '/blacklist'
55 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
58 it('Should fail with a wrong video', async function () {
59 const wrongPath = '/api/v1/videos/blabla/blacklist'
61 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
64 it('Should fail with a non authenticated user', async function () {
66 const path = basePath + server.video + '/blacklist'
67 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
70 it('Should fail with a non admin user', async function () {
72 const path = basePath + server.video + '/blacklist'
73 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
76 it('Should fail with a local video', async function () {
78 const path = basePath + server.video.id + '/blacklist'
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
83 describe('When removing a video in blacklist', function () {
84 const basePath = '/api/v1/videos/'
86 it('Should fail with a non authenticated user', async function () {
87 const path = basePath + server.video.id + '/blacklist'
89 await request(server.url)
91 .set('Authorization', 'Bearer ' + 'fake token')
92 .set('Accept', 'application/json')
96 it('Should fail with a non admin user', async function () {
97 const path = basePath + server.video.id + '/blacklist'
99 await request(server.url)
101 .set('Authorization', 'Bearer ' + userAccessToken)
102 .set('Accept', 'application/json')
106 it('Should fail with an incorrect id', async function () {
107 const path = basePath + 'foobar/blacklist'
109 await request(server.url)
111 .set('Authorization', 'Bearer ' + server.accessToken)
112 .set('Accept', 'application/json')
116 it('Should fail with a not blacklisted video', async function () {
117 // The video was not added to the blacklist so it should fail
118 const path = basePath + server.video.id + '/blacklist'
120 await request(server.url)
122 .set('Authorization', 'Bearer ' + server.accessToken)
123 .set('Accept', 'application/json')
128 describe('When listing videos in blacklist', function () {
129 const basePath = '/api/v1/videos/blacklist/'
131 it('Should fail with a non authenticated user', async function () {
132 const path = basePath
134 await request(server.url)
136 .query({ sort: 'createdAt' })
137 .set('Accept', 'application/json')
138 .set('Authorization', 'Bearer ' + 'fake token')
142 it('Should fail with a non admin user', async function () {
143 const path = basePath
145 await request(server.url)
147 .query({ sort: 'createdAt' })
148 .set('Authorization', 'Bearer ' + userAccessToken)
149 .set('Accept', 'application/json')
153 it('Should fail with a bad start pagination', async function () {
154 const path = basePath
156 await request(server.url)
158 .query({ start: 'foobar' })
159 .set('Accept', 'application/json')
160 .set('Authorization', 'Bearer ' + server.accessToken)
164 it('Should fail with a bad count pagination', async function () {
165 const path = basePath
167 await request(server.url)
169 .query({ count: 'foobar' })
170 .set('Accept', 'application/json')
171 .set('Authorization', 'Bearer ' + server.accessToken)
175 it('Should fail with an incorrect sort', async function () {
176 const path = basePath
178 await request(server.url)
180 .query({ sort: 'foobar' })
181 .set('Accept', 'application/json')
182 .set('Authorization', 'Bearer ' + server.accessToken)
187 after(async function () {
188 killallServers([ server ])
190 // Keep the logs if the test failed