1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
15 const expect = chai.expect
17 describe('Test bulk actions', function () {
18 const commentsUser3: { videoId: number, commentId: number }[] = []
20 let servers: PeerTubeServer[] = []
21 let user1Token: string
22 let user2Token: string
23 let user3Token: string
25 let bulkCommand: BulkCommand
27 before(async function () {
30 servers = await createMultipleServers(2)
32 // Get the access tokens
33 await setAccessTokensToServers(servers)
36 const user = { username: 'user1', password: 'password' }
37 await servers[0].users.create({ username: user.username, password: user.password })
39 user1Token = await servers[0].login.getAccessToken(user)
43 const user = { username: 'user2', password: 'password' }
44 await servers[0].users.create({ username: user.username, password: user.password })
46 user2Token = await servers[0].login.getAccessToken(user)
50 const user = { username: 'user3', password: 'password' }
51 await servers[1].users.create({ username: user.username, password: user.password })
53 user3Token = await servers[1].login.getAccessToken(user)
56 await doubleFollow(servers[0], servers[1])
58 bulkCommand = new BulkCommand(servers[0])
61 describe('Bulk remove comments', function () {
62 async function checkInstanceCommentsRemoved () {
64 const { data } = await servers[0].videos.list()
66 // Server 1 should not have these comments anymore
67 for (const video of data) {
68 const { data } = await servers[0].comments.listThreads({ videoId: video.id })
69 const comment = data.find(c => c.text === 'comment by user 3')
71 expect(comment).to.not.exist
76 const { data } = await servers[1].videos.list()
78 // Server 1 should not have these comments on videos of server 1
79 for (const video of data) {
80 const { data } = await servers[1].comments.listThreads({ videoId: video.id })
81 const comment = data.find(c => c.text === 'comment by user 3')
83 if (video.account.host === 'localhost:' + servers[0].port) {
84 expect(comment).to.not.exist
86 expect(comment).to.exist
92 before(async function () {
95 await servers[0].videos.upload({ attributes: { name: 'video 1 server 1' } })
96 await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
97 await servers[0].videos.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } })
99 await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
101 await waitJobs(servers)
104 const { data } = await servers[0].videos.list()
105 for (const video of data) {
106 await servers[0].comments.createThread({ videoId: video.id, text: 'comment by root server 1' })
107 await servers[0].comments.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
108 await servers[0].comments.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
113 const { data } = await servers[1].videos.list()
115 for (const video of data) {
116 await servers[1].comments.createThread({ videoId: video.id, text: 'comment by root server 2' })
118 const comment = await servers[1].comments.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
119 commentsUser3.push({ videoId: video.id, commentId: comment.id })
123 await waitJobs(servers)
126 it('Should delete comments of an account on my videos', async function () {
129 await bulkCommand.removeCommentsOf({
132 accountName: 'user2',
137 await waitJobs(servers)
139 for (const server of servers) {
140 const { data } = await server.videos.list()
142 for (const video of data) {
143 const { data } = await server.comments.listThreads({ videoId: video.id })
144 const comment = data.find(c => c.text === 'comment by user 2')
146 if (video.name === 'video 3 server 1') expect(comment).to.not.exist
147 else expect(comment).to.exist
152 it('Should delete comments of an account on the instance', async function () {
155 await bulkCommand.removeCommentsOf({
157 accountName: 'user3@localhost:' + servers[1].port,
162 await waitJobs(servers)
164 await checkInstanceCommentsRemoved()
167 it('Should not re create the comment on video update', async function () {
170 for (const obj of commentsUser3) {
171 await servers[1].comments.addReply({
173 videoId: obj.videoId,
174 toCommentId: obj.commentId,
175 text: 'comment by user 3 bis'
179 await waitJobs(servers)
181 await checkInstanceCommentsRemoved()
185 after(async function () {
186 await cleanupTests(servers)