]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d3ea8975 | 2 | |
d3ea8975 | 3 | import 'mocha' |
19149d45 | 4 | import * as chai from 'chai' |
2b02c520 | 5 | import { VideoComment, VideoCommentAdmin, VideoCommentThreadTree } from '@shared/models' |
7c3b7976 | 6 | import { cleanupTests, testImage } from '../../../../shared/extra-utils' |
cf117aaa | 7 | import { |
a1587156 | 8 | createUser, |
3cd0734f | 9 | dateIsValid, |
210feb6c | 10 | flushAndRunServer, |
a1587156 | 11 | getAccessToken, |
3cd0734f C |
12 | ServerInfo, |
13 | setAccessTokensToServers, | |
14 | updateMyAvatar, | |
cf117aaa | 15 | uploadVideo |
94565d52 | 16 | } from '../../../../shared/extra-utils/index' |
c5d31dba | 17 | import { |
3cd0734f C |
18 | addVideoCommentReply, |
19 | addVideoCommentThread, | |
20 | deleteVideoComment, | |
f1273314 | 21 | getAdminVideoComments, |
3cd0734f | 22 | getVideoCommentThreads, |
c5d31dba | 23 | getVideoThreadComments |
94565d52 | 24 | } from '../../../../shared/extra-utils/videos/video-comments' |
d3ea8975 C |
25 | |
26 | const expect = chai.expect | |
27 | ||
e2e22e40 | 28 | describe('Test video comments', function () { |
d3ea8975 C |
29 | let server: ServerInfo |
30 | let videoId | |
31 | let videoUUID | |
32 | let threadId | |
4cb6d457 | 33 | let replyToDeleteId: number |
d3ea8975 | 34 | |
32c68d67 RK |
35 | let userAccessTokenServer1: string |
36 | ||
d3ea8975 | 37 | before(async function () { |
e212f887 | 38 | this.timeout(30000) |
d3ea8975 | 39 | |
210feb6c | 40 | server = await flushAndRunServer(1) |
d3ea8975 C |
41 | |
42 | await setAccessTokensToServers([ server ]) | |
43 | ||
44 | const res = await uploadVideo(server.url, server.accessToken, {}) | |
45 | videoUUID = res.body.video.uuid | |
46 | videoId = res.body.video.id | |
cf117aaa C |
47 | |
48 | await updateMyAvatar({ | |
49 | url: server.url, | |
50 | accessToken: server.accessToken, | |
51 | fixture: 'avatar.png' | |
52 | }) | |
32c68d67 RK |
53 | |
54 | await createUser({ | |
55 | url: server.url, | |
56 | accessToken: server.accessToken, | |
57 | username: 'user1', | |
58 | password: 'password' | |
59 | }) | |
60 | userAccessTokenServer1 = await getAccessToken(server.url, 'user1', 'password') | |
d3ea8975 C |
61 | }) |
62 | ||
f1273314 | 63 | describe('User comments', function () { |
d3ea8975 | 64 | |
f1273314 C |
65 | it('Should not have threads on this video', async function () { |
66 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
d3ea8975 | 67 | |
f1273314 | 68 | expect(res.body.total).to.equal(0) |
9d6b9d10 | 69 | expect(res.body.totalNotDeletedComments).to.equal(0) |
f1273314 C |
70 | expect(res.body.data).to.be.an('array') |
71 | expect(res.body.data).to.have.lengthOf(0) | |
72 | }) | |
d3ea8975 | 73 | |
f1273314 C |
74 | it('Should create a thread in this video', async function () { |
75 | const text = 'my super first comment' | |
76 | ||
77 | const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) | |
78 | const comment = res.body.comment | |
79 | ||
80 | expect(comment.inReplyToCommentId).to.be.null | |
81 | expect(comment.text).equal('my super first comment') | |
82 | expect(comment.videoId).to.equal(videoId) | |
83 | expect(comment.id).to.equal(comment.threadId) | |
84 | expect(comment.account.name).to.equal('root') | |
85 | expect(comment.account.host).to.equal('localhost:' + server.port) | |
86 | expect(comment.account.url).to.equal('http://localhost:' + server.port + '/accounts/root') | |
87 | expect(comment.totalReplies).to.equal(0) | |
88 | expect(comment.totalRepliesFromVideoAuthor).to.equal(0) | |
89 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
90 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
91 | }) | |
d3ea8975 | 92 | |
f1273314 C |
93 | it('Should list threads of this video', async function () { |
94 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
d3ea8975 | 95 | |
f1273314 | 96 | expect(res.body.total).to.equal(1) |
9d6b9d10 | 97 | expect(res.body.totalNotDeletedComments).to.equal(1) |
f1273314 C |
98 | expect(res.body.data).to.be.an('array') |
99 | expect(res.body.data).to.have.lengthOf(1) | |
cf117aaa | 100 | |
f1273314 C |
101 | const comment: VideoComment = res.body.data[0] |
102 | expect(comment.inReplyToCommentId).to.be.null | |
103 | expect(comment.text).equal('my super first comment') | |
104 | expect(comment.videoId).to.equal(videoId) | |
105 | expect(comment.id).to.equal(comment.threadId) | |
106 | expect(comment.account.name).to.equal('root') | |
107 | expect(comment.account.host).to.equal('localhost:' + server.port) | |
cf117aaa | 108 | |
f1273314 | 109 | await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') |
d3ea8975 | 110 | |
f1273314 C |
111 | expect(comment.totalReplies).to.equal(0) |
112 | expect(comment.totalRepliesFromVideoAuthor).to.equal(0) | |
113 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
114 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
d3ea8975 | 115 | |
f1273314 C |
116 | threadId = comment.threadId |
117 | }) | |
d3ea8975 | 118 | |
f1273314 C |
119 | it('Should get all the thread created', async function () { |
120 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | |
d3ea8975 | 121 | |
f1273314 C |
122 | const rootComment = res.body.comment |
123 | expect(rootComment.inReplyToCommentId).to.be.null | |
124 | expect(rootComment.text).equal('my super first comment') | |
125 | expect(rootComment.videoId).to.equal(videoId) | |
126 | expect(dateIsValid(rootComment.createdAt as string)).to.be.true | |
127 | expect(dateIsValid(rootComment.updatedAt as string)).to.be.true | |
128 | }) | |
d3ea8975 | 129 | |
f1273314 C |
130 | it('Should create multiple replies in this thread', async function () { |
131 | const text1 = 'my super answer to thread 1' | |
132 | const childCommentRes = await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text1) | |
133 | const childCommentId = childCommentRes.body.comment.id | |
d3ea8975 | 134 | |
f1273314 C |
135 | const text2 = 'my super answer to answer of thread 1' |
136 | await addVideoCommentReply(server.url, server.accessToken, videoId, childCommentId, text2) | |
d3ea8975 | 137 | |
f1273314 C |
138 | const text3 = 'my second answer to thread 1' |
139 | await addVideoCommentReply(server.url, server.accessToken, videoId, threadId, text3) | |
140 | }) | |
d3ea8975 | 141 | |
f1273314 C |
142 | it('Should get correctly the replies', async function () { |
143 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | |
d3ea8975 | 144 | |
f1273314 C |
145 | const tree: VideoCommentThreadTree = res.body |
146 | expect(tree.comment.text).equal('my super first comment') | |
147 | expect(tree.children).to.have.lengthOf(2) | |
d3ea8975 | 148 | |
f1273314 C |
149 | const firstChild = tree.children[0] |
150 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
151 | expect(firstChild.children).to.have.lengthOf(1) | |
d3ea8975 | 152 | |
f1273314 C |
153 | const childOfFirstChild = firstChild.children[0] |
154 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
155 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
d3ea8975 | 156 | |
f1273314 C |
157 | const secondChild = tree.children[1] |
158 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
159 | expect(secondChild.children).to.have.lengthOf(0) | |
4cb6d457 | 160 | |
f1273314 C |
161 | replyToDeleteId = secondChild.comment.id |
162 | }) | |
d3ea8975 | 163 | |
f1273314 C |
164 | it('Should create other threads', async function () { |
165 | const text1 = 'super thread 2' | |
166 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text1) | |
d3ea8975 | 167 | |
f1273314 C |
168 | const text2 = 'super thread 3' |
169 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text2) | |
170 | }) | |
d3ea8975 | 171 | |
f1273314 C |
172 | it('Should list the threads', async function () { |
173 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') | |
d3ea8975 | 174 | |
f1273314 | 175 | expect(res.body.total).to.equal(3) |
9d6b9d10 | 176 | expect(res.body.totalNotDeletedComments).to.equal(6) |
f1273314 C |
177 | expect(res.body.data).to.be.an('array') |
178 | expect(res.body.data).to.have.lengthOf(3) | |
d3ea8975 | 179 | |
f1273314 C |
180 | expect(res.body.data[0].text).to.equal('my super first comment') |
181 | expect(res.body.data[0].totalReplies).to.equal(3) | |
182 | expect(res.body.data[1].text).to.equal('super thread 2') | |
183 | expect(res.body.data[1].totalReplies).to.equal(0) | |
184 | expect(res.body.data[2].text).to.equal('super thread 3') | |
185 | expect(res.body.data[2].totalReplies).to.equal(0) | |
186 | }) | |
d3ea8975 | 187 | |
f1273314 C |
188 | it('Should delete a reply', async function () { |
189 | await deleteVideoComment(server.url, server.accessToken, videoId, replyToDeleteId) | |
4cb6d457 | 190 | |
9d6b9d10 C |
191 | { |
192 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') | |
4cb6d457 | 193 | |
9d6b9d10 C |
194 | expect(res.body.total).to.equal(3) |
195 | expect(res.body.totalNotDeletedComments).to.equal(5) | |
196 | } | |
4cb6d457 | 197 | |
9d6b9d10 C |
198 | { |
199 | const res = await getVideoThreadComments(server.url, videoUUID, threadId) | |
4cb6d457 | 200 | |
9d6b9d10 C |
201 | const tree: VideoCommentThreadTree = res.body |
202 | expect(tree.comment.text).equal('my super first comment') | |
203 | expect(tree.children).to.have.lengthOf(2) | |
204 | ||
205 | const firstChild = tree.children[0] | |
206 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
207 | expect(firstChild.children).to.have.lengthOf(1) | |
208 | ||
209 | const childOfFirstChild = firstChild.children[0] | |
210 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
211 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
69222afa | 212 | |
9d6b9d10 C |
213 | const deletedChildOfFirstChild = tree.children[1] |
214 | expect(deletedChildOfFirstChild.comment.text).to.equal('') | |
215 | expect(deletedChildOfFirstChild.comment.isDeleted).to.be.true | |
216 | expect(deletedChildOfFirstChild.comment.deletedAt).to.not.be.null | |
217 | expect(deletedChildOfFirstChild.comment.account).to.be.null | |
218 | expect(deletedChildOfFirstChild.children).to.have.lengthOf(0) | |
219 | } | |
f1273314 | 220 | }) |
4cb6d457 | 221 | |
f1273314 C |
222 | it('Should delete a complete thread', async function () { |
223 | await deleteVideoComment(server.url, server.accessToken, videoId, threadId) | |
224 | ||
225 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5, 'createdAt') | |
226 | expect(res.body.total).to.equal(3) | |
227 | expect(res.body.data).to.be.an('array') | |
228 | expect(res.body.data).to.have.lengthOf(3) | |
229 | ||
230 | expect(res.body.data[0].text).to.equal('') | |
231 | expect(res.body.data[0].isDeleted).to.be.true | |
232 | expect(res.body.data[0].deletedAt).to.not.be.null | |
233 | expect(res.body.data[0].account).to.be.null | |
234 | expect(res.body.data[0].totalReplies).to.equal(3) | |
235 | expect(res.body.data[1].text).to.equal('super thread 2') | |
236 | expect(res.body.data[1].totalReplies).to.equal(0) | |
237 | expect(res.body.data[2].text).to.equal('super thread 3') | |
238 | expect(res.body.data[2].totalReplies).to.equal(0) | |
239 | }) | |
4cb6d457 | 240 | |
f1273314 C |
241 | it('Should count replies from the video author correctly', async function () { |
242 | const text = 'my super first comment' | |
243 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text) | |
244 | let res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
245 | const comment: VideoComment = res.body.data[0] | |
246 | const threadId2 = comment.threadId | |
247 | ||
248 | const text2 = 'a first answer to thread 4 by a third party' | |
249 | await addVideoCommentReply(server.url, userAccessTokenServer1, videoId, threadId2, text2) | |
250 | ||
251 | const text3 = 'my second answer to thread 4' | |
252 | await addVideoCommentReply(server.url, server.accessToken, videoId, threadId2, text3) | |
253 | ||
254 | res = await getVideoThreadComments(server.url, videoUUID, threadId2) | |
255 | const tree: VideoCommentThreadTree = res.body | |
256 | expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1) | |
257 | }) | |
4cb6d457 C |
258 | }) |
259 | ||
f1273314 C |
260 | 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 | ||
272 | it('Should list instance comments as admin', async function () { | |
273 | const { comments } = await getComments({ start: 0, count: 1 }) | |
274 | ||
275 | expect(comments[0].text).to.equal('my second answer to thread 4') | |
276 | }) | |
277 | ||
278 | it('Should filter instance comments by isLocal', async function () { | |
279 | const { total, comments } = await getComments({ isLocal: false }) | |
32c68d67 | 280 | |
f1273314 C |
281 | expect(comments).to.have.lengthOf(0) |
282 | expect(total).to.equal(0) | |
283 | }) | |
284 | ||
285 | it('Should search instance comments by account', async function () { | |
286 | const { total, comments } = await getComments({ searchAccount: 'user' }) | |
287 | ||
288 | expect(comments).to.have.lengthOf(1) | |
289 | expect(total).to.equal(1) | |
290 | ||
291 | expect(comments[0].text).to.equal('a first answer to thread 4 by a third party') | |
292 | }) | |
32c68d67 | 293 | |
f1273314 C |
294 | it('Should search instance comments by video', async function () { |
295 | { | |
296 | const { total, comments } = await getComments({ searchVideo: 'video' }) | |
32c68d67 | 297 | |
f1273314 C |
298 | expect(comments).to.have.lengthOf(7) |
299 | expect(total).to.equal(7) | |
300 | } | |
32c68d67 | 301 | |
f1273314 C |
302 | { |
303 | const { total, comments } = await getComments({ searchVideo: 'hello' }) | |
304 | ||
305 | expect(comments).to.have.lengthOf(0) | |
306 | expect(total).to.equal(0) | |
307 | } | |
308 | }) | |
309 | ||
310 | it('Should search instance comments', async function () { | |
311 | const { total, comments } = await getComments({ search: 'super thread 3' }) | |
312 | ||
313 | expect(comments).to.have.lengthOf(1) | |
314 | expect(total).to.equal(1) | |
315 | expect(comments[0].text).to.equal('super thread 3') | |
316 | }) | |
32c68d67 RK |
317 | }) |
318 | ||
7c3b7976 C |
319 | after(async function () { |
320 | await cleanupTests([ server ]) | |
d3ea8975 C |
321 | }) |
322 | }) |