diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-14 16:56:15 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-05-29 09:21:26 +0200 |
commit | 444c0a0e017824fb4ce526281a22c4abe0a13c50 (patch) | |
tree | 6a3c1ea8c4995361c582176257d1e1315287411d /server/tests/api | |
parent | 99139e7753e20ab0fba8eae5638d3dd3e792fe43 (diff) | |
download | PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.gz PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.tar.zst PeerTube-444c0a0e017824fb4ce526281a22c4abe0a13c50.zip |
Add ability to bulk delete comments
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params/bulk.ts | 88 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/bulk.ts | 198 |
3 files changed, 287 insertions, 0 deletions
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts new file mode 100644 index 000000000..432858b33 --- /dev/null +++ b/server/tests/api/check-params/bulk.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { | ||
5 | cleanupTests, | ||
6 | createUser, | ||
7 | flushAndRunServer, | ||
8 | ServerInfo, | ||
9 | setAccessTokensToServers, | ||
10 | userLogin | ||
11 | } from '../../../../shared/extra-utils' | ||
12 | import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' | ||
13 | |||
14 | describe('Test bulk API validators', function () { | ||
15 | let server: ServerInfo | ||
16 | let userAccessToken: string | ||
17 | |||
18 | // --------------------------------------------------------------- | ||
19 | |||
20 | before(async function () { | ||
21 | this.timeout(120000) | ||
22 | |||
23 | server = await flushAndRunServer(1) | ||
24 | await setAccessTokensToServers([ server ]) | ||
25 | |||
26 | const user = { username: 'user1', password: 'password' } | ||
27 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | ||
28 | |||
29 | userAccessToken = await userLogin(server, user) | ||
30 | }) | ||
31 | |||
32 | describe('When removing comments of', function () { | ||
33 | const path = '/api/v1/bulk/remove-comments-of' | ||
34 | |||
35 | it('Should fail with an unauthenticated user', async function () { | ||
36 | await makePostBodyRequest({ | ||
37 | url: server.url, | ||
38 | path, | ||
39 | fields: { accountName: 'user1', scope: 'my-videos' }, | ||
40 | statusCodeExpected: 401 | ||
41 | }) | ||
42 | }) | ||
43 | |||
44 | it('Should fail with an unknown account', async function () { | ||
45 | await makePostBodyRequest({ | ||
46 | url: server.url, | ||
47 | token: server.accessToken, | ||
48 | path, | ||
49 | fields: { accountName: 'user2', scope: 'my-videos' }, | ||
50 | statusCodeExpected: 404 | ||
51 | }) | ||
52 | }) | ||
53 | |||
54 | it('Should fail with an invalid scope', async function () { | ||
55 | await makePostBodyRequest({ | ||
56 | url: server.url, | ||
57 | token: server.accessToken, | ||
58 | path, | ||
59 | fields: { accountName: 'user1', scope: 'my-videoss' }, | ||
60 | statusCodeExpected: 400 | ||
61 | }) | ||
62 | }) | ||
63 | |||
64 | it('Should fail to delete comments of the instance without the appropriate rights', async function () { | ||
65 | await makePostBodyRequest({ | ||
66 | url: server.url, | ||
67 | token: userAccessToken, | ||
68 | path, | ||
69 | fields: { accountName: 'user1', scope: 'instance' }, | ||
70 | statusCodeExpected: 403 | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | it('Should succeed with the correct params', async function () { | ||
75 | await makePostBodyRequest({ | ||
76 | url: server.url, | ||
77 | token: server.accessToken, | ||
78 | path, | ||
79 | fields: { accountName: 'user1', scope: 'instance' }, | ||
80 | statusCodeExpected: 204 | ||
81 | }) | ||
82 | }) | ||
83 | }) | ||
84 | |||
85 | after(async function () { | ||
86 | await cleanupTests([ server ]) | ||
87 | }) | ||
88 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index ef152f55c..93ffd98b1 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import './accounts' | 1 | import './accounts' |
2 | import './blocklist' | 2 | import './blocklist' |
3 | import './bulk' | ||
3 | import './config' | 4 | import './config' |
4 | import './contact-form' | 5 | import './contact-form' |
5 | import './debug' | 6 | import './debug' |
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts new file mode 100644 index 000000000..63321d4bb --- /dev/null +++ b/server/tests/api/server/bulk.ts | |||
@@ -0,0 +1,198 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { VideoComment } from '@shared/models/videos/video-comment.model' | ||
6 | import { | ||
7 | addVideoCommentThread, | ||
8 | bulkRemoveCommentsOf, | ||
9 | cleanupTests, | ||
10 | createUser, | ||
11 | flushAndRunMultipleServers, | ||
12 | getVideoCommentThreads, | ||
13 | getVideosList, | ||
14 | ServerInfo, | ||
15 | setAccessTokensToServers, | ||
16 | uploadVideo, | ||
17 | userLogin, | ||
18 | waitJobs, | ||
19 | addVideoCommentReply | ||
20 | } from '../../../../shared/extra-utils/index' | ||
21 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | ||
22 | import { Video } from '@shared/models' | ||
23 | |||
24 | const expect = chai.expect | ||
25 | |||
26 | describe('Test bulk actions', function () { | ||
27 | const commentsUser3: { videoId: number, commentId: number }[] = [] | ||
28 | |||
29 | let servers: ServerInfo[] = [] | ||
30 | let user1AccessToken: string | ||
31 | let user2AccessToken: string | ||
32 | let user3AccessToken: string | ||
33 | |||
34 | before(async function () { | ||
35 | this.timeout(30000) | ||
36 | |||
37 | servers = await flushAndRunMultipleServers(2) | ||
38 | |||
39 | // Get the access tokens | ||
40 | await setAccessTokensToServers(servers) | ||
41 | |||
42 | { | ||
43 | const user = { username: 'user1', password: 'password' } | ||
44 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | ||
45 | |||
46 | user1AccessToken = await userLogin(servers[0], user) | ||
47 | } | ||
48 | |||
49 | { | ||
50 | const user = { username: 'user2', password: 'password' } | ||
51 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) | ||
52 | |||
53 | user2AccessToken = await userLogin(servers[0], user) | ||
54 | } | ||
55 | |||
56 | { | ||
57 | const user = { username: 'user3', password: 'password' } | ||
58 | await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) | ||
59 | |||
60 | user3AccessToken = await userLogin(servers[1], user) | ||
61 | } | ||
62 | |||
63 | await doubleFollow(servers[0], servers[1]) | ||
64 | }) | ||
65 | |||
66 | describe('Bulk remove comments', function () { | ||
67 | async function checkInstanceCommentsRemoved () { | ||
68 | { | ||
69 | const res = await getVideosList(servers[0].url) | ||
70 | const videos = res.body.data as Video[] | ||
71 | |||
72 | // Server 1 should not have these comments anymore | ||
73 | for (const video of videos) { | ||
74 | const resThreads = await getVideoCommentThreads(servers[0].url, video.id, 0, 10) | ||
75 | const comments = resThreads.body.data as VideoComment[] | ||
76 | const comment = comments.find(c => c.text === 'comment by user 3') | ||
77 | |||
78 | expect(comment).to.not.exist | ||
79 | } | ||
80 | } | ||
81 | |||
82 | { | ||
83 | const res = await getVideosList(servers[1].url) | ||
84 | const videos = res.body.data as Video[] | ||
85 | |||
86 | // Server 1 should not have these comments on videos of server 1 | ||
87 | for (const video of videos) { | ||
88 | const resThreads = await getVideoCommentThreads(servers[1].url, video.id, 0, 10) | ||
89 | const comments = resThreads.body.data as VideoComment[] | ||
90 | const comment = comments.find(c => c.text === 'comment by user 3') | ||
91 | |||
92 | if (video.account.host === 'localhost:' + servers[0].port) { | ||
93 | expect(comment).to.not.exist | ||
94 | } else { | ||
95 | expect(comment).to.exist | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | before(async function () { | ||
102 | this.timeout(60000) | ||
103 | |||
104 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 1 server 1' }) | ||
105 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) | ||
106 | await uploadVideo(servers[0].url, user1AccessToken, { name: 'video 3 server 1' }) | ||
107 | |||
108 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video 1 server 2' }) | ||
109 | |||
110 | await waitJobs(servers) | ||
111 | |||
112 | { | ||
113 | const res = await getVideosList(servers[0].url) | ||
114 | for (const video of res.body.data) { | ||
115 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, video.id, 'comment by root server 1') | ||
116 | await addVideoCommentThread(servers[0].url, user1AccessToken, video.id, 'comment by user 1') | ||
117 | await addVideoCommentThread(servers[0].url, user2AccessToken, video.id, 'comment by user 2') | ||
118 | } | ||
119 | } | ||
120 | |||
121 | { | ||
122 | const res = await getVideosList(servers[1].url) | ||
123 | for (const video of res.body.data) { | ||
124 | await addVideoCommentThread(servers[1].url, servers[1].accessToken, video.id, 'comment by root server 2') | ||
125 | |||
126 | const res = await addVideoCommentThread(servers[1].url, user3AccessToken, video.id, 'comment by user 3') | ||
127 | commentsUser3.push({ videoId: video.id, commentId: res.body.comment.id }) | ||
128 | } | ||
129 | } | ||
130 | |||
131 | await waitJobs(servers) | ||
132 | }) | ||
133 | |||
134 | it('Should delete comments of an account on my videos', async function () { | ||
135 | this.timeout(60000) | ||
136 | |||
137 | await bulkRemoveCommentsOf({ | ||
138 | url: servers[0].url, | ||
139 | token: user1AccessToken, | ||
140 | attributes: { | ||
141 | accountName: 'user2', | ||
142 | scope: 'my-videos' | ||
143 | } | ||
144 | }) | ||
145 | |||
146 | await waitJobs(servers) | ||
147 | |||
148 | for (const server of servers) { | ||
149 | const res = await getVideosList(server.url) | ||
150 | |||
151 | for (const video of res.body.data) { | ||
152 | const resThreads = await getVideoCommentThreads(server.url, video.id, 0, 10) | ||
153 | const comments = resThreads.body.data as VideoComment[] | ||
154 | const comment = comments.find(c => c.text === 'comment by user 2') | ||
155 | |||
156 | if (video.name === 'video 3 server 1') { | ||
157 | expect(comment).to.not.exist | ||
158 | } else { | ||
159 | expect(comment).to.exist | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | }) | ||
164 | |||
165 | it('Should delete comments of an account on the instance', async function () { | ||
166 | this.timeout(60000) | ||
167 | |||
168 | await bulkRemoveCommentsOf({ | ||
169 | url: servers[0].url, | ||
170 | token: servers[0].accessToken, | ||
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 | }) | ||