1 /* tslint:disable:no-unused-expression */
8 getBlacklistedVideosList, getVideo, getVideoWithToken,
12 removeVideoFromBlacklist,
15 setAccessTokensToServers,
19 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
20 import { VideoDetails } from '../../../../shared/models/videos'
21 import { expect } from 'chai'
23 describe('Test video blacklist API validators', function () {
24 let server: ServerInfo
25 let notBlacklistedVideoId: number
26 let userAccessToken1 = ''
27 let userAccessToken2 = ''
29 // ---------------------------------------------------------------
31 before(async function () {
36 server = await runServer(1)
38 await setAccessTokensToServers([ server ])
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password)
44 userAccessToken1 = await userLogin(server, { username, password })
48 const username = 'user2'
49 const password = 'my super password'
50 await createUser(server.url, server.accessToken, username, password)
51 userAccessToken2 = await userLogin(server, { username, password })
55 const res = await uploadVideo(server.url, userAccessToken1, {})
56 server.video = res.body.video
60 const res = await uploadVideo(server.url, server.accessToken, {})
61 notBlacklistedVideoId = res.body.video.uuid
65 describe('When adding a video in blacklist', function () {
66 const basePath = '/api/v1/videos/'
68 it('Should fail with nothing', async function () {
69 const path = basePath + server.video + '/blacklist'
71 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
74 it('Should fail with a wrong video', async function () {
75 const wrongPath = '/api/v1/videos/blabla/blacklist'
77 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
80 it('Should fail with a non authenticated user', async function () {
81 const path = basePath + server.video + '/blacklist'
83 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
86 it('Should fail with a non admin user', async function () {
87 const path = basePath + server.video + '/blacklist'
89 await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
92 it('Should fail with an invalid reason', async function () {
93 const path = basePath + server.video.uuid + '/blacklist'
94 const fields = { reason: 'a'.repeat(305) }
96 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 it('Should succeed with the correct params', async function () {
100 const path = basePath + server.video.uuid + '/blacklist'
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
107 describe('When updating a video in blacklist', function () {
108 const basePath = '/api/v1/videos/'
110 it('Should fail with a wrong video', async function () {
111 const wrongPath = '/api/v1/videos/blabla/blacklist'
113 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
116 it('Should fail with a video not blacklisted', async function () {
117 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
119 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
122 it('Should fail with a non authenticated user', async function () {
123 const path = basePath + server.video + '/blacklist'
125 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
128 it('Should fail with a non admin user', async function () {
129 const path = basePath + server.video + '/blacklist'
131 await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
134 it('Should fail with an invalid reason', async function () {
135 const path = basePath + server.video.uuid + '/blacklist'
136 const fields = { reason: 'a'.repeat(305) }
138 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 it('Should succeed with the correct params', async function () {
142 const path = basePath + server.video.uuid + '/blacklist'
143 const fields = { reason: 'hello' }
145 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
149 describe('When getting blacklisted video', function () {
151 it('Should fail with a non authenticated user', async function () {
152 await getVideo(server.url, server.video.uuid, 401)
155 it('Should fail with another user', async function () {
156 await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403)
159 it('Should succeed with the owner authenticated user', async function () {
160 const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200)
161 const video: VideoDetails = res.body
163 expect(video.blacklisted).to.be.true
166 it('Should succeed with an admin', async function () {
167 const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200)
168 const video: VideoDetails = res.body
170 expect(video.blacklisted).to.be.true
174 describe('When removing a video in blacklist', function () {
175 it('Should fail with a non authenticated user', async function () {
176 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
179 it('Should fail with a non admin user', async function () {
180 await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403)
183 it('Should fail with an incorrect id', async function () {
184 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
187 it('Should fail with a not blacklisted video', async function () {
188 // The video was not added to the blacklist so it should fail
189 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
192 it('Should succeed with the correct params', async function () {
193 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
197 describe('When listing videos in blacklist', function () {
198 const basePath = '/api/v1/videos/blacklist/'
200 it('Should fail with a non authenticated user', async function () {
201 await getBlacklistedVideosList(server.url, 'fake token', 401)
204 it('Should fail with a non admin user', async function () {
205 await getBlacklistedVideosList(server.url, userAccessToken2, 403)
208 it('Should fail with a bad start pagination', async function () {
209 await checkBadStartPagination(server.url, basePath, server.accessToken)
212 it('Should fail with a bad count pagination', async function () {
213 await checkBadCountPagination(server.url, basePath, server.accessToken)
216 it('Should fail with an incorrect sort', async function () {
217 await checkBadSortPagination(server.url, basePath, server.accessToken)
221 after(async function () {
222 killallServers([ server ])
224 // Keep the logs if the test failed