aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-blacklist.ts
diff options
context:
space:
mode:
authorGreen-Star <Green-Star@users.noreply.github.com>2017-09-22 09:13:43 +0200
committerBigard Florian <florian.bigard@gmail.com>2017-09-22 09:13:43 +0200
commit792dbaf07f83fbe3f1d209cd9edf190442c7d2f3 (patch)
treef7edf9caf17baaaf95c219c3ac73d598e3fd3df8 /server/tests/api/check-params/video-blacklist.ts
parentc9d6d155c397d0da0cb2d50064264fc1716f0501 (diff)
downloadPeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.gz
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.tar.zst
PeerTube-792dbaf07f83fbe3f1d209cd9edf190442c7d2f3.zip
Handle blacklist (#84)
* Client: Add list blacklist feature * Server: Add list blacklist feature * Client: Add videoId column * Server: Add some video infos in the REST api * Client: Add video information in the blacklist list * Fix sortable columns :) * Client: Add removeFromBlacklist feature * Server: Add removeFromBlacklist feature * Move to TypeScript * Move to TypeScript and Promises * Server: Fix blacklist list sort * Server: Fetch videos informations * Use common shared interface for client and server * Add check-params remove blacklisted video tests * Add check-params list blacklisted videos tests * Add list blacklist tests * Add remove from blacklist tests * Add video blacklist management tests * Fix rebase onto develop issues * Server: Add sort on blacklist id column * Server: Add blacklists library * Add blacklist id sort test * Add check-params tests for blacklist list pagination, count and sort * Fix coding style * Increase Remote API tests timeout * Increase Request scheduler API tests timeout * Fix typo * Increase video transcoding API tests timeout * Move tests to Typescript * Use lodash orderBy method * Fix typos * Client: Remove optional tests in blacklist model attributes * Move blacklist routes from 'blacklists' to 'blacklist' * CLient: Remove blacklist-list.component.scss * Rename 'blacklists' files to 'blacklist' * Use only BlacklistedVideo interface * Server: Use getFormattedObjects method in listBlacklist method * Client: Use new coding style * Server: Use new sort validator methods * Server: Use new checkParams methods * Client: Fix sortable columns
Diffstat (limited to 'server/tests/api/check-params/video-blacklist.ts')
-rw-r--r--server/tests/api/check-params/video-blacklist.ts195
1 files changed, 195 insertions, 0 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
new file mode 100644
index 000000000..80e6f8011
--- /dev/null
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -0,0 +1,195 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as request from 'supertest'
5
6import {
7 ServerInfo,
8 flushTests,
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 getUserAccessToken
17} from '../../utils'
18
19describe('Test video blacklist API validators', function () {
20 let server: ServerInfo
21 let userAccessToken = ''
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(120000)
27
28 await flushTests()
29
30 server = await runServer(1)
31
32 await setAccessTokensToServers([ server ])
33
34 const username = 'user1'
35 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password)
37 userAccessToken = await getUserAccessToken(server, { username, password })
38
39 // Upload a video
40 const videoAttributes = {}
41 await uploadVideo(server.url, server.accessToken, videoAttributes)
42
43 const res = await getVideosList(server.url)
44
45 const videos = res.body.data
46 server.video = videos[0]
47 })
48
49 describe('When adding a video in blacklist', function () {
50 const basePath = '/api/v1/videos/'
51
52 it('Should fail with nothing', async function () {
53 const path = basePath + server.video + '/blacklist'
54 const fields = {}
55 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
56 })
57
58 it('Should fail with a wrong video', async function () {
59 const wrongPath = '/api/v1/videos/blabla/blacklist'
60 const fields = {}
61 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
62 })
63
64 it('Should fail with a non authenticated user', async function () {
65 const fields = {}
66 const path = basePath + server.video + '/blacklist'
67 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
68 })
69
70 it('Should fail with a non admin user', async function () {
71 const fields = {}
72 const path = basePath + server.video + '/blacklist'
73 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
74 })
75
76 it('Should fail with a local video', async function () {
77 const fields = {}
78 const path = basePath + server.video.id + '/blacklist'
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
80 })
81 })
82
83 describe('When removing a video in blacklist', function () {
84 const basePath = '/api/v1/blacklist/'
85
86 it('Should fail with a non authenticated user', async function () {
87 const path = basePath + server.video.id
88
89 await request(server.url)
90 .delete(path)
91 .set('Authorization', 'Bearer ' + 'fake token')
92 .set('Accept', 'application/json')
93 .expect(401)
94 })
95
96 it('Should fail with a non admin user', async function () {
97 const path = basePath + server.video.id
98
99 await request(server.url)
100 .delete(path)
101 .set('Authorization', 'Bearer ' + userAccessToken)
102 .set('Accept', 'application/json')
103 .expect(403)
104 })
105
106 it('Should fail with an incorrect id', async function () {
107 const path = basePath + 'foobar'
108
109 await request(server.url)
110 .delete(path)
111 .set('Authorization', 'Bearer ' + server.accessToken)
112 .set('Accept', 'application/json')
113 .expect(400)
114 })
115
116 it('Should fail with a not blacklisted video', async function () {
117 // The video was not added to the blacklist so it should fail
118 const path = basePath + server.video.id
119
120 await request(server.url)
121 .delete(path)
122 .set('Authorization', 'Bearer ' + server.accessToken)
123 .set('Accept', 'application/json')
124 .expect(404)
125 })
126 })
127
128 describe('When listing videos in blacklist', function () {
129 const basePath = '/api/v1/blacklist/'
130
131 it('Should fail with a non authenticated user', async function () {
132 const path = basePath
133
134 await request(server.url)
135 .get(path)
136 .query({ sort: 'createdAt' })
137 .set('Accept', 'application/json')
138 .set('Authorization', 'Bearer ' + 'fake token')
139 .expect(401)
140 })
141
142 it('Should fail with a non admin user', async function () {
143 const path = basePath
144
145 await request(server.url)
146 .get(path)
147 .query({ sort: 'createdAt' })
148 .set('Authorization', 'Bearer ' + userAccessToken)
149 .set('Accept', 'application/json')
150 .expect(403)
151 })
152
153 it('Should fail with a bad start pagination', async function () {
154 const path = basePath
155
156 await request(server.url)
157 .get(path)
158 .query({ start: 'foobar' })
159 .set('Accept', 'application/json')
160 .set('Authorization', 'Bearer ' + server.accessToken)
161 .expect(400)
162 })
163
164 it('Should fail with a bad count pagination', async function () {
165 const path = basePath
166
167 await request(server.url)
168 .get(path)
169 .query({ count: 'foobar' })
170 .set('Accept', 'application/json')
171 .set('Authorization', 'Bearer ' + server.accessToken)
172 .expect(400)
173 })
174
175 it('Should fail with an incorrect sort', async function () {
176 const path = basePath
177
178 await request(server.url)
179 .get(path)
180 .query({ sort: 'foobar' })
181 .set('Accept', 'application/json')
182 .set('Authorization', 'Bearer ' + server.accessToken)
183 .expect(400)
184 })
185 })
186
187 after(async function () {
188 killallServers([ server ])
189
190 // Keep the logs if the test failed
191 if (this['ok']) {
192 await flushTests()
193 }
194 })
195})