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