1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { Video, VideoComment } from '@shared/models'
13 flushAndRunMultipleServers,
14 getVideoCommentThreads,
17 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils/index'
23 const expect = chai.expect
25 describe('Test bulk actions', function () {
26 const commentsUser3: { videoId: number, commentId: number }[] = []
28 let servers: ServerInfo[] = []
29 let user1AccessToken: string
30 let user2AccessToken: string
31 let user3AccessToken: string
33 let bulkCommand: BulkCommand
35 before(async function () {
38 servers = await flushAndRunMultipleServers(2)
40 // Get the access tokens
41 await setAccessTokensToServers(servers)
44 const user = { username: 'user1', password: 'password' }
45 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
47 user1AccessToken = await userLogin(servers[0], user)
51 const user = { username: 'user2', password: 'password' }
52 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
54 user2AccessToken = await userLogin(servers[0], user)
58 const user = { username: 'user3', password: 'password' }
59 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
61 user3AccessToken = await userLogin(servers[1], user)
64 await doubleFollow(servers[0], servers[1])
66 bulkCommand = new BulkCommand(servers[0])
69 describe('Bulk remove comments', function () {
70 async function checkInstanceCommentsRemoved () {
72 const res = await getVideosList(servers[0].url)
73 const videos = res.body.data as Video[]
75 // Server 1 should not have these comments anymore
76 for (const video of videos) {
77 const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10)
78 const comments = resThreads.body.data as VideoComment[]
79 const comment = comments.find(c => c.text === 'comment by user 3')
81 expect(comment).to.not.exist
86 const res = await getVideosList(servers[1].url)
87 const videos = res.body.data as Video[]
89 // Server 1 should not have these comments on videos of server 1
90 for (const video of videos) {
91 const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10)
92 const comments = resThreads.body.data as VideoComment[]
93 const comment = comments.find(c => c.text === 'comment by user 3')
95 if (video.account.host === 'localhost:' + servers[0].port) {
96 expect(comment).to.not.exist
98 expect(comment).to.exist
104 before(async function () {
107 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' })
108 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' })
109 await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' })
111 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' })
113 await waitJobs(servers)
116 const res = await getVideosList(servers[0].url)
117 for (const video of res.body.data) {
118 await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1')
119 await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1')
120 await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2')
125 const res = await getVideosList(servers[1].url)
126 for (const video of res.body.data) {
127 await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2')
129 const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3')
130 commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id })
134 await waitJobs(servers)
137 it('Should delete comments of an account on my videos', async function () {
140 await bulkCommand.removeCommentsOf({
141 token: user1AccessToken,
143 accountName: 'user2',
148 await waitJobs(servers)
150 for (const server of servers) {
151 const res = await getVideosList(server.url)
153 for (const video of res.body.data) {
154 const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10)
155 const comments = resThreads.body.data as VideoComment[]
156 const comment = comments.find(c => c.text === 'comment by user 2')
158 if (video.name === 'video 3 server 1') {
159 expect(comment).to.not.exist
161 expect(comment).to.exist
167 it('Should delete comments of an account on the instance', async function () {
170 await bulkCommand.removeCommentsOf({
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)