1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { Video } from '@shared/models'
11 flushAndRunMultipleServers,
14 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils/index'
20 const expect = chai.expect
22 describe('Test bulk actions', function () {
23 const commentsUser3: { videoId: number, commentId: number }[] = []
25 let servers: ServerInfo[] = []
26 let user1Token: string
27 let user2Token: string
28 let user3Token: string
30 let bulkCommand: BulkCommand
32 before(async function () {
35 servers = await flushAndRunMultipleServers(2)
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
41 const user = { username: 'user1', password: 'password' }
42 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
44 user1Token = await userLogin(servers[0], user)
48 const user = { username: 'user2', password: 'password' }
49 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
51 user2Token = await userLogin(servers[0], user)
55 const user = { username: 'user3', password: 'password' }
56 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
58 user3Token = await userLogin(servers[1], user)
61 await doubleFollow(servers[0], servers[1])
63 bulkCommand = new BulkCommand(servers[0])
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 { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
75 const comment = data.find(c => c.text === 'comment by user 3')
77 expect(comment).to.not.exist
82 const res = await getVideosList(servers[1].url)
83 const videos = res.body.data as Video[]
85 // Server 1 should not have these comments on videos of server 1
86 for (const video of videos) {
87 const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
88 const comment = data.find(c => c.text === 'comment by user 3')
90 if (video.account.host === 'localhost:' + servers[0].port) {
91 expect(comment).to.not.exist
93 expect(comment).to.exist
99 before(async function () {
102 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
103 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
104 await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' })
106 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
108 await waitJobs(servers)
111 const res = await getVideosList(servers[0].url)
112 for (const video of res.body.data) {
113 await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
114 await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
115 await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
120 const res = await getVideosList(servers[1].url)
122 for (const video of res.body.data) {
123 await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
125 const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
126 commentsUser3.push({ videoId: video.id, commentId: comment.id })
130 await waitJobs(servers)
133 it('Should delete comments of an account on my videos', async function () {
136 await bulkCommand.removeCommentsOf({
139 accountName: 'user2',
144 await waitJobs(servers)
146 for (const server of servers) {
147 const res = await getVideosList(server.url)
149 for (const video of res.body.data) {
150 const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
151 const comment = data.find(c => c.text === 'comment by user 2')
153 if (video.name === 'video 3 server 1') expect(comment).to.not.exist
154 else expect(comment).to.exist
159 it('Should delete comments of an account on the instance', async function () {
162 await bulkCommand.removeCommentsOf({
164 accountName: 'user3@localhost:' + servers[1].port,
169 await waitJobs(servers)
171 await checkInstanceCommentsRemoved()
174 it('Should not re create the comment on video update', async function () {
177 for (const obj of commentsUser3) {
178 await servers[1].commentsCommand.addReply({
180 videoId: obj.videoId,
181 toCommentId: obj.commentId,
182 text: 'comment by user 3 bis'
186 await waitJobs(servers)
188 await checkInstanceCommentsRemoved()
192 after(async function () {
193 await cleanupTests(servers)