]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-blacklist.ts
Add ability to delete our account
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-blacklist.ts
CommitLineData
792dbaf0
GS
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
792dbaf0
GS
4
5import {
11ba2ab3
C
6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer,
7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin
792dbaf0 8} from '../../utils'
11ba2ab3 9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
792dbaf0
GS
10
11describe('Test video blacklist API validators', function () {
12 let server: ServerInfo
13 let userAccessToken = ''
14
15 // ---------------------------------------------------------------
16
17 before(async function () {
18 this.timeout(120000)
19
20 await flushTests()
21
22 server = await runServer(1)
23
24 await setAccessTokensToServers([ server ])
25
26 const username = 'user1'
27 const password = 'my super password'
28 await createUser(server.url, server.accessToken, username, password)
eec63bbc 29 userAccessToken = await userLogin(server, { username, password })
792dbaf0 30
11ba2ab3
C
31 const res = await uploadVideo(server.url, server.accessToken, {})
32 server.video = res.body.video
792dbaf0
GS
33 })
34
35 describe('When adding a video in blacklist', function () {
36 const basePath = '/api/v1/videos/'
37
38 it('Should fail with nothing', async function () {
39 const path = basePath + server.video + '/blacklist'
40 const fields = {}
41 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
42 })
43
44 it('Should fail with a wrong video', async function () {
45 const wrongPath = '/api/v1/videos/blabla/blacklist'
46 const fields = {}
47 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
48 })
49
50 it('Should fail with a non authenticated user', async function () {
792dbaf0 51 const path = basePath + server.video + '/blacklist'
11ba2ab3 52 const fields = {}
792dbaf0
GS
53 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
54 })
55
56 it('Should fail with a non admin user', async function () {
792dbaf0 57 const path = basePath + server.video + '/blacklist'
11ba2ab3 58 const fields = {}
792dbaf0
GS
59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
60 })
61
62 it('Should fail with a local video', async function () {
792dbaf0 63 const path = basePath + server.video.id + '/blacklist'
11ba2ab3 64 const fields = {}
792dbaf0
GS
65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
66 })
67 })
68
69 describe('When removing a video in blacklist', function () {
792dbaf0 70 it('Should fail with a non authenticated user', async function () {
11ba2ab3 71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401)
792dbaf0
GS
72 })
73
74 it('Should fail with a non admin user', async function () {
11ba2ab3 75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403)
792dbaf0
GS
76 })
77
78 it('Should fail with an incorrect id', async function () {
11ba2ab3 79 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
792dbaf0
GS
80 })
81
82 it('Should fail with a not blacklisted video', async function () {
83 // The video was not added to the blacklist so it should fail
11ba2ab3 84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404)
792dbaf0
GS
85 })
86 })
87
88 describe('When listing videos in blacklist', function () {
35bf0c83 89 const basePath = '/api/v1/videos/blacklist/'
792dbaf0
GS
90
91 it('Should fail with a non authenticated user', async function () {
11ba2ab3 92 await getBlacklistedVideosList(server.url, 'fake token', 401)
792dbaf0
GS
93 })
94
95 it('Should fail with a non admin user', async function () {
11ba2ab3 96 await getBlacklistedVideosList(server.url, userAccessToken, 403)
792dbaf0
GS
97 })
98
99 it('Should fail with a bad start pagination', async function () {
11ba2ab3 100 await checkBadStartPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
101 })
102
103 it('Should fail with a bad count pagination', async function () {
11ba2ab3 104 await checkBadCountPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
105 })
106
107 it('Should fail with an incorrect sort', async function () {
11ba2ab3 108 await checkBadSortPagination(server.url, basePath, server.accessToken)
792dbaf0
GS
109 })
110 })
111
112 after(async function () {
113 killallServers([ server ])
114
115 // Keep the logs if the test failed
116 if (this['ok']) {
117 await flushTests()
118 }
119 })
120})