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