]>
Commit | Line | Data |
---|---|---|
444c0a0e C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
444c0a0e | 3 | import * as chai from 'chai' |
444c0a0e | 4 | import { |
a6a79eae | 5 | BulkCommand, |
444c0a0e | 6 | cleanupTests, |
254d3579 | 7 | createMultipleServers, |
4c7e60bc | 8 | doubleFollow, |
254d3579 | 9 | PeerTubeServer, |
444c0a0e | 10 | setAccessTokensToServers, |
2b02c520 | 11 | waitJobs |
bf54587a | 12 | } from '@shared/server-commands' |
444c0a0e C |
13 | |
14 | const expect = chai.expect | |
15 | ||
16 | describe('Test bulk actions', function () { | |
17 | const commentsUser3: { videoId: number, commentId: number }[] = [] | |
18 | ||
254d3579 | 19 | let servers: PeerTubeServer[] = [] |
12edc149 C |
20 | let user1Token: string |
21 | let user2Token: string | |
22 | let user3Token: string | |
444c0a0e | 23 | |
a6a79eae C |
24 | let bulkCommand: BulkCommand |
25 | ||
444c0a0e C |
26 | before(async function () { |
27 | this.timeout(30000) | |
28 | ||
254d3579 | 29 | servers = await createMultipleServers(2) |
444c0a0e C |
30 | |
31 | // Get the access tokens | |
32 | await setAccessTokensToServers(servers) | |
33 | ||
34 | { | |
35 | const user = { username: 'user1', password: 'password' } | |
89d241a7 | 36 | await servers[0].users.create({ username: user.username, password: user.password }) |
444c0a0e | 37 | |
89d241a7 | 38 | user1Token = await servers[0].login.getAccessToken(user) |
444c0a0e C |
39 | } |
40 | ||
41 | { | |
42 | const user = { username: 'user2', password: 'password' } | |
89d241a7 | 43 | await servers[0].users.create({ username: user.username, password: user.password }) |
444c0a0e | 44 | |
89d241a7 | 45 | user2Token = await servers[0].login.getAccessToken(user) |
444c0a0e C |
46 | } |
47 | ||
48 | { | |
49 | const user = { username: 'user3', password: 'password' } | |
89d241a7 | 50 | await servers[1].users.create({ username: user.username, password: user.password }) |
444c0a0e | 51 | |
89d241a7 | 52 | user3Token = await servers[1].login.getAccessToken(user) |
444c0a0e C |
53 | } |
54 | ||
55 | await doubleFollow(servers[0], servers[1]) | |
a6a79eae C |
56 | |
57 | bulkCommand = new BulkCommand(servers[0]) | |
444c0a0e C |
58 | }) |
59 | ||
60 | describe('Bulk remove comments', function () { | |
61 | async function checkInstanceCommentsRemoved () { | |
62 | { | |
89d241a7 | 63 | const { data } = await servers[0].videos.list() |
444c0a0e C |
64 | |
65 | // Server 1 should not have these comments anymore | |
d23dd9fb | 66 | for (const video of data) { |
89d241a7 | 67 | const { data } = await servers[0].comments.listThreads({ videoId: video.id }) |
12edc149 | 68 | const comment = data.find(c => c.text === 'comment by user 3') |
444c0a0e C |
69 | |
70 | expect(comment).to.not.exist | |
71 | } | |
72 | } | |
73 | ||
74 | { | |
89d241a7 | 75 | const { data } = await servers[1].videos.list() |
444c0a0e C |
76 | |
77 | // Server 1 should not have these comments on videos of server 1 | |
d23dd9fb | 78 | for (const video of data) { |
89d241a7 | 79 | const { data } = await servers[1].comments.listThreads({ videoId: video.id }) |
12edc149 | 80 | const comment = data.find(c => c.text === 'comment by user 3') |
444c0a0e C |
81 | |
82 | if (video.account.host === 'localhost:' + servers[0].port) { | |
83 | expect(comment).to.not.exist | |
84 | } else { | |
85 | expect(comment).to.exist | |
86 | } | |
87 | } | |
88 | } | |
89 | } | |
90 | ||
91 | before(async function () { | |
0c39df25 | 92 | this.timeout(120000) |
444c0a0e | 93 | |
89d241a7 C |
94 | await servers[0].videos.upload({ attributes: { name: 'video 1 server 1' } }) |
95 | await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) | |
96 | await servers[0].videos.upload({ token: user1Token, attributes: { name: 'video 3 server 1' } }) | |
444c0a0e | 97 | |
89d241a7 | 98 | await servers[1].videos.upload({ attributes: { name: 'video 1 server 2' } }) |
444c0a0e C |
99 | |
100 | await waitJobs(servers) | |
101 | ||
102 | { | |
89d241a7 | 103 | const { data } = await servers[0].videos.list() |
d23dd9fb | 104 | for (const video of data) { |
89d241a7 C |
105 | await servers[0].comments.createThread({ videoId: video.id, text: 'comment by root server 1' }) |
106 | await servers[0].comments.createThread({ token: user1Token, videoId: video.id, text: 'comment by user 1' }) | |
107 | await servers[0].comments.createThread({ token: user2Token, videoId: video.id, text: 'comment by user 2' }) | |
444c0a0e C |
108 | } |
109 | } | |
110 | ||
111 | { | |
89d241a7 | 112 | const { data } = await servers[1].videos.list() |
12edc149 | 113 | |
d23dd9fb | 114 | for (const video of data) { |
89d241a7 | 115 | await servers[1].comments.createThread({ videoId: video.id, text: 'comment by root server 2' }) |
444c0a0e | 116 | |
89d241a7 | 117 | const comment = await servers[1].comments.createThread({ token: user3Token, videoId: video.id, text: 'comment by user 3' }) |
12edc149 | 118 | commentsUser3.push({ videoId: video.id, commentId: comment.id }) |
444c0a0e C |
119 | } |
120 | } | |
121 | ||
122 | await waitJobs(servers) | |
123 | }) | |
124 | ||
125 | it('Should delete comments of an account on my videos', async function () { | |
126 | this.timeout(60000) | |
127 | ||
a6a79eae | 128 | await bulkCommand.removeCommentsOf({ |
12edc149 | 129 | token: user1Token, |
444c0a0e C |
130 | attributes: { |
131 | accountName: 'user2', | |
132 | scope: 'my-videos' | |
133 | } | |
134 | }) | |
135 | ||
136 | await waitJobs(servers) | |
137 | ||
138 | for (const server of servers) { | |
89d241a7 | 139 | const { data } = await server.videos.list() |
444c0a0e | 140 | |
d23dd9fb | 141 | for (const video of data) { |
89d241a7 | 142 | const { data } = await server.comments.listThreads({ videoId: video.id }) |
12edc149 | 143 | const comment = data.find(c => c.text === 'comment by user 2') |
444c0a0e | 144 | |
12edc149 C |
145 | if (video.name === 'video 3 server 1') expect(comment).to.not.exist |
146 | else expect(comment).to.exist | |
444c0a0e C |
147 | } |
148 | } | |
149 | }) | |
150 | ||
151 | it('Should delete comments of an account on the instance', async function () { | |
152 | this.timeout(60000) | |
153 | ||
a6a79eae | 154 | await bulkCommand.removeCommentsOf({ |
444c0a0e C |
155 | attributes: { |
156 | accountName: 'user3@localhost:' + servers[1].port, | |
157 | scope: 'instance' | |
158 | } | |
159 | }) | |
160 | ||
161 | await waitJobs(servers) | |
162 | ||
163 | await checkInstanceCommentsRemoved() | |
164 | }) | |
165 | ||
166 | it('Should not re create the comment on video update', async function () { | |
167 | this.timeout(60000) | |
168 | ||
169 | for (const obj of commentsUser3) { | |
89d241a7 | 170 | await servers[1].comments.addReply({ |
12edc149 C |
171 | token: user3Token, |
172 | videoId: obj.videoId, | |
173 | toCommentId: obj.commentId, | |
174 | text: 'comment by user 3 bis' | |
175 | }) | |
444c0a0e C |
176 | } |
177 | ||
178 | await waitJobs(servers) | |
179 | ||
180 | await checkInstanceCommentsRemoved() | |
181 | }) | |
182 | }) | |
183 | ||
184 | after(async function () { | |
185 | await cleanupTests(servers) | |
186 | }) | |
187 | }) |