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