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