aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-blacklists.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-blacklists.ts')
-rw-r--r--server/tests/api/check-params/video-blacklists.ts90
1 files changed, 90 insertions, 0 deletions
diff --git a/server/tests/api/check-params/video-blacklists.ts b/server/tests/api/check-params/video-blacklists.ts
new file mode 100644
index 000000000..d0ad78ff1
--- /dev/null
+++ b/server/tests/api/check-params/video-blacklists.ts
@@ -0,0 +1,90 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 ServerInfo,
7 flushTests,
8 runServer,
9 uploadVideo,
10 getVideosList,
11 createUser,
12 setAccessTokensToServers,
13 killallServers,
14 makePostBodyRequest,
15 getUserAccessToken
16} from '../../utils'
17
18describe('Test video blacklists API validators', function () {
19 let server: ServerInfo
20 let userAccessToken = ''
21
22 // ---------------------------------------------------------------
23
24 before(async function () {
25 this.timeout(120000)
26
27 await flushTests()
28
29 server = await runServer(1)
30
31 await setAccessTokensToServers([ server ])
32
33 const username = 'user1'
34 const password = 'my super password'
35 await createUser(server.url, server.accessToken, username, password)
36 userAccessToken = await getUserAccessToken(server, { username, password })
37
38 // Upload a video
39 const videoAttributes = {}
40 await uploadVideo(server.url, server.accessToken, videoAttributes)
41
42 const res = await getVideosList(server.url)
43
44 const videos = res.body.data
45 server.video = videos[0]
46 })
47
48 describe('When adding a video in blacklist', function () {
49 const basePath = '/api/v1/videos/'
50
51 it('Should fail with nothing', async function () {
52 const path = basePath + server.video + '/blacklist'
53 const fields = {}
54 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
55 })
56
57 it('Should fail with a wrong video', async function () {
58 const wrongPath = '/api/v1/videos/blabla/blacklist'
59 const fields = {}
60 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
61 })
62
63 it('Should fail with a non authenticated user', async function () {
64 const fields = {}
65 const path = basePath + server.video + '/blacklist'
66 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
67 })
68
69 it('Should fail with a non admin user', async function () {
70 const fields = {}
71 const path = basePath + server.video + '/blacklist'
72 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
73 })
74
75 it('Should fail with a local video', async function () {
76 const fields = {}
77 const path = basePath + server.video.id + '/blacklist'
78 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
79 })
80 })
81
82 after(async function () {
83 killallServers([ server ])
84
85 // Keep the logs if the test failed
86 if (this['ok']) {
87 await flushTests()
88 }
89 })
90})