]>
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 { Video, VideoComment } from '@shared/models' | |
6 | import { | |
7 | addVideoCommentReply, | |
8 | addVideoCommentThread, | |
9 | BulkCommand, | |
10 | cleanupTests, | |
11 | createUser, | |
12 | doubleFollow, | |
13 | flushAndRunMultipleServers, | |
14 | getVideoCommentThreads, | |
15 | getVideosList, | |
16 | ServerInfo, | |
17 | setAccessTokensToServers, | |
18 | uploadVideo, | |
19 | userLogin, | |
20 | waitJobs | |
21 | } from '../../../../shared/extra-utils/index' | |
22 | ||
23 | const expect = chai.expect | |
24 | ||
25 | describe('Test bulk actions', function () { | |
26 | const commentsUser3: { videoId: number, commentId: number }[] = [] | |
27 | ||
28 | let servers: ServerInfo[] = [] | |
29 | let user1AccessToken: string | |
30 | let user2AccessToken: string | |
31 | let user3AccessToken: string | |
32 | ||
33 | let bulkCommand: BulkCommand | |
34 | ||
35 | before(async function () { | |
36 | this.timeout(30000) | |
37 | ||
38 | servers = await flushAndRunMultipleServers(2) | |
39 | ||
40 | // Get the access tokens | |
41 | await setAccessTokensToServers(servers) | |
42 | ||
43 | { | |
44 | const user = { username: 'user1', password: 'password' } | |
45 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | |
46 | ||
47 | user1AccessToken = await userLogin(servers[0], user) | |
48 | } | |
49 | ||
50 | { | |
51 | const user = { username: 'user2', password: 'password' } | |
52 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | |
53 | ||
54 | user2AccessToken = await userLogin(servers[0], user) | |
55 | } | |
56 | ||
57 | { | |
58 | const user = { username: 'user3', password: 'password' } | |
59 | await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) | |
60 | ||
61 | user3AccessToken = await userLogin(servers[1], user) | |
62 | } | |
63 | ||
64 | await doubleFollow(servers[0], servers[1]) | |
65 | ||
66 | bulkCommand = new BulkCommand(servers[0]) | |
67 | }) | |
68 | ||
69 | describe('Bulk remove comments', function () { | |
70 | async function checkInstanceCommentsRemoved () { | |
71 | { | |
72 | const res = await getVideosList(servers[0].url) | |
73 | const videos = res.body.data as Video[] | |
74 | ||
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') | |
80 | ||
81 | expect(comment).to.not.exist | |
82 | } | |
83 | } | |
84 | ||
85 | { | |
86 | const res = await getVideosList(servers[1].url) | |
87 | const videos = res.body.data as Video[] | |
88 | ||
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') | |
94 | ||
95 | if (video.account.host === 'localhost:' + servers[0].port) { | |
96 | expect(comment).to.not.exist | |
97 | } else { | |
98 | expect(comment).to.exist | |
99 | } | |
100 | } | |
101 | } | |
102 | } | |
103 | ||
104 | before(async function () { | |
105 | this.timeout(120000) | |
106 | ||
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' }) | |
110 | ||
111 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) | |
112 | ||
113 | await waitJobs(servers) | |
114 | ||
115 | { | |
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') | |
121 | } | |
122 | } | |
123 | ||
124 | { | |
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') | |
128 | ||
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 }) | |
131 | } | |
132 | } | |
133 | ||
134 | await waitJobs(servers) | |
135 | }) | |
136 | ||
137 | it('Should delete comments of an account on my videos', async function () { | |
138 | this.timeout(60000) | |
139 | ||
140 | await bulkCommand.removeCommentsOf({ | |
141 | token: user1AccessToken, | |
142 | attributes: { | |
143 | accountName: 'user2', | |
144 | scope: 'my-videos' | |
145 | } | |
146 | }) | |
147 | ||
148 | await waitJobs(servers) | |
149 | ||
150 | for (const server of servers) { | |
151 | const res = await getVideosList(server.url) | |
152 | ||
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') | |
157 | ||
158 | if (video.name === 'video 3 server 1') { | |
159 | expect(comment).to.not.exist | |
160 | } else { | |
161 | expect(comment).to.exist | |
162 | } | |
163 | } | |
164 | } | |
165 | }) | |
166 | ||
167 | it('Should delete comments of an account on the instance', async function () { | |
168 | this.timeout(60000) | |
169 | ||
170 | await bulkCommand.removeCommentsOf({ | |
171 | attributes: { | |
172 | accountName: 'user3@localhost:' + servers[1].port, | |
173 | scope: 'instance' | |
174 | } | |
175 | }) | |
176 | ||
177 | await waitJobs(servers) | |
178 | ||
179 | await checkInstanceCommentsRemoved() | |
180 | }) | |
181 | ||
182 | it('Should not re create the comment on video update', async function () { | |
183 | this.timeout(60000) | |
184 | ||
185 | for (const obj of commentsUser3) { | |
186 | await addVideoCommentReply(servers[1].url, user3AccessToken, obj.videoId, obj.commentId, 'comment by user 3 bis') | |
187 | } | |
188 | ||
189 | await waitJobs(servers) | |
190 | ||
191 | await checkInstanceCommentsRemoved() | |
192 | }) | |
193 | }) | |
194 | ||
195 | after(async function () { | |
196 | await cleanupTests(servers) | |
197 | }) | |
198 | }) |