diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-01 19:04:29 +0200 |
commit | 843aa7ba0312e7180e7bbae147e32ee60e70d9ba (patch) | |
tree | df5533a9dda312877b8b3a6992b81c75044c094e /server/tests/api/check-params | |
parent | 3eeeb87fe62fab3e48455f53c8a725b49878b9b3 (diff) | |
download | PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.gz PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.tar.zst PeerTube-843aa7ba0312e7180e7bbae147e32ee60e70d9ba.zip |
Server: add tests for video blacklists
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.js | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.js | 8 | ||||
-rw-r--r-- | server/tests/api/check-params/video-blacklists.js | 123 |
3 files changed, 128 insertions, 4 deletions
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js index d0824f08a..527ab65a9 100644 --- a/server/tests/api/check-params/index.js +++ b/server/tests/api/check-params/index.js | |||
@@ -7,3 +7,4 @@ require('./users') | |||
7 | require('./requests') | 7 | require('./requests') |
8 | require('./videos') | 8 | require('./videos') |
9 | require('./video-abuses') | 9 | require('./video-abuses') |
10 | require('./video-blacklists') | ||
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js index 6dc5a7090..8c520aab4 100644 --- a/server/tests/api/check-params/video-abuses.js +++ b/server/tests/api/check-params/video-abuses.js | |||
@@ -129,7 +129,7 @@ describe('Test video abuses API validators', function () { | |||
129 | const basePath = '/api/v1/videos/' | 129 | const basePath = '/api/v1/videos/' |
130 | 130 | ||
131 | it('Should fail with nothing', function (done) { | 131 | it('Should fail with nothing', function (done) { |
132 | const path = basePath + server.video + '/abuse' | 132 | const path = basePath + server.video.id + '/abuse' |
133 | const data = {} | 133 | const data = {} |
134 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | 134 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
135 | }) | 135 | }) |
@@ -142,7 +142,7 @@ describe('Test video abuses API validators', function () { | |||
142 | 142 | ||
143 | it('Should fail with a non authenticated user', function (done) { | 143 | it('Should fail with a non authenticated user', function (done) { |
144 | const data = {} | 144 | const data = {} |
145 | const path = basePath + server.video + '/abuse' | 145 | const path = basePath + server.video.id + '/abuse' |
146 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) | 146 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) |
147 | }) | 147 | }) |
148 | 148 | ||
@@ -150,7 +150,7 @@ describe('Test video abuses API validators', function () { | |||
150 | const data = { | 150 | const data = { |
151 | reason: 'h' | 151 | reason: 'h' |
152 | } | 152 | } |
153 | const path = basePath + server.video + '/abuse' | 153 | const path = basePath + server.video.id + '/abuse' |
154 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | 154 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
155 | }) | 155 | }) |
156 | 156 | ||
@@ -161,7 +161,7 @@ describe('Test video abuses API validators', function () { | |||
161 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + | 161 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + |
162 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' | 162 | '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' |
163 | } | 163 | } |
164 | const path = basePath + server.video + '/abuse' | 164 | const path = basePath + server.video.id + '/abuse' |
165 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | 165 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) |
166 | }) | 166 | }) |
167 | }) | 167 | }) |
diff --git a/server/tests/api/check-params/video-blacklists.js b/server/tests/api/check-params/video-blacklists.js new file mode 100644 index 000000000..a39ab0cfa --- /dev/null +++ b/server/tests/api/check-params/video-blacklists.js | |||
@@ -0,0 +1,123 @@ | |||
1 | /* eslint-disable no-unused-expressions */ | ||
2 | |||
3 | 'use strict' | ||
4 | |||
5 | const series = require('async/series') | ||
6 | |||
7 | const loginUtils = require('../../utils/login') | ||
8 | const requestsUtils = require('../../utils/requests') | ||
9 | const serversUtils = require('../../utils/servers') | ||
10 | const usersUtils = require('../../utils/users') | ||
11 | const videosUtils = require('../../utils/videos') | ||
12 | |||
13 | describe('Test video blacklists API validators', function () { | ||
14 | let server = null | ||
15 | let userAccessToken = null | ||
16 | |||
17 | // --------------------------------------------------------------- | ||
18 | |||
19 | before(function (done) { | ||
20 | this.timeout(20000) | ||
21 | |||
22 | series([ | ||
23 | function (next) { | ||
24 | serversUtils.flushTests(next) | ||
25 | }, | ||
26 | function (next) { | ||
27 | serversUtils.runServer(1, function (server1) { | ||
28 | server = server1 | ||
29 | |||
30 | next() | ||
31 | }) | ||
32 | }, | ||
33 | function (next) { | ||
34 | loginUtils.loginAndGetAccessToken(server, function (err, token) { | ||
35 | if (err) throw err | ||
36 | server.accessToken = token | ||
37 | |||
38 | next() | ||
39 | }) | ||
40 | }, | ||
41 | function (next) { | ||
42 | const username = 'user1' | ||
43 | const password = 'my super password' | ||
44 | |||
45 | usersUtils.createUser(server.url, server.accessToken, username, password, next) | ||
46 | }, | ||
47 | function (next) { | ||
48 | const user = { | ||
49 | username: 'user1', | ||
50 | password: 'my super password' | ||
51 | } | ||
52 | |||
53 | loginUtils.getUserAccessToken(server, user, function (err, accessToken) { | ||
54 | if (err) throw err | ||
55 | |||
56 | userAccessToken = accessToken | ||
57 | |||
58 | next() | ||
59 | }) | ||
60 | }, | ||
61 | // Upload a video | ||
62 | function (next) { | ||
63 | const videoAttributes = {} | ||
64 | videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next) | ||
65 | }, | ||
66 | function (next) { | ||
67 | videosUtils.getVideosList(server.url, function (err, res) { | ||
68 | if (err) throw err | ||
69 | |||
70 | const videos = res.body.data | ||
71 | server.video = videos[0] | ||
72 | |||
73 | next() | ||
74 | }) | ||
75 | } | ||
76 | ], done) | ||
77 | }) | ||
78 | |||
79 | describe('When adding a video in blacklist', function () { | ||
80 | const basePath = '/api/v1/videos/' | ||
81 | |||
82 | it('Should fail with nothing', function (done) { | ||
83 | const path = basePath + server.video + '/blacklist' | ||
84 | const data = {} | ||
85 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) | ||
86 | }) | ||
87 | |||
88 | it('Should fail with a wrong video', function (done) { | ||
89 | const wrongPath = '/api/v1/videos/blabla/blacklist' | ||
90 | const data = {} | ||
91 | requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done) | ||
92 | }) | ||
93 | |||
94 | it('Should fail with a non authenticated user', function (done) { | ||
95 | const data = {} | ||
96 | const path = basePath + server.video + '/blacklist' | ||
97 | requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) | ||
98 | }) | ||
99 | |||
100 | it('Should fail with a non admin user', function (done) { | ||
101 | const data = {} | ||
102 | const path = basePath + server.video + '/blacklist' | ||
103 | requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403) | ||
104 | }) | ||
105 | |||
106 | it('Should fail with a local video', function (done) { | ||
107 | const data = {} | ||
108 | const path = basePath + server.video.id + '/blacklist' | ||
109 | requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 403) | ||
110 | }) | ||
111 | }) | ||
112 | |||
113 | after(function (done) { | ||
114 | process.kill(-server.app.pid) | ||
115 | |||
116 | // Keep the logs if the test failed | ||
117 | if (this.ok) { | ||
118 | serversUtils.flushTests(done) | ||
119 | } else { | ||
120 | done() | ||
121 | } | ||
122 | }) | ||
123 | }) | ||