1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test bulk actions', function () {
15 const commentsUser3: { videoId: number, commentId: number }[] = []
17 let servers: PeerTubeServer[] = []
18 let user1Token: string
19 let user2Token: string
20 let user3Token: string
22 let bulkCommand: BulkCommand
24 before(async function () {
27 servers = await createMultipleServers(2)
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
33 const user = { username: 'user1', password: 'password' }
34 await servers[0].users.create({ username: user.username, password: user.password })
36 user1Token = await servers[0].login.getAccessToken(user)
40 const user = { username: 'user2', password: 'password' }
41 await servers[0].users.create({ username: user.username, password: user.password })
43 user2Token = await servers[0].login.getAccessToken(user)
47 const user = { username: 'user3', password: 'password' }
48 await servers[1].users.create({ username: user.username, password: user.password })
50 user3Token = await servers[1].login.getAccessToken(user)
53 await doubleFollow(servers[0], servers[1])
55 bulkCommand = new BulkCommand(servers[0])
58 describe('Bulk remove comments', function () {
59 async function checkInstanceCommentsRemoved () {
61 const { data } = await servers[0].videos.list()
63 // Server 1 should not have these comments anymore
64 for (const video of data) {
65 const { data } = await servers[0].comments.listThreads({ videoId: video.id })
66 const comment = data.find(c => c.text === 'comment by user 3')
68 expect(comment).to.not.exist
73 const { data } = await servers[1].videos.list()
75 // Server 1 should not have these comments on videos of server 1
76 for (const video of data) {
77 const { data } = await servers[1].comments.listThreads({ videoId: video.id })
78 const comment = data.find(c => c.text === 'comment by user 3')
80 if (video.account.host === servers[0].host) {
81 expect(comment).to.not.exist
83 expect(comment).to.exist
89 before(async function () {
92 await servers[0].videos.upload({ attributes: { name: 'video 1 server 1' } })
93 await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } })
94 await servers[0].videos.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } })
96 await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } })
98 await waitJobs(servers)
101 const { data } = await servers[0].videos.list()
102 for (const video of data) {
103 await servers[0].comments.createThread({ videoId: video.id, text: 'comment by root server 1' })
104 await servers[0].comments.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
105 await servers[0].comments.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
110 const { data } = await servers[1].videos.list()
112 for (const video of data) {
113 await servers[1].comments.createThread({ videoId: video.id, text: 'comment by root server 2' })
115 const comment = await servers[1].comments.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
116 commentsUser3.push({ videoId: video.id, commentId: comment.id })
120 await waitJobs(servers)
123 it('Should delete comments of an account on my videos', async function () {
126 await bulkCommand.removeCommentsOf({
129 accountName: 'user2',
134 await waitJobs(servers)
136 for (const server of servers) {
137 const { data } = await server.videos.list()
139 for (const video of data) {
140 const { data } = await server.comments.listThreads({ videoId: video.id })
141 const comment = data.find(c => c.text === 'comment by user 2')
143 if (video.name === 'video 3 server 1') expect(comment).to.not.exist
144 else expect(comment).to.exist
149 it('Should delete comments of an account on the instance', async function () {
152 await bulkCommand.removeCommentsOf({
154 accountName: 'user3@' + servers[1].host,
159 await waitJobs(servers)
161 await checkInstanceCommentsRemoved()
164 it('Should not re create the comment on video update', async function () {
167 for (const obj of commentsUser3) {
168 await servers[1].comments.addReply({
170 videoId: obj.videoId,
171 toCommentId: obj.commentId,
172 text: 'comment by user 3 bis'
176 await waitJobs(servers)
178 await checkInstanceCommentsRemoved()
182 after(async function () {
183 await cleanupTests(servers)