diff options
Diffstat (limited to 'server/tests/api/check-params/video-blacklist.ts')
-rw-r--r-- | server/tests/api/check-params/video-blacklist.ts | 82 |
1 files changed, 62 insertions, 20 deletions
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 145f43980..3d4837d58 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts | |||
@@ -26,6 +26,7 @@ import { | |||
26 | } from '../../../../shared/extra-utils/requests/check-api-params' | 26 | } from '../../../../shared/extra-utils/requests/check-api-params' |
27 | import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' | 27 | import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' |
28 | import { expect } from 'chai' | 28 | import { expect } from 'chai' |
29 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
29 | 30 | ||
30 | describe('Test video blacklist API validators', function () { | 31 | describe('Test video blacklist API validators', function () { |
31 | let servers: ServerInfo[] | 32 | let servers: ServerInfo[] |
@@ -94,13 +95,19 @@ describe('Test video blacklist API validators', function () { | |||
94 | it('Should fail with a non authenticated user', async function () { | 95 | it('Should fail with a non authenticated user', async function () { |
95 | const path = basePath + servers[0].video + '/blacklist' | 96 | const path = basePath + servers[0].video + '/blacklist' |
96 | const fields = {} | 97 | const fields = {} |
97 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) | 98 | await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
98 | }) | 99 | }) |
99 | 100 | ||
100 | it('Should fail with a non admin user', async function () { | 101 | it('Should fail with a non admin user', async function () { |
101 | const path = basePath + servers[0].video + '/blacklist' | 102 | const path = basePath + servers[0].video + '/blacklist' |
102 | const fields = {} | 103 | const fields = {} |
103 | await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) | 104 | await makePostBodyRequest({ |
105 | url: servers[0].url, | ||
106 | path, | ||
107 | token: userAccessToken2, | ||
108 | fields, | ||
109 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | ||
110 | }) | ||
104 | }) | 111 | }) |
105 | 112 | ||
106 | it('Should fail with an invalid reason', async function () { | 113 | it('Should fail with an invalid reason', async function () { |
@@ -114,14 +121,26 @@ describe('Test video blacklist API validators', function () { | |||
114 | const path = basePath + remoteVideoUUID + '/blacklist' | 121 | const path = basePath + remoteVideoUUID + '/blacklist' |
115 | const fields = { unfederate: true } | 122 | const fields = { unfederate: true } |
116 | 123 | ||
117 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) | 124 | await makePostBodyRequest({ |
125 | url: servers[0].url, | ||
126 | path, | ||
127 | token: servers[0].accessToken, | ||
128 | fields, | ||
129 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | ||
130 | }) | ||
118 | }) | 131 | }) |
119 | 132 | ||
120 | it('Should succeed with the correct params', async function () { | 133 | it('Should succeed with the correct params', async function () { |
121 | const path = basePath + servers[0].video.uuid + '/blacklist' | 134 | const path = basePath + servers[0].video.uuid + '/blacklist' |
122 | const fields = {} | 135 | const fields = {} |
123 | 136 | ||
124 | await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) | 137 | await makePostBodyRequest({ |
138 | url: servers[0].url, | ||
139 | path, | ||
140 | token: servers[0].accessToken, | ||
141 | fields, | ||
142 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
143 | }) | ||
125 | }) | 144 | }) |
126 | }) | 145 | }) |
127 | 146 | ||
@@ -137,19 +156,31 @@ describe('Test video blacklist API validators', function () { | |||
137 | it('Should fail with a video not blacklisted', async function () { | 156 | it('Should fail with a video not blacklisted', async function () { |
138 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' | 157 | const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' |
139 | const fields = {} | 158 | const fields = {} |
140 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) | 159 | await makePutBodyRequest({ |
160 | url: servers[0].url, | ||
161 | path, | ||
162 | token: servers[0].accessToken, | ||
163 | fields, | ||
164 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | ||
165 | }) | ||
141 | }) | 166 | }) |
142 | 167 | ||
143 | it('Should fail with a non authenticated user', async function () { | 168 | it('Should fail with a non authenticated user', async function () { |
144 | const path = basePath + servers[0].video + '/blacklist' | 169 | const path = basePath + servers[0].video + '/blacklist' |
145 | const fields = {} | 170 | const fields = {} |
146 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) | 171 | await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) |
147 | }) | 172 | }) |
148 | 173 | ||
149 | it('Should fail with a non admin user', async function () { | 174 | it('Should fail with a non admin user', async function () { |
150 | const path = basePath + servers[0].video + '/blacklist' | 175 | const path = basePath + servers[0].video + '/blacklist' |
151 | const fields = {} | 176 | const fields = {} |
152 | await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) | 177 | await makePutBodyRequest({ |
178 | url: servers[0].url, | ||
179 | path, | ||
180 | token: userAccessToken2, | ||
181 | fields, | ||
182 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | ||
183 | }) | ||
153 | }) | 184 | }) |
154 | 185 | ||
155 | it('Should fail with an invalid reason', async function () { | 186 | it('Should fail with an invalid reason', async function () { |
@@ -163,29 +194,35 @@ describe('Test video blacklist API validators', function () { | |||
163 | const path = basePath + servers[0].video.uuid + '/blacklist' | 194 | const path = basePath + servers[0].video.uuid + '/blacklist' |
164 | const fields = { reason: 'hello' } | 195 | const fields = { reason: 'hello' } |
165 | 196 | ||
166 | await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) | 197 | await makePutBodyRequest({ |
198 | url: servers[0].url, | ||
199 | path, | ||
200 | token: servers[0].accessToken, | ||
201 | fields, | ||
202 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
203 | }) | ||
167 | }) | 204 | }) |
168 | }) | 205 | }) |
169 | 206 | ||
170 | describe('When getting blacklisted video', function () { | 207 | describe('When getting blacklisted video', function () { |
171 | 208 | ||
172 | it('Should fail with a non authenticated user', async function () { | 209 | it('Should fail with a non authenticated user', async function () { |
173 | await getVideo(servers[0].url, servers[0].video.uuid, 401) | 210 | await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) |
174 | }) | 211 | }) |
175 | 212 | ||
176 | it('Should fail with another user', async function () { | 213 | it('Should fail with another user', async function () { |
177 | await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) | 214 | await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) |
178 | }) | 215 | }) |
179 | 216 | ||
180 | it('Should succeed with the owner authenticated user', async function () { | 217 | it('Should succeed with the owner authenticated user', async function () { |
181 | const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) | 218 | const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) |
182 | const video: VideoDetails = res.body | 219 | const video: VideoDetails = res.body |
183 | 220 | ||
184 | expect(video.blacklisted).to.be.true | 221 | expect(video.blacklisted).to.be.true |
185 | }) | 222 | }) |
186 | 223 | ||
187 | it('Should succeed with an admin', async function () { | 224 | it('Should succeed with an admin', async function () { |
188 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) | 225 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.OK_200) |
189 | const video: VideoDetails = res.body | 226 | const video: VideoDetails = res.body |
190 | 227 | ||
191 | expect(video.blacklisted).to.be.true | 228 | expect(video.blacklisted).to.be.true |
@@ -194,24 +231,24 @@ describe('Test video blacklist API validators', function () { | |||
194 | 231 | ||
195 | describe('When removing a video in blacklist', function () { | 232 | describe('When removing a video in blacklist', function () { |
196 | it('Should fail with a non authenticated user', async function () { | 233 | it('Should fail with a non authenticated user', async function () { |
197 | await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) | 234 | await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) |
198 | }) | 235 | }) |
199 | 236 | ||
200 | it('Should fail with a non admin user', async function () { | 237 | it('Should fail with a non admin user', async function () { |
201 | await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) | 238 | await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) |
202 | }) | 239 | }) |
203 | 240 | ||
204 | it('Should fail with an incorrect id', async function () { | 241 | it('Should fail with an incorrect id', async function () { |
205 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) | 242 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) |
206 | }) | 243 | }) |
207 | 244 | ||
208 | it('Should fail with a not blacklisted video', async function () { | 245 | it('Should fail with a not blacklisted video', async function () { |
209 | // The video was not added to the blacklist so it should fail | 246 | // The video was not added to the blacklist so it should fail |
210 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) | 247 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) |
211 | }) | 248 | }) |
212 | 249 | ||
213 | it('Should succeed with the correct params', async function () { | 250 | it('Should succeed with the correct params', async function () { |
214 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) | 251 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) |
215 | }) | 252 | }) |
216 | }) | 253 | }) |
217 | 254 | ||
@@ -219,11 +256,11 @@ describe('Test video blacklist API validators', function () { | |||
219 | const basePath = '/api/v1/videos/blacklist/' | 256 | const basePath = '/api/v1/videos/blacklist/' |
220 | 257 | ||
221 | it('Should fail with a non authenticated user', async function () { | 258 | it('Should fail with a non authenticated user', async function () { |
222 | await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 }) | 259 | await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
223 | }) | 260 | }) |
224 | 261 | ||
225 | it('Should fail with a non admin user', async function () { | 262 | it('Should fail with a non admin user', async function () { |
226 | await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 }) | 263 | await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) |
227 | }) | 264 | }) |
228 | 265 | ||
229 | it('Should fail with a bad start pagination', async function () { | 266 | it('Should fail with a bad start pagination', async function () { |
@@ -239,7 +276,12 @@ describe('Test video blacklist API validators', function () { | |||
239 | }) | 276 | }) |
240 | 277 | ||
241 | it('Should fail with an invalid type', async function () { | 278 | it('Should fail with an invalid type', async function () { |
242 | await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 }) | 279 | await getBlacklistedVideosList({ |
280 | url: servers[0].url, | ||
281 | token: servers[0].accessToken, | ||
282 | type: 0, | ||
283 | specialStatus: HttpStatusCode.BAD_REQUEST_400 | ||
284 | }) | ||
243 | }) | 285 | }) |
244 | 286 | ||
245 | it('Should succeed with the correct parameters', async function () { | 287 | it('Should succeed with the correct parameters', async function () { |