diff options
Diffstat (limited to 'server/tests/api/check-params/video-comments.ts')
-rw-r--r-- | server/tests/api/check-params/video-comments.ts | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 5cf90bacc..181282ce1 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
@@ -29,6 +29,7 @@ describe('Test video comments API validator', function () { | |||
29 | let server: ServerInfo | 29 | let server: ServerInfo |
30 | let videoUUID: string | 30 | let videoUUID: string |
31 | let userAccessToken: string | 31 | let userAccessToken: string |
32 | let userAccessToken2: string | ||
32 | let commentId: number | 33 | let commentId: number |
33 | 34 | ||
34 | // --------------------------------------------------------------- | 35 | // --------------------------------------------------------------- |
@@ -53,13 +54,16 @@ describe('Test video comments API validator', function () { | |||
53 | } | 54 | } |
54 | 55 | ||
55 | { | 56 | { |
56 | const user = { | 57 | const user = { username: 'user1', password: 'my super password' } |
57 | username: 'user1', | ||
58 | password: 'my super password' | ||
59 | } | ||
60 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 58 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
61 | userAccessToken = await userLogin(server, user) | 59 | userAccessToken = await userLogin(server, user) |
62 | } | 60 | } |
61 | |||
62 | { | ||
63 | const user = { username: 'user2', password: 'my super password' } | ||
64 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | ||
65 | userAccessToken2 = await userLogin(server, user) | ||
66 | } | ||
63 | }) | 67 | }) |
64 | 68 | ||
65 | describe('When listing video comment threads', function () { | 69 | describe('When listing video comment threads', function () { |
@@ -133,7 +137,7 @@ describe('Test video comments API validator', function () { | |||
133 | 137 | ||
134 | it('Should fail with a long comment', async function () { | 138 | it('Should fail with a long comment', async function () { |
135 | const fields = { | 139 | const fields = { |
136 | text: 'h'.repeat(3001) | 140 | text: 'h'.repeat(10001) |
137 | } | 141 | } |
138 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) | 142 | await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields }) |
139 | }) | 143 | }) |
@@ -176,7 +180,7 @@ describe('Test video comments API validator', function () { | |||
176 | 180 | ||
177 | it('Should fail with a long comment', async function () { | 181 | it('Should fail with a long comment', async function () { |
178 | const fields = { | 182 | const fields = { |
179 | text: 'h'.repeat(3001) | 183 | text: 'h'.repeat(10001) |
180 | } | 184 | } |
181 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) | 185 | await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields }) |
182 | }) | 186 | }) |
@@ -224,6 +228,40 @@ describe('Test video comments API validator', function () { | |||
224 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) | 228 | await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) |
225 | }) | 229 | }) |
226 | 230 | ||
231 | it('Should succeed with the same user', async function () { | ||
232 | let commentToDelete: number | ||
233 | |||
234 | { | ||
235 | const res = await addVideoCommentThread(server.url, userAccessToken, videoUUID, 'hello') | ||
236 | commentToDelete = res.body.comment.id | ||
237 | } | ||
238 | |||
239 | const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete | ||
240 | |||
241 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) | ||
242 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) | ||
243 | }) | ||
244 | |||
245 | it('Should succeed with the owner of the video', async function () { | ||
246 | let commentToDelete: number | ||
247 | let anotherVideoUUID: string | ||
248 | |||
249 | { | ||
250 | const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) | ||
251 | anotherVideoUUID = res.body.video.uuid | ||
252 | } | ||
253 | |||
254 | { | ||
255 | const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello') | ||
256 | commentToDelete = res.body.comment.id | ||
257 | } | ||
258 | |||
259 | const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete | ||
260 | |||
261 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) | ||
262 | await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) | ||
263 | }) | ||
264 | |||
227 | it('Should succeed with the correct parameters', async function () { | 265 | it('Should succeed with the correct parameters', async function () { |
228 | await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) | 266 | await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) |
229 | }) | 267 | }) |