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