1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
12 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { Video } from '@shared/models'
18 const expect = chai.expect
20 describe('Test bulk actions', function () {
21 const commentsUser3: { videoId: number, commentId: number }[] = []
23 let servers: ServerInfo[] = []
24 let user1Token: string
25 let user2Token: string
26 let user3Token: string
28 let bulkCommand: BulkCommand
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
39 const user = { username: 'user1', password: 'password' }
40 await servers[0].usersCommand.create({ username: user.username, password: user.password })
42 user1Token = await servers[0].loginCommand.getAccessToken(user)
46 const user = { username: 'user2', password: 'password' }
47 await servers[0].usersCommand.create({ username: user.username, password: user.password })
49 user2Token = await servers[0].loginCommand.getAccessToken(user)
53 const user = { username: 'user3', password: 'password' }
54 await servers[1].usersCommand.create({ username: user.username, password: user.password })
56 user3Token = await servers[1].loginCommand.getAccessToken(user)
59 await doubleFollow(servers[0], servers[1])
61 bulkCommand = new BulkCommand(servers[0])
64 describe('Bulk remove comments', function () {
65 async function checkInstanceCommentsRemoved () {
67 const res = await getVideosList(servers[0].url)
68 const videos = res.body.data as Video[]
70 // Server 1 should not have these comments anymore
71 for (const video of videos) {
72 const { data } = await servers[0].commentsCommand.listThreads({ videoId: video.id })
73 const comment = data.find(c => c.text === 'comment by user 3')
75 expect(comment).to.not.exist
80 const res = await getVideosList(servers[1].url)
81 const videos = res.body.data as Video[]
83 // Server 1 should not have these comments on videos of server 1
84 for (const video of videos) {
85 const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.id })
86 const comment = data.find(c => c.text === 'comment by user 3')
88 if (video.account.host === 'localhost:' + servers[0].port) {
89 expect(comment).to.not.exist
91 expect(comment).to.exist
97 before(async function () {
100 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
101 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
102 await uploadVideo(servers[0].url, user1Token, { name: 'video 3 server 1' })
104 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
106 await waitJobs(servers)
109 const res = await getVideosList(servers[0].url)
110 for (const video of res.body.data) {
111 await servers[0].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 1' })
112 await servers[0].commentsCommand.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' })
113 await servers[0].commentsCommand.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' })
118 const res = await getVideosList(servers[1].url)
120 for (const video of res.body.data) {
121 await servers[1].commentsCommand.createThread({ videoId: video.id, text: 'comment by root server 2' })
123 const comment = await servers[1].commentsCommand.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' })
124 commentsUser3.push({ videoId: video.id, commentId: comment.id })
128 await waitJobs(servers)
131 it('Should delete comments of an account on my videos', async function () {
134 await bulkCommand.removeCommentsOf({
137 accountName: 'user2',
142 await waitJobs(servers)
144 for (const server of servers) {
145 const res = await getVideosList(server.url)
147 for (const video of res.body.data) {
148 const { data } = await server.commentsCommand.listThreads({ videoId: video.id })
149 const comment = data.find(c => c.text === 'comment by user 2')
151 if (video.name === 'video 3 server 1') expect(comment).to.not.exist
152 else expect(comment).to.exist
157 it('Should delete comments of an account on the instance', async function () {
160 await bulkCommand.removeCommentsOf({
162 accountName: 'user3@localhost:' + servers[1].port,
167 await waitJobs(servers)
169 await checkInstanceCommentsRemoved()
172 it('Should not re create the comment on video update', async function () {
175 for (const obj of commentsUser3) {
176 await servers[1].commentsCommand.addReply({
178 videoId: obj.videoId,
179 toCommentId: obj.commentId,
180 text: 'comment by user 3 bis'
184 await waitJobs(servers)
186 await checkInstanceCommentsRemoved()
190 after(async function () {
191 await cleanupTests(servers)