aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-comments.ts')
-rw-r--r--server/tests/api/check-params/video-comments.ts109
1 files changed, 84 insertions, 25 deletions
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 662d4a70d..659a10c41 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' 22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24const expect = chai.expect 25const expect = chai.expect
25 26
@@ -83,7 +84,7 @@ describe('Test video comments API validator', function () {
83 await makeGetRequest({ 84 await makeGetRequest({
84 url: server.url, 85 url: server.url,
85 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', 86 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
86 statusCodeExpected: 404 87 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
87 }) 88 })
88 }) 89 })
89 }) 90 })
@@ -93,7 +94,7 @@ describe('Test video comments API validator', function () {
93 await makeGetRequest({ 94 await makeGetRequest({
94 url: server.url, 95 url: server.url,
95 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, 96 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
96 statusCodeExpected: 404 97 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
97 }) 98 })
98 }) 99 })
99 100
@@ -101,7 +102,7 @@ describe('Test video comments API validator', function () {
101 await makeGetRequest({ 102 await makeGetRequest({
102 url: server.url, 103 url: server.url,
103 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', 104 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
104 statusCodeExpected: 404 105 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
105 }) 106 })
106 }) 107 })
107 108
@@ -109,7 +110,7 @@ describe('Test video comments API validator', function () {
109 await makeGetRequest({ 110 await makeGetRequest({
110 url: server.url, 111 url: server.url,
111 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, 112 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
112 statusCodeExpected: 200 113 statusCodeExpected: HttpStatusCode.OK_200
113 }) 114 })
114 }) 115 })
115 }) 116 })
@@ -120,7 +121,13 @@ describe('Test video comments API validator', function () {
120 const fields = { 121 const fields = {
121 text: 'text' 122 text: 'text'
122 } 123 }
123 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) 124 await makePostBodyRequest({
125 url: server.url,
126 path: pathThread,
127 token: 'none',
128 fields,
129 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
130 })
124 }) 131 })
125 132
126 it('Should fail with nothing', async function () { 133 it('Should fail with nothing', async function () {
@@ -147,14 +154,26 @@ describe('Test video comments API validator', function () {
147 const fields = { 154 const fields = {
148 text: 'super comment' 155 text: 'super comment'
149 } 156 }
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 157 await makePostBodyRequest({
158 url: server.url,
159 path,
160 token: server.accessToken,
161 fields,
162 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
163 })
151 }) 164 })
152 165
153 it('Should succeed with the correct parameters', async function () { 166 it('Should succeed with the correct parameters', async function () {
154 const fields = { 167 const fields = {
155 text: 'super comment' 168 text: 'super comment'
156 } 169 }
157 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) 170 await makePostBodyRequest({
171 url: server.url,
172 path: pathThread,
173 token: server.accessToken,
174 fields,
175 statusCodeExpected: HttpStatusCode.OK_200
176 })
158 }) 177 })
159 }) 178 })
160 179
@@ -163,7 +182,13 @@ describe('Test video comments API validator', function () {
163 const fields = { 182 const fields = {
164 text: 'text' 183 text: 'text'
165 } 184 }
166 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) 185 await makePostBodyRequest({
186 url: server.url,
187 path: pathComment,
188 token: 'none',
189 fields,
190 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
191 })
167 }) 192 })
168 193
169 it('Should fail with nothing', async function () { 194 it('Should fail with nothing', async function () {
@@ -190,7 +215,13 @@ describe('Test video comments API validator', function () {
190 const fields = { 215 const fields = {
191 text: 'super comment' 216 text: 'super comment'
192 } 217 }
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 218 await makePostBodyRequest({
219 url: server.url,
220 path,
221 token: server.accessToken,
222 fields,
223 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
224 })
194 }) 225 })
195 226
196 it('Should fail with an incorrect comment', async function () { 227 it('Should fail with an incorrect comment', async function () {
@@ -198,34 +229,51 @@ describe('Test video comments API validator', function () {
198 const fields = { 229 const fields = {
199 text: 'super comment' 230 text: 'super comment'
200 } 231 }
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 232 await makePostBodyRequest({
233 url: server.url,
234 path,
235 token: server.accessToken,
236 fields,
237 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
238 })
202 }) 239 })
203 240
204 it('Should succeed with the correct parameters', async function () { 241 it('Should succeed with the correct parameters', async function () {
205 const fields = { 242 const fields = {
206 text: 'super comment' 243 text: 'super comment'
207 } 244 }
208 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) 245 await makePostBodyRequest({
246 url: server.url,
247 path: pathComment,
248 token: server.accessToken,
249 fields,
250 statusCodeExpected: HttpStatusCode.OK_200
251 })
209 }) 252 })
210 }) 253 })
211 254
212 describe('When removing video comments', function () { 255 describe('When removing video comments', function () {
213 it('Should fail with a non authenticated user', async function () { 256 it('Should fail with a non authenticated user', async function () {
214 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 }) 257 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
215 }) 258 })
216 259
217 it('Should fail with another user', async function () { 260 it('Should fail with another user', async function () {
218 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 }) 261 await makeDeleteRequest({
262 url: server.url,
263 path: pathComment,
264 token: userAccessToken,
265 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
266 })
219 }) 267 })
220 268
221 it('Should fail with an incorrect video', async function () { 269 it('Should fail with an incorrect video', async function () {
222 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId 270 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
223 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 271 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
224 }) 272 })
225 273
226 it('Should fail with an incorrect comment', async function () { 274 it('Should fail with an incorrect comment', async function () {
227 const path = '/api/v1/videos/' + videoUUID + '/comments/124' 275 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
228 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 276 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
229 }) 277 })
230 278
231 it('Should succeed with the same user', async function () { 279 it('Should succeed with the same user', async function () {
@@ -238,8 +286,8 @@ describe('Test video comments API validator', function () {
238 286
239 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete 287 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
240 288
241 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 289 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
242 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 290 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
243 }) 291 })
244 292
245 it('Should succeed with the owner of the video', async function () { 293 it('Should succeed with the owner of the video', async function () {
@@ -258,12 +306,17 @@ describe('Test video comments API validator', function () {
258 306
259 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete 307 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
260 308
261 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 309 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
262 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 310 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
263 }) 311 })
264 312
265 it('Should succeed with the correct parameters', async function () { 313 it('Should succeed with the correct parameters', async function () {
266 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) 314 await makeDeleteRequest({
315 url: server.url,
316 path: pathComment,
317 token: server.accessToken,
318 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
319 })
267 }) 320 })
268 }) 321 })
269 322
@@ -278,7 +331,7 @@ describe('Test video comments API validator', function () {
278 const res = await makeGetRequest({ 331 const res = await makeGetRequest({
279 url: server.url, 332 url: server.url,
280 path: pathThread, 333 path: pathThread,
281 statusCodeExpected: 200 334 statusCodeExpected: HttpStatusCode.OK_200
282 }) 335 })
283 expect(res.body.total).to.equal(0) 336 expect(res.body.total).to.equal(0)
284 expect(res.body.data).to.have.lengthOf(0) 337 expect(res.body.data).to.have.lengthOf(0)
@@ -290,7 +343,13 @@ describe('Test video comments API validator', function () {
290 const fields = { 343 const fields = {
291 text: 'super comment' 344 text: 'super comment'
292 } 345 }
293 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) 346 await makePostBodyRequest({
347 url: server.url,
348 path: pathThread,
349 token: server.accessToken,
350 fields,
351 statusCodeExpected: HttpStatusCode.CONFLICT_409
352 })
294 }) 353 })
295 354
296 it('Should return conflict on comment thread add') 355 it('Should return conflict on comment thread add')
@@ -315,7 +374,7 @@ describe('Test video comments API validator', function () {
315 await makeGetRequest({ 374 await makeGetRequest({
316 url: server.url, 375 url: server.url,
317 path, 376 path,
318 statusCodeExpected: 401 377 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
319 }) 378 })
320 }) 379 })
321 380
@@ -324,7 +383,7 @@ describe('Test video comments API validator', function () {
324 url: server.url, 383 url: server.url,
325 path, 384 path,
326 token: userAccessToken, 385 token: userAccessToken,
327 statusCodeExpected: 403 386 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
328 }) 387 })
329 }) 388 })
330 389
@@ -339,7 +398,7 @@ describe('Test video comments API validator', function () {
339 searchAccount: 'toto', 398 searchAccount: 'toto',
340 searchVideo: 'toto' 399 searchVideo: 'toto'
341 }, 400 },
342 statusCodeExpected: 200 401 statusCodeExpected: HttpStatusCode.OK_200
343 }) 402 })
344 }) 403 })
345 }) 404 })