1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoComment } from '@shared/models/videos/video-comment.model'
11 flushAndRunMultipleServers,
12 getVideoCommentThreads,
15 setAccessTokensToServers,
20 } from '../../../../shared/extra-utils/index'
21 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
22 import { Video } from '@shared/models'
24 const expect = chai.expect
26 describe('Test bulk actions', function () {
27 const commentsUser3: { videoId: number, commentId: number }[] = []
29 let servers: ServerInfo[] = []
30 let user1AccessToken: string
31 let user2AccessToken: string
32 let user3AccessToken: string
34 before(async function () {
37 servers = await flushAndRunMultipleServers(2)
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
43 const user = { username: 'user1', password: 'password' }
44 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
46 user1AccessToken = await userLogin(servers[0], user)
50 const user = { username: 'user2', password: 'password' }
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
53 user2AccessToken = await userLogin(servers[0], user)
57 const user = { username: 'user3', password: 'password' }
58 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
60 user3AccessToken = await userLogin(servers[1], user)
63 await doubleFollow(servers[0], servers[1])
66 describe('Bulk remove comments', function () {
67 async function checkInstanceCommentsRemoved () {
69 const res = await getVideosList(servers[0].url)
70 const videos = res.body.data as Video[]
72 // Server 1 should not have these comments anymore
73 for (const video of videos) {
74 const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10)
75 const comments = resThreads.body.data as VideoComment[]
76 const comment = comments.find(c => c.text === 'comment by user 3')
78 expect(comment).to.not.exist
83 const res = await getVideosList(servers[1].url)
84 const videos = res.body.data as Video[]
86 // Server 1 should not have these comments on videos of server 1
87 for (const video of videos) {
88 const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10)
89 const comments = resThreads.body.data as VideoComment[]
90 const comment = comments.find(c => c.text === 'comment by user 3')
92 if (video.account.host === 'localhost:' + servers[0].port) {
93 expect(comment).to.not.exist
95 expect(comment).to.exist
101 before(async function () {
104 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
105 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
106 await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' })
108 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
110 await waitJobs(servers)
113 const res = await getVideosList(servers[0].url)
114 for (const video of res.body.data) {
115 await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1')
116 await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1')
117 await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2')
122 const res = await getVideosList(servers[1].url)
123 for (const video of res.body.data) {
124 await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2')
126 const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3')
127 commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id })
131 await waitJobs(servers)
134 it('Should delete comments of an account on my videos', async function () {
137 await bulkRemoveCommentsOf({
139 token: user1AccessToken,
141 accountName: 'user2',
146 await waitJobs(servers)
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
151 for (const video of res.body.data) {
152 const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10)
153 const comments = resThreads.body.data as VideoComment[]
154 const comment = comments.find(c => c.text === 'comment by user 2')
156 if (video.name === 'video 3 server 1') {
157 expect(comment).to.not.exist
159 expect(comment).to.exist
165 it('Should delete comments of an account on the instance', async function () {
168 await bulkRemoveCommentsOf({
170 token: servers[0].accessToken,
172 accountName: 'user3@localhost:' + servers[1].port,
177 await waitJobs(servers)
179 await checkInstanceCommentsRemoved()
182 it('Should not re create the comment on video update', async function () {
185 for (const obj of commentsUser3) {
186 await addVideoCommentReply(servers[1].url, user3AccessToken, obj.videoId, obj.commentId, 'comment by user 3 bis')
189 await waitJobs(servers)
191 await checkInstanceCommentsRemoved()
195 after(async function () {
196 await cleanupTests(servers)