aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-comments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-comments.ts')
-rw-r--r--server/tests/api/videos/video-comments.ts193
1 files changed, 88 insertions, 105 deletions
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index b6b002307..548d9fbf5 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -2,38 +2,33 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models'
6import { cleanupTests, testImage } from '../../../../shared/extra-utils'
7import { 5import {
6 cleanupTests,
7 CommentsCommand,
8 createUser, 8 createUser,
9 dateIsValid, 9 dateIsValid,
10 flushAndRunServer, 10 flushAndRunServer,
11 getAccessToken, 11 getAccessToken,
12 ServerInfo, 12 ServerInfo,
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 testImage,
14 updateMyAvatar, 15 updateMyAvatar,
15 uploadVideo 16 uploadVideo
16} from '../../../../shared/extra-utils/index' 17} from '@shared/extra-utils'
17import {
18 addVideoCommentReply,
19 addVideoCommentThread,
20 deleteVideoComment,
21 getAdminVideoComments,
22 getVideoCommentThreads,
23 getVideoThreadComments
24} from '../../../../shared/extra-utils/videos/video-comments'
25 18
26const expect = chai.expect 19const expect = chai.expect
27 20
28describe('Test video comments', function () { 21describe('Test video comments', function () {
29 let server: ServerInfo 22 let server: ServerInfo
30 let videoId 23 let videoId: number
31 let videoUUID 24 let videoUUID: string
32 let threadId 25 let threadId: number
33 let replyToDeleteId: number 26 let replyToDeleteId: number
34 27
35 let userAccessTokenServer1: string 28 let userAccessTokenServer1: string
36 29
30 let command: CommentsCommand
31
37 before(async function () { 32 before(async function () {
38 this.timeout(30000) 33 this.timeout(30000)
39 34
@@ -58,24 +53,25 @@ describe('Test video comments', function () {
58 password: 'password' 53 password: 'password'
59 }) 54 })
60 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') 55 userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password')
56
57 command = server.commentsCommand
61 }) 58 })
62 59
63 describe('User comments', function () { 60 describe('User comments', function () {
64 61
65 it('Should not have threads on this video', async function () { 62 it('Should not have threads on this video', async function () {
66 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 63 const body = await command.listThreads({ videoId: videoUUID })
67 64
68 expect(res.body.total).to.equal(0) 65 expect(body.total).to.equal(0)
69 expect(res.body.totalNotDeletedComments).to.equal(0) 66 expect(body.totalNotDeletedComments).to.equal(0)
70 expect(res.body.data).to.be.an('array') 67 expect(body.data).to.be.an('array')
71 expect(res.body.data).to.have.lengthOf(0) 68 expect(body.data).to.have.lengthOf(0)
72 }) 69 })
73 70
74 it('Should create a thread in this video', async function () { 71 it('Should create a thread in this video', async function () {
75 const text = 'my super first comment' 72 const text = 'my super first comment'
76 73
77 const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 74 const comment = await command.createThread({ videoId: videoUUID, text })
78 const comment = res.body.comment
79 75
80 expect(comment.inReplyToCommentId).to.be.null 76 expect(comment.inReplyToCommentId).to.be.null
81 expect(comment.text).equal('my super first comment') 77 expect(comment.text).equal('my super first comment')
@@ -91,14 +87,14 @@ describe('Test video comments', function () {
91 }) 87 })
92 88
93 it('Should list threads of this video', async function () { 89 it('Should list threads of this video', async function () {
94 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 90 const body = await command.listThreads({ videoId: videoUUID })
95 91
96 expect(res.body.total).to.equal(1) 92 expect(body.total).to.equal(1)
97 expect(res.body.totalNotDeletedComments).to.equal(1) 93 expect(body.totalNotDeletedComments).to.equal(1)
98 expect(res.body.data).to.be.an('array') 94 expect(body.data).to.be.an('array')
99 expect(res.body.data).to.have.lengthOf(1) 95 expect(body.data).to.have.lengthOf(1)
100 96
101 const comment: VideoComment = res.body.data[0] 97 const comment = body.data[0]
102 expect(comment.inReplyToCommentId).to.be.null 98 expect(comment.inReplyToCommentId).to.be.null
103 expect(comment.text).equal('my super first comment') 99 expect(comment.text).equal('my super first comment')
104 expect(comment.videoId).to.equal(videoId) 100 expect(comment.videoId).to.equal(videoId)
@@ -117,9 +113,9 @@ describe('Test video comments', function () {
117 }) 113 })
118 114
119 it('Should get all the thread created', async function () { 115 it('Should get all the thread created', async function () {
120 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 116 const body = await command.getThread({ videoId: videoUUID, threadId })
121 117
122 const rootComment = res.body.comment 118 const rootComment = body.comment
123 expect(rootComment.inReplyToCommentId).to.be.null 119 expect(rootComment.inReplyToCommentId).to.be.null
124 expect(rootComment.text).equal('my super first comment') 120 expect(rootComment.text).equal('my super first comment')
125 expect(rootComment.videoId).to.equal(videoId) 121 expect(rootComment.videoId).to.equal(videoId)
@@ -129,20 +125,19 @@ describe('Test video comments', function () {
129 125
130 it('Should create multiple replies in this thread', async function () { 126 it('Should create multiple replies in this thread', async function () {
131 const text1 = 'my super answer to thread 1' 127 const text1 = 'my super answer to thread 1'
132 const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) 128 const created = await command.addReply({ videoId, toCommentId: threadId, text: text1 })
133 const childCommentId = childCommentRes.body.comment.id 129 const childCommentId = created.id
134 130
135 const text2 = 'my super answer to answer of thread 1' 131 const text2 = 'my super answer to answer of thread 1'
136 await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) 132 await command.addReply({ videoId, toCommentId: childCommentId, text: text2 })
137 133
138 const text3 = 'my second answer to thread 1' 134 const text3 = 'my second answer to thread 1'
139 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) 135 await command.addReply({ videoId, toCommentId: threadId, text: text3 })
140 }) 136 })
141 137
142 it('Should get correctly the replies', async function () { 138 it('Should get correctly the replies', async function () {
143 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 139 const tree = await command.getThread({ videoId: videoUUID, threadId })
144 140
145 const tree: VideoCommentThreadTree = res.body
146 expect(tree.comment.text).equal('my super first comment') 141 expect(tree.comment.text).equal('my super first comment')
147 expect(tree.children).to.have.lengthOf(2) 142 expect(tree.children).to.have.lengthOf(2)
148 143
@@ -163,42 +158,41 @@ describe('Test video comments', function () {
163 158
164 it('Should create other threads', async function () { 159 it('Should create other threads', async function () {
165 const text1 = 'super thread 2' 160 const text1 = 'super thread 2'
166 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) 161 await command.createThread({ videoId: videoUUID, text: text1 })
167 162
168 const text2 = 'super thread 3' 163 const text2 = 'super thread 3'
169 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) 164 await command.createThread({ videoId: videoUUID, text: text2 })
170 }) 165 })
171 166
172 it('Should list the threads', async function () { 167 it('Should list the threads', async function () {
173 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 168 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
174 169
175 expect(res.body.total).to.equal(3) 170 expect(body.total).to.equal(3)
176 expect(res.body.totalNotDeletedComments).to.equal(6) 171 expect(body.totalNotDeletedComments).to.equal(6)
177 expect(res.body.data).to.be.an('array') 172 expect(body.data).to.be.an('array')
178 expect(res.body.data).to.have.lengthOf(3) 173 expect(body.data).to.have.lengthOf(3)
179 174
180 expect(res.body.data[0].text).to.equal('my super first comment') 175 expect(body.data[0].text).to.equal('my super first comment')
181 expect(res.body.data[0].totalReplies).to.equal(3) 176 expect(body.data[0].totalReplies).to.equal(3)
182 expect(res.body.data[1].text).to.equal('super thread 2') 177 expect(body.data[1].text).to.equal('super thread 2')
183 expect(res.body.data[1].totalReplies).to.equal(0) 178 expect(body.data[1].totalReplies).to.equal(0)
184 expect(res.body.data[2].text).to.equal('super thread 3') 179 expect(body.data[2].text).to.equal('super thread 3')
185 expect(res.body.data[2].totalReplies).to.equal(0) 180 expect(body.data[2].totalReplies).to.equal(0)
186 }) 181 })
187 182
188 it('Should delete a reply', async function () { 183 it('Should delete a reply', async function () {
189 await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) 184 await command.delete({ videoId, commentId: replyToDeleteId })
190 185
191 { 186 {
192 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 187 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
193 188
194 expect(res.body.total).to.equal(3) 189 expect(body.total).to.equal(3)
195 expect(res.body.totalNotDeletedComments).to.equal(5) 190 expect(body.totalNotDeletedComments).to.equal(5)
196 } 191 }
197 192
198 { 193 {
199 const res = await getVideoThreadComments(server.url, videoUUID, threadId) 194 const tree = await command.getThread({ videoId: videoUUID, threadId })
200 195
201 const tree: VideoCommentThreadTree = res.body
202 expect(tree.comment.text).equal('my super first comment') 196 expect(tree.comment.text).equal('my super first comment')
203 expect(tree.children).to.have.lengthOf(2) 197 expect(tree.children).to.have.lengthOf(2)
204 198
@@ -220,99 +214,88 @@ describe('Test video comments', function () {
220 }) 214 })
221 215
222 it('Should delete a complete thread', async function () { 216 it('Should delete a complete thread', async function () {
223 await deleteVideoComment(server.url, server.accessToken, videoId, threadId) 217 await command.delete({ videoId, commentId: threadId })
224 218
225 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') 219 const body = await command.listThreads({ videoId: videoUUID, sort: 'createdAt' })
226 expect(res.body.total).to.equal(3) 220 expect(body.total).to.equal(3)
227 expect(res.body.data).to.be.an('array') 221 expect(body.data).to.be.an('array')
228 expect(res.body.data).to.have.lengthOf(3) 222 expect(body.data).to.have.lengthOf(3)
229 223
230 expect(res.body.data[0].text).to.equal('') 224 expect(body.data[0].text).to.equal('')
231 expect(res.body.data[0].isDeleted).to.be.true 225 expect(body.data[0].isDeleted).to.be.true
232 expect(res.body.data[0].deletedAt).to.not.be.null 226 expect(body.data[0].deletedAt).to.not.be.null
233 expect(res.body.data[0].account).to.be.null 227 expect(body.data[0].account).to.be.null
234 expect(res.body.data[0].totalReplies).to.equal(2) 228 expect(body.data[0].totalReplies).to.equal(2)
235 expect(res.body.data[1].text).to.equal('super thread 2') 229 expect(body.data[1].text).to.equal('super thread 2')
236 expect(res.body.data[1].totalReplies).to.equal(0) 230 expect(body.data[1].totalReplies).to.equal(0)
237 expect(res.body.data[2].text).to.equal('super thread 3') 231 expect(body.data[2].text).to.equal('super thread 3')
238 expect(res.body.data[2].totalReplies).to.equal(0) 232 expect(body.data[2].totalReplies).to.equal(0)
239 }) 233 })
240 234
241 it('Should count replies from the video author correctly', async function () { 235 it('Should count replies from the video author correctly', async function () {
242 const text = 'my super first comment' 236 await command.createThread({ videoId: videoUUID, text: 'my super first comment' })
243 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) 237
244 let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 238 const { data } = await command.listThreads({ videoId: videoUUID })
245 const comment: VideoComment = res.body.data[0] 239 const threadId2 = data[0].threadId
246 const threadId2 = comment.threadId
247 240
248 const text2 = 'a first answer to thread 4 by a third party' 241 const text2 = 'a first answer to thread 4 by a third party'
249 await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) 242 await command.addReply({ token: userAccessTokenServer1, videoId, toCommentId: threadId2, text: text2 })
250 243
251 const text3 = 'my second answer to thread 4' 244 const text3 = 'my second answer to thread 4'
252 await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) 245 await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
253 246
254 res = await getVideoThreadComments(server.url, videoUUID, threadId2) 247 const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
255 const tree: VideoCommentThreadTree = res.body
256 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) 248 expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
257 }) 249 })
258 }) 250 })
259 251
260 describe('All instance comments', function () { 252 describe('All instance comments', function () {
261 async function getComments (options: any = {}) {
262 const res = await getAdminVideoComments(Object.assign({
263 url: server.url,
264 token: server.accessToken,
265 start: 0,
266 count: 10
267 }, options))
268
269 return { comments: res.body.data as VideoCommentAdmin[], total: res.body.total as number }
270 }
271 253
272 it('Should list instance comments as admin', async function () { 254 it('Should list instance comments as admin', async function () {
273 const { comments } = await getComments({ start: 0, count: 1 }) 255 const { data } = await command.listForAdmin({ start: 0, count: 1 })
274 256
275 expect(comments[0].text).to.equal('my second answer to thread 4') 257 expect(data[0].text).to.equal('my second answer to thread 4')
276 }) 258 })
277 259
278 it('Should filter instance comments by isLocal', async function () { 260 it('Should filter instance comments by isLocal', async function () {
279 const { total, comments } = await getComments({ isLocal: false }) 261 const { total, data } = await command.listForAdmin({ isLocal: false })
280 262
281 expect(comments).to.have.lengthOf(0) 263 expect(data).to.have.lengthOf(0)
282 expect(total).to.equal(0) 264 expect(total).to.equal(0)
283 }) 265 })
284 266
285 it('Should search instance comments by account', async function () { 267 it('Should search instance comments by account', async function () {
286 const { total, comments } = await getComments({ searchAccount: 'user' }) 268 const { total, data } = await command.listForAdmin({ searchAccount: 'user' })
287 269
288 expect(comments).to.have.lengthOf(1) 270 expect(data).to.have.lengthOf(1)
289 expect(total).to.equal(1) 271 expect(total).to.equal(1)
290 272
291 expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') 273 expect(data[0].text).to.equal('a first answer to thread 4 by a third party')
292 }) 274 })
293 275
294 it('Should search instance comments by video', async function () { 276 it('Should search instance comments by video', async function () {
295 { 277 {
296 const { total, comments } = await getComments({ searchVideo: 'video' }) 278 const { total, data } = await command.listForAdmin({ searchVideo: 'video' })
297 279
298 expect(comments).to.have.lengthOf(7) 280 expect(data).to.have.lengthOf(7)
299 expect(total).to.equal(7) 281 expect(total).to.equal(7)
300 } 282 }
301 283
302 { 284 {
303 const { total, comments } = await getComments({ searchVideo: 'hello' }) 285 const { total, data } = await command.listForAdmin({ searchVideo: 'hello' })
304 286
305 expect(comments).to.have.lengthOf(0) 287 expect(data).to.have.lengthOf(0)
306 expect(total).to.equal(0) 288 expect(total).to.equal(0)
307 } 289 }
308 }) 290 })
309 291
310 it('Should search instance comments', async function () { 292 it('Should search instance comments', async function () {
311 const { total, comments } = await getComments({ search: 'super thread 3' }) 293 const { total, data } = await command.listForAdmin({ search: 'super thread 3' })
312 294
313 expect(comments).to.have.lengthOf(1)
314 expect(total).to.equal(1) 295 expect(total).to.equal(1)
315 expect(comments[0].text).to.equal('super thread 3') 296
297 expect(data).to.have.lengthOf(1)
298 expect(data[0].text).to.equal('super thread 3')
316 }) 299 })
317 }) 300 })
318 301