1 /* tslint:disable:no-unused-expression */
8 getBlacklistedVideosList, getVideo, getVideoWithToken,
12 removeVideoFromBlacklist,
15 setAccessTokensToServers,
18 } from '../../../../shared/utils'
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23 } from '../../../../shared/utils/requests/check-api-params'
24 import { VideoDetails } from '../../../../shared/models/videos'
25 import { expect } from 'chai'
27 describe('Test video blacklist API validators', function () {
28 let server: ServerInfo
29 let notBlacklistedVideoId: number
30 let userAccessToken1 = ''
31 let userAccessToken2 = ''
33 // ---------------------------------------------------------------
35 before(async function () {
40 server = await runServer(1)
42 await setAccessTokensToServers([ server ])
45 const username = 'user1'
46 const password = 'my super password'
47 await createUser(server.url, server.accessToken, username, password)
48 userAccessToken1 = await userLogin(server, { username, password })
52 const username = 'user2'
53 const password = 'my super password'
54 await createUser(server.url, server.accessToken, username, password)
55 userAccessToken2 = await userLogin(server, { username, password })
59 const res = await uploadVideo(server.url, userAccessToken1, {})
60 server.video = res.body.video
64 const res = await uploadVideo(server.url, server.accessToken, {})
65 notBlacklistedVideoId = res.body.video.uuid
69 describe('When adding a video in blacklist', function () {
70 const basePath = '/api/v1/videos/'
72 it('Should fail with nothing', async function () {
73 const path = basePath + server.video + '/blacklist'
75 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
78 it('Should fail with a wrong video', async function () {
79 const wrongPath = '/api/v1/videos/blabla/blacklist'
81 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
84 it('Should fail with a non authenticated user', async function () {
85 const path = basePath + server.video + '/blacklist'
87 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
90 it('Should fail with a non admin user', async function () {
91 const path = basePath + server.video + '/blacklist'
93 await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
96 it('Should fail with an invalid reason', async function () {
97 const path = basePath + server.video.uuid + '/blacklist'
98 const fields = { reason: 'a'.repeat(305) }
100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
103 it('Should succeed with the correct params', async function () {
104 const path = basePath + server.video.uuid + '/blacklist'
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
111 describe('When updating a video in blacklist', function () {
112 const basePath = '/api/v1/videos/'
114 it('Should fail with a wrong video', async function () {
115 const wrongPath = '/api/v1/videos/blabla/blacklist'
117 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
120 it('Should fail with a video not blacklisted', async function () {
121 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
123 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
126 it('Should fail with a non authenticated user', async function () {
127 const path = basePath + server.video + '/blacklist'
129 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
132 it('Should fail with a non admin user', async function () {
133 const path = basePath + server.video + '/blacklist'
135 await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
138 it('Should fail with an invalid reason', async function () {
139 const path = basePath + server.video.uuid + '/blacklist'
140 const fields = { reason: 'a'.repeat(305) }
142 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
145 it('Should succeed with the correct params', async function () {
146 const path = basePath + server.video.uuid + '/blacklist'
147 const fields = { reason: 'hello' }
149 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
153 describe('When getting blacklisted video', function () {
155 it('Should fail with a non authenticated user', async function () {
156 await getVideo(server.url, server.video.uuid, 401)
159 it('Should fail with another user', async function () {
160 await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403)
163 it('Should succeed with the owner authenticated user', async function () {
164 const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200)
165 const video: VideoDetails = res.body
167 expect(video.blacklisted).to.be.true
170 it('Should succeed with an admin', async function () {
171 const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200)
172 const video: VideoDetails = res.body
174 expect(video.blacklisted).to.be.true
178 describe('When removing a video in blacklist', function () {
179 it('Should fail with a non authenticated user', async function () {
180 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
183 it('Should fail with a non admin user', async function () {
184 await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403)
187 it('Should fail with an incorrect id', async function () {
188 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
191 it('Should fail with a not blacklisted video', async function () {
192 // The video was not added to the blacklist so it should fail
193 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
196 it('Should succeed with the correct params', async function () {
197 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
201 describe('When listing videos in blacklist', function () {
202 const basePath = '/api/v1/videos/blacklist/'
204 it('Should fail with a non authenticated user', async function () {
205 await getBlacklistedVideosList(server.url, 'fake token', 401)
208 it('Should fail with a non admin user', async function () {
209 await getBlacklistedVideosList(server.url, userAccessToken2, 403)
212 it('Should fail with a bad start pagination', async function () {
213 await checkBadStartPagination(server.url, basePath, server.accessToken)
216 it('Should fail with a bad count pagination', async function () {
217 await checkBadCountPagination(server.url, basePath, server.accessToken)
220 it('Should fail with an incorrect sort', async function () {
221 await checkBadSortPagination(server.url, basePath, server.accessToken)
225 after(async function () {
226 killallServers([ server ])
228 // Keep the logs if the test failed