aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-comments.ts39
-rw-r--r--server/tests/api/videos/multiple-servers.ts33
-rw-r--r--server/tests/api/videos/video-comments.ts38
-rw-r--r--server/tests/utils/videos/video-comments.ts21
4 files changed, 126 insertions, 5 deletions
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index c11660d07..9190054da 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -3,8 +3,9 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers, 6 createUser,
7 uploadVideo 7 flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
8 uploadVideo, userLogin
8} from '../../utils' 9} from '../../utils'
9import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 10import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
10import { addVideoCommentThread } from '../../utils/videos/video-comments' 11import { addVideoCommentThread } from '../../utils/videos/video-comments'
@@ -16,6 +17,7 @@ describe('Test video comments API validator', function () {
16 let pathComment: string 17 let pathComment: string
17 let server: ServerInfo 18 let server: ServerInfo
18 let videoUUID: string 19 let videoUUID: string
20 let userAccessToken: string
19 let commentId: number 21 let commentId: number
20 22
21 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
@@ -40,6 +42,15 @@ describe('Test video comments API validator', function () {
40 commentId = res.body.comment.id 42 commentId = res.body.comment.id
41 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId 43 pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
42 } 44 }
45
46 {
47 const user = {
48 username: 'user1',
49 password: 'my super password'
50 }
51 await createUser(server.url, server.accessToken, user.username, user.password)
52 userAccessToken = await userLogin(server, user)
53 }
43 }) 54 })
44 55
45 describe('When listing video comment threads', function () { 56 describe('When listing video comment threads', function () {
@@ -185,6 +196,30 @@ describe('Test video comments API validator', function () {
185 }) 196 })
186 }) 197 })
187 198
199 describe('When removing video comments', function () {
200 it('Should fail with a non authenticated user', async function () {
201 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 })
202 })
203
204 it('Should fail with another user', async function () {
205 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 })
206 })
207
208 it('Should fail with an incorrect video', async function () {
209 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
210 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
211 })
212
213 it('Should fail with an incorrect comment', async function () {
214 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
215 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 })
216 })
217
218 it('Should succeed with the correct parameters', async function () {
219 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 })
220 })
221 })
222
188 describe('When a video has comments disabled', function () { 223 describe('When a video has comments disabled', function () {
189 before(async function () { 224 before(async function () {
190 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) 225 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index b6dfe0d1b..6712829d4 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -13,7 +13,7 @@ import {
13 updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd 13 updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
14} from '../../utils' 14} from '../../utils'
15import { 15import {
16 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, 16 addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
17 getVideoThreadComments 17 getVideoThreadComments
18} from '../../utils/videos/video-comments' 18} from '../../utils/videos/video-comments'
19 19
@@ -738,6 +738,37 @@ describe('Test multiple servers', function () {
738 } 738 }
739 }) 739 })
740 740
741 it('Should delete the thread comments', async function () {
742 this.timeout(10000)
743
744 const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
745 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
746 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
747
748 await wait(5000)
749 })
750
751 it('Should have the thread comments deleted on other servers too', async function () {
752 for (const server of servers) {
753 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
754
755 expect(res.body.total).to.equal(1)
756 expect(res.body.data).to.be.an('array')
757 expect(res.body.data).to.have.lengthOf(1)
758
759 {
760 const comment: VideoComment = res.body.data[0]
761 expect(comment).to.not.be.undefined
762 expect(comment.inReplyToCommentId).to.be.null
763 expect(comment.account.name).to.equal('root')
764 expect(comment.account.host).to.equal('localhost:9003')
765 expect(comment.totalReplies).to.equal(0)
766 expect(dateIsValid(comment.createdAt as string)).to.be.true
767 expect(dateIsValid(comment.updatedAt as string)).to.be.true
768 }
769 }
770 })
771
741 it('Should disable comments', async function () { 772 it('Should disable comments', async function () {
742 this.timeout(20000) 773 this.timeout(20000)
743 774
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 604a3027d..18d484ccf 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -9,7 +9,7 @@ import {
9 uploadVideo 9 uploadVideo
10} from '../../utils/index' 10} from '../../utils/index'
11import { 11import {
12 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, 12 addVideoCommentReply, addVideoCommentThread, deleteVideoComment, getVideoCommentThreads,
13 getVideoThreadComments 13 getVideoThreadComments
14} from '../../utils/videos/video-comments' 14} from '../../utils/videos/video-comments'
15 15
@@ -20,6 +20,7 @@ describe('Test video comments', function () {
20 let videoId 20 let videoId
21 let videoUUID 21 let videoUUID
22 let threadId 22 let threadId
23 let replyToDeleteId: number
23 24
24 before(async function () { 25 before(async function () {
25 this.timeout(10000) 26 this.timeout(10000)
@@ -61,6 +62,7 @@ describe('Test video comments', function () {
61 expect(comment.id).to.equal(comment.threadId) 62 expect(comment.id).to.equal(comment.threadId)
62 expect(comment.account.name).to.equal('root') 63 expect(comment.account.name).to.equal('root')
63 expect(comment.account.host).to.equal('localhost:9001') 64 expect(comment.account.host).to.equal('localhost:9001')
65 expect(comment.account.url).to.equal('http://localhost:9001/accounts/root')
64 expect(comment.totalReplies).to.equal(0) 66 expect(comment.totalReplies).to.equal(0)
65 expect(dateIsValid(comment.createdAt as string)).to.be.true 67 expect(dateIsValid(comment.createdAt as string)).to.be.true
66 expect(dateIsValid(comment.updatedAt as string)).to.be.true 68 expect(dateIsValid(comment.updatedAt as string)).to.be.true
@@ -132,6 +134,8 @@ describe('Test video comments', function () {
132 const secondChild = tree.children[1] 134 const secondChild = tree.children[1]
133 expect(secondChild.comment.text).to.equal('my second answer to thread 1') 135 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
134 expect(secondChild.children).to.have.lengthOf(0) 136 expect(secondChild.children).to.have.lengthOf(0)
137
138 replyToDeleteId = secondChild.comment.id
135 }) 139 })
136 140
137 it('Should create other threads', async function () { 141 it('Should create other threads', async function () {
@@ -157,6 +161,38 @@ describe('Test video comments', function () {
157 expect(res.body.data[2].totalReplies).to.equal(0) 161 expect(res.body.data[2].totalReplies).to.equal(0)
158 }) 162 })
159 163
164 it('Should delete a reply', async function () {
165 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId)
166
167 const res = await getVideoThreadComments(server.url, videoUUID, threadId)
168
169 const tree: VideoCommentThreadTree = res.body
170 expect(tree.comment.text).equal('my super first comment')
171 expect(tree.children).to.have.lengthOf(1)
172
173 const firstChild = tree.children[0]
174 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
175 expect(firstChild.children).to.have.lengthOf(1)
176
177 const childOfFirstChild = firstChild.children[0]
178 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
179 expect(childOfFirstChild.children).to.have.lengthOf(0)
180 })
181
182 it('Should delete a complete thread', async function () {
183 await deleteVideoComment(server.url, server.accessToken, videoId, threadId)
184
185 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt')
186 expect(res.body.total).to.equal(2)
187 expect(res.body.data).to.be.an('array')
188 expect(res.body.data).to.have.lengthOf(2)
189
190 expect(res.body.data[0].text).to.equal('super thread 2')
191 expect(res.body.data[0].totalReplies).to.equal(0)
192 expect(res.body.data[1].text).to.equal('super thread 3')
193 expect(res.body.data[1].totalReplies).to.equal(0)
194 })
195
160 after(async function () { 196 after(async function () {
161 killallServers([ server ]) 197 killallServers([ server ])
162 198
diff --git a/server/tests/utils/videos/video-comments.ts b/server/tests/utils/videos/video-comments.ts
index 878147049..1b9ee452e 100644
--- a/server/tests/utils/videos/video-comments.ts
+++ b/server/tests/utils/videos/video-comments.ts
@@ -1,4 +1,5 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2import { makeDeleteRequest } from '../'
2 3
3function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) { 4function getVideoCommentThreads (url: string, videoId: number | string, start: number, count: number, sort?: string) {
4 const path = '/api/v1/videos/' + videoId + '/comment-threads' 5 const path = '/api/v1/videos/' + videoId + '/comment-threads'
@@ -54,11 +55,29 @@ function addVideoCommentReply (
54 .expect(expectedStatus) 55 .expect(expectedStatus)
55} 56}
56 57
58function deleteVideoComment (
59 url: string,
60 token: string,
61 videoId: number | string,
62 commentId: number,
63 statusCodeExpected = 204
64) {
65 const path = '/api/v1/videos/' + videoId + '/comments/' + commentId
66
67 return makeDeleteRequest({
68 url,
69 path,
70 token,
71 statusCodeExpected
72 })
73}
74
57// --------------------------------------------------------------------------- 75// ---------------------------------------------------------------------------
58 76
59export { 77export {
60 getVideoCommentThreads, 78 getVideoCommentThreads,
61 getVideoThreadComments, 79 getVideoThreadComments,
62 addVideoCommentThread, 80 addVideoCommentThread,
63 addVideoCommentReply 81 addVideoCommentReply,
82 deleteVideoComment
64} 83}