1 /* tslint:disable:no-unused-expression */
6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer,
7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin
9 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11 describe('Test video blacklist API validators', function () {
12 let server: ServerInfo
13 let userAccessToken = ''
15 // ---------------------------------------------------------------
17 before(async function () {
22 server = await runServer(1)
24 await setAccessTokensToServers([ server ])
26 const username = 'user1'
27 const password = 'my super password'
28 await createUser(server.url, server.accessToken, username, password)
29 userAccessToken = await userLogin(server, { username, password })
31 const res = await uploadVideo(server.url, server.accessToken, {})
32 server.video = res.body.video
35 describe('When adding a video in blacklist', function () {
36 const basePath = '/api/v1/videos/'
38 it('Should fail with nothing', async function () {
39 const path = basePath + server.video + '/blacklist'
41 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
44 it('Should fail with a wrong video', async function () {
45 const wrongPath = '/api/v1/videos/blabla/blacklist'
47 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
50 it('Should fail with a non authenticated user', async function () {
51 const path = basePath + server.video + '/blacklist'
53 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
56 it('Should fail with a non admin user', async function () {
57 const path = basePath + server.video + '/blacklist'
59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
62 it('Should fail with a local video', async function () {
63 const path = basePath + server.video.id + '/blacklist'
65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
69 describe('When removing a video in blacklist', function () {
70 it('Should fail with a non authenticated user', async function () {
71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401)
74 it('Should fail with a non admin user', async function () {
75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403)
78 it('Should fail with an incorrect id', async function () {
79 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
82 it('Should fail with a not blacklisted video', async function () {
83 // The video was not added to the blacklist so it should fail
84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404)
88 describe('When listing videos in blacklist', function () {
89 const basePath = '/api/v1/videos/blacklist/'
91 it('Should fail with a non authenticated user', async function () {
92 await getBlacklistedVideosList(server.url, 'fake token', 401)
95 it('Should fail with a non admin user', async function () {
96 await getBlacklistedVideosList(server.url, userAccessToken, 403)
99 it('Should fail with a bad start pagination', async function () {
100 await checkBadStartPagination(server.url, basePath, server.accessToken)
103 it('Should fail with a bad count pagination', async function () {
104 await checkBadCountPagination(server.url, basePath, server.accessToken)
107 it('Should fail with an incorrect sort', async function () {
108 await checkBadSortPagination(server.url, basePath, server.accessToken)
112 after(async function () {
113 killallServers([ server ])
115 // Keep the logs if the test failed