1 /* tslint:disable:no-unused-expression */
8 getBlacklistedVideosList,
12 removeVideoFromBlacklist,
15 setAccessTokensToServers,
19 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
21 describe('Test video blacklist API validators', function () {
22 let server: ServerInfo
23 let notBlacklistedVideoId: number
24 let userAccessToken = ''
26 // ---------------------------------------------------------------
28 before(async function () {
33 server = await runServer(1)
35 await setAccessTokensToServers([ server ])
37 const username = 'user1'
38 const password = 'my super password'
39 await createUser(server.url, server.accessToken, username, password)
40 userAccessToken = await userLogin(server, { username, password })
43 const res = await uploadVideo(server.url, server.accessToken, {})
44 server.video = res.body.video
48 const res = await uploadVideo(server.url, server.accessToken, {})
49 notBlacklistedVideoId = res.body.video.uuid
53 describe('When adding a video in blacklist', function () {
54 const basePath = '/api/v1/videos/'
56 it('Should fail with nothing', async function () {
57 const path = basePath + server.video + '/blacklist'
59 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
62 it('Should fail with a wrong video', async function () {
63 const wrongPath = '/api/v1/videos/blabla/blacklist'
65 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
68 it('Should fail with a non authenticated user', async function () {
69 const path = basePath + server.video + '/blacklist'
71 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
74 it('Should fail with a non admin user', async function () {
75 const path = basePath + server.video + '/blacklist'
77 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
80 it('Should fail with an invalid reason', async function () {
81 const path = basePath + server.video.uuid + '/blacklist'
82 const fields = { reason: 'a'.repeat(305) }
84 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
87 it('Should succeed with the correct params', async function () {
88 const path = basePath + server.video.uuid + '/blacklist'
91 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
95 describe('When updating a video in blacklist', function () {
96 const basePath = '/api/v1/videos/'
98 it('Should fail with a wrong video', async function () {
99 const wrongPath = '/api/v1/videos/blabla/blacklist'
101 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
104 it('Should fail with a video not blacklisted', async function () {
105 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
107 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 })
110 it('Should fail with a non authenticated user', async function () {
111 const path = basePath + server.video + '/blacklist'
113 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
116 it('Should fail with a non admin user', async function () {
117 const path = basePath + server.video + '/blacklist'
119 await makePutBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
122 it('Should fail with an invalid reason', async function () {
123 const path = basePath + server.video.uuid + '/blacklist'
124 const fields = { reason: 'a'.repeat(305) }
126 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 it('Should succeed with the correct params', async function () {
130 const path = basePath + server.video.uuid + '/blacklist'
131 const fields = { reason: 'hello' }
133 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
137 describe('When removing a video in blacklist', function () {
138 it('Should fail with a non authenticated user', async function () {
139 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401)
142 it('Should fail with a non admin user', async function () {
143 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.uuid, 403)
146 it('Should fail with an incorrect id', async function () {
147 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
150 it('Should fail with a not blacklisted video', async function () {
151 // The video was not added to the blacklist so it should fail
152 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404)
155 it('Should succeed with the correct params', async function () {
156 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204)
160 describe('When listing videos in blacklist', function () {
161 const basePath = '/api/v1/videos/blacklist/'
163 it('Should fail with a non authenticated user', async function () {
164 await getBlacklistedVideosList(server.url, 'fake token', 401)
167 it('Should fail with a non admin user', async function () {
168 await getBlacklistedVideosList(server.url, userAccessToken, 403)
171 it('Should fail with a bad start pagination', async function () {
172 await checkBadStartPagination(server.url, basePath, server.accessToken)
175 it('Should fail with a bad count pagination', async function () {
176 await checkBadCountPagination(server.url, basePath, server.accessToken)
179 it('Should fail with an incorrect sort', async function () {
180 await checkBadSortPagination(server.url, basePath, server.accessToken)
184 after(async function () {
185 killallServers([ server ])
187 // Keep the logs if the test failed