aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-blacklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-blacklist.ts')
-rw-r--r--server/tests/api/check-params/video-blacklist.ts109
1 files changed, 17 insertions, 92 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index c8b457182..6cd13d23f 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -1,20 +1,12 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import 'mocha' 3import 'mocha'
4import * as request from 'supertest'
5 4
6import { 5import {
7 ServerInfo, 6 createUser, flushTests, getBlacklistedVideosList, killallServers, makePostBodyRequest, removeVideoFromBlacklist, runServer,
8 flushTests, 7 ServerInfo, setAccessTokensToServers, uploadVideo, userLogin
9 runServer,
10 uploadVideo,
11 getVideosList,
12 createUser,
13 setAccessTokensToServers,
14 killallServers,
15 makePostBodyRequest,
16 userLogin
17} from '../../utils' 8} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
18 10
19describe('Test video blacklist API validators', function () { 11describe('Test video blacklist API validators', function () {
20 let server: ServerInfo 12 let server: ServerInfo
@@ -36,14 +28,8 @@ describe('Test video blacklist API validators', function () {
36 await createUser(server.url, server.accessToken, username, password) 28 await createUser(server.url, server.accessToken, username, password)
37 userAccessToken = await userLogin(server, { username, password }) 29 userAccessToken = await userLogin(server, { username, password })
38 30
39 // Upload a video 31 const res = await uploadVideo(server.url, server.accessToken, {})
40 const videoAttributes = {} 32 server.video = res.body.video
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 }) 33 })
48 34
49 describe('When adding a video in blacklist', function () { 35 describe('When adding a video in blacklist', function () {
@@ -62,66 +48,40 @@ describe('Test video blacklist API validators', function () {
62 }) 48 })
63 49
64 it('Should fail with a non authenticated user', async function () { 50 it('Should fail with a non authenticated user', async function () {
65 const fields = {}
66 const path = basePath + server.video + '/blacklist' 51 const path = basePath + server.video + '/blacklist'
52 const fields = {}
67 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 53 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
68 }) 54 })
69 55
70 it('Should fail with a non admin user', async function () { 56 it('Should fail with a non admin user', async function () {
71 const fields = {}
72 const path = basePath + server.video + '/blacklist' 57 const path = basePath + server.video + '/blacklist'
58 const fields = {}
73 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 59 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 })
74 }) 60 })
75 61
76 it('Should fail with a local video', async function () { 62 it('Should fail with a local video', async function () {
77 const fields = {}
78 const path = basePath + server.video.id + '/blacklist' 63 const path = basePath + server.video.id + '/blacklist'
64 const fields = {}
79 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 }) 65 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 403 })
80 }) 66 })
81 }) 67 })
82 68
83 describe('When removing a video in blacklist', function () { 69 describe('When removing a video in blacklist', function () {
84 const basePath = '/api/v1/videos/'
85
86 it('Should fail with a non authenticated user', async function () { 70 it('Should fail with a non authenticated user', async function () {
87 const path = basePath + server.video.id + '/blacklist' 71 await removeVideoFromBlacklist(server.url, 'fake token', server.video.id, 401)
88
89 await request(server.url)
90 .delete(path)
91 .set('Authorization', 'Bearer ' + 'fake token')
92 .set('Accept', 'application/json')
93 .expect(401)
94 }) 72 })
95 73
96 it('Should fail with a non admin user', async function () { 74 it('Should fail with a non admin user', async function () {
97 const path = basePath + server.video.id + '/blacklist' 75 await removeVideoFromBlacklist(server.url, userAccessToken, server.video.id, 403)
98
99 await request(server.url)
100 .delete(path)
101 .set('Authorization', 'Bearer ' + userAccessToken)
102 .set('Accept', 'application/json')
103 .expect(403)
104 }) 76 })
105 77
106 it('Should fail with an incorrect id', async function () { 78 it('Should fail with an incorrect id', async function () {
107 const path = basePath + 'foobar/blacklist' 79 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400)
108
109 await request(server.url)
110 .delete(path)
111 .set('Authorization', 'Bearer ' + server.accessToken)
112 .set('Accept', 'application/json')
113 .expect(400)
114 }) 80 })
115 81
116 it('Should fail with a not blacklisted video', async function () { 82 it('Should fail with a not blacklisted video', async function () {
117 // The video was not added to the blacklist so it should fail 83 // The video was not added to the blacklist so it should fail
118 const path = basePath + server.video.id + '/blacklist' 84 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.id, 404)
119
120 await request(server.url)
121 .delete(path)
122 .set('Authorization', 'Bearer ' + server.accessToken)
123 .set('Accept', 'application/json')
124 .expect(404)
125 }) 85 })
126 }) 86 })
127 87
@@ -129,58 +89,23 @@ describe('Test video blacklist API validators', function () {
129 const basePath = '/api/v1/videos/blacklist/' 89 const basePath = '/api/v1/videos/blacklist/'
130 90
131 it('Should fail with a non authenticated user', async function () { 91 it('Should fail with a non authenticated user', async function () {
132 const path = basePath 92 await getBlacklistedVideosList(server.url, 'fake token', 401)
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 }) 93 })
141 94
142 it('Should fail with a non admin user', async function () { 95 it('Should fail with a non admin user', async function () {
143 const path = basePath 96 await getBlacklistedVideosList(server.url, userAccessToken, 403)
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 }) 97 })
152 98
153 it('Should fail with a bad start pagination', async function () { 99 it('Should fail with a bad start pagination', async function () {
154 const path = basePath 100 await checkBadStartPagination(server.url, basePath, server.accessToken)
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 }) 101 })
163 102
164 it('Should fail with a bad count pagination', async function () { 103 it('Should fail with a bad count pagination', async function () {
165 const path = basePath 104 await checkBadCountPagination(server.url, basePath, server.accessToken)
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 }) 105 })
174 106
175 it('Should fail with an incorrect sort', async function () { 107 it('Should fail with an incorrect sort', async function () {
176 const path = basePath 108 await checkBadSortPagination(server.url, basePath, server.accessToken)
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 }) 109 })
185 }) 110 })
186 111