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