diff options
Diffstat (limited to 'server/tests/api/activitypub/cleaner.ts')
-rw-r--r-- | server/tests/api/activitypub/cleaner.ts | 105 |
1 files changed, 49 insertions, 56 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 75ef56ce3..51cf6e599 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts | |||
@@ -4,24 +4,18 @@ import 'mocha' | |||
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | closeAllSequelize, | 7 | createMultipleServers, |
8 | deleteAll, | ||
9 | doubleFollow, | 8 | doubleFollow, |
10 | getCount, | 9 | PeerTubeServer, |
11 | selectQuery, | 10 | setAccessTokensToServers, |
12 | setVideoField, | 11 | wait, |
13 | updateQuery, | 12 | waitJobs |
14 | wait | 13 | } from '@shared/extra-utils' |
15 | } from '../../../../shared/extra-utils' | ||
16 | import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index' | ||
17 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
18 | import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments' | ||
19 | import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos' | ||
20 | 14 | ||
21 | const expect = chai.expect | 15 | const expect = chai.expect |
22 | 16 | ||
23 | describe('Test AP cleaner', function () { | 17 | describe('Test AP cleaner', function () { |
24 | let servers: ServerInfo[] = [] | 18 | let servers: PeerTubeServer[] = [] |
25 | let videoUUID1: string | 19 | let videoUUID1: string |
26 | let videoUUID2: string | 20 | let videoUUID2: string |
27 | let videoUUID3: string | 21 | let videoUUID3: string |
@@ -36,7 +30,7 @@ describe('Test AP cleaner', function () { | |||
36 | videos: { cleanup_remote_interactions: true } | 30 | videos: { cleanup_remote_interactions: true } |
37 | } | 31 | } |
38 | } | 32 | } |
39 | servers = await flushAndRunMultipleServers(3, config) | 33 | servers = await createMultipleServers(3, config) |
40 | 34 | ||
41 | // Get the access tokens | 35 | // Get the access tokens |
42 | await setAccessTokensToServers(servers) | 36 | await setAccessTokensToServers(servers) |
@@ -52,9 +46,9 @@ describe('Test AP cleaner', function () { | |||
52 | // Create 1 comment per video | 46 | // Create 1 comment per video |
53 | // Update 1 remote URL and 1 local URL on | 47 | // Update 1 remote URL and 1 local URL on |
54 | 48 | ||
55 | videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid | 49 | videoUUID1 = (await servers[0].videos.quickUpload({ name: 'server 1' })).uuid |
56 | videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid | 50 | videoUUID2 = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid |
57 | videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid | 51 | videoUUID3 = (await servers[2].videos.quickUpload({ name: 'server 3' })).uuid |
58 | 52 | ||
59 | videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] | 53 | videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] |
60 | 54 | ||
@@ -62,8 +56,8 @@ describe('Test AP cleaner', function () { | |||
62 | 56 | ||
63 | for (const server of servers) { | 57 | for (const server of servers) { |
64 | for (const uuid of videoUUIDs) { | 58 | for (const uuid of videoUUIDs) { |
65 | await rateVideo(server.url, server.accessToken, uuid, 'like') | 59 | await server.videos.rate({ id: uuid, rating: 'like' }) |
66 | await addVideoCommentThread(server.url, server.accessToken, uuid, 'comment') | 60 | await server.comments.createThread({ videoId: uuid, text: 'comment' }) |
67 | } | 61 | } |
68 | } | 62 | } |
69 | 63 | ||
@@ -73,9 +67,10 @@ describe('Test AP cleaner', function () { | |||
73 | it('Should have the correct likes', async function () { | 67 | it('Should have the correct likes', async function () { |
74 | for (const server of servers) { | 68 | for (const server of servers) { |
75 | for (const uuid of videoUUIDs) { | 69 | for (const uuid of videoUUIDs) { |
76 | const res = await getVideo(server.url, uuid) | 70 | const video = await server.videos.get({ id: uuid }) |
77 | expect(res.body.likes).to.equal(3) | 71 | |
78 | expect(res.body.dislikes).to.equal(0) | 72 | expect(video.likes).to.equal(3) |
73 | expect(video.dislikes).to.equal(0) | ||
79 | } | 74 | } |
80 | } | 75 | } |
81 | }) | 76 | }) |
@@ -83,9 +78,9 @@ describe('Test AP cleaner', function () { | |||
83 | it('Should destroy server 3 internal likes and correctly clean them', async function () { | 78 | it('Should destroy server 3 internal likes and correctly clean them', async function () { |
84 | this.timeout(20000) | 79 | this.timeout(20000) |
85 | 80 | ||
86 | await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') | 81 | await servers[2].sql.deleteAll('accountVideoRate') |
87 | for (const uuid of videoUUIDs) { | 82 | for (const uuid of videoUUIDs) { |
88 | await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') | 83 | await servers[2].sql.setVideoField(uuid, 'likes', '0') |
89 | } | 84 | } |
90 | 85 | ||
91 | await wait(5000) | 86 | await wait(5000) |
@@ -93,16 +88,16 @@ describe('Test AP cleaner', function () { | |||
93 | 88 | ||
94 | // Updated rates of my video | 89 | // Updated rates of my video |
95 | { | 90 | { |
96 | const res = await getVideo(servers[0].url, videoUUID1) | 91 | const video = await servers[0].videos.get({ id: videoUUID1 }) |
97 | expect(res.body.likes).to.equal(2) | 92 | expect(video.likes).to.equal(2) |
98 | expect(res.body.dislikes).to.equal(0) | 93 | expect(video.dislikes).to.equal(0) |
99 | } | 94 | } |
100 | 95 | ||
101 | // Did not update rates of a remote video | 96 | // Did not update rates of a remote video |
102 | { | 97 | { |
103 | const res = await getVideo(servers[0].url, videoUUID2) | 98 | const video = await servers[0].videos.get({ id: videoUUID2 }) |
104 | expect(res.body.likes).to.equal(3) | 99 | expect(video.likes).to.equal(3) |
105 | expect(res.body.dislikes).to.equal(0) | 100 | expect(video.dislikes).to.equal(0) |
106 | } | 101 | } |
107 | }) | 102 | }) |
108 | 103 | ||
@@ -111,7 +106,7 @@ describe('Test AP cleaner', function () { | |||
111 | 106 | ||
112 | for (const server of servers) { | 107 | for (const server of servers) { |
113 | for (const uuid of videoUUIDs) { | 108 | for (const uuid of videoUUIDs) { |
114 | await rateVideo(server.url, server.accessToken, uuid, 'dislike') | 109 | await server.videos.rate({ id: uuid, rating: 'dislike' }) |
115 | } | 110 | } |
116 | } | 111 | } |
117 | 112 | ||
@@ -119,9 +114,9 @@ describe('Test AP cleaner', function () { | |||
119 | 114 | ||
120 | for (const server of servers) { | 115 | for (const server of servers) { |
121 | for (const uuid of videoUUIDs) { | 116 | for (const uuid of videoUUIDs) { |
122 | const res = await getVideo(server.url, uuid) | 117 | const video = await server.videos.get({ id: uuid }) |
123 | expect(res.body.likes).to.equal(0) | 118 | expect(video.likes).to.equal(0) |
124 | expect(res.body.dislikes).to.equal(3) | 119 | expect(video.dislikes).to.equal(3) |
125 | } | 120 | } |
126 | } | 121 | } |
127 | }) | 122 | }) |
@@ -129,10 +124,10 @@ describe('Test AP cleaner', function () { | |||
129 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { | 124 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { |
130 | this.timeout(20000) | 125 | this.timeout(20000) |
131 | 126 | ||
132 | await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') | 127 | await servers[2].sql.deleteAll('accountVideoRate') |
133 | 128 | ||
134 | for (const uuid of videoUUIDs) { | 129 | for (const uuid of videoUUIDs) { |
135 | await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') | 130 | await servers[2].sql.setVideoField(uuid, 'dislikes', '0') |
136 | } | 131 | } |
137 | 132 | ||
138 | await wait(5000) | 133 | await wait(5000) |
@@ -140,31 +135,31 @@ describe('Test AP cleaner', function () { | |||
140 | 135 | ||
141 | // Updated rates of my video | 136 | // Updated rates of my video |
142 | { | 137 | { |
143 | const res = await getVideo(servers[0].url, videoUUID1) | 138 | const video = await servers[0].videos.get({ id: videoUUID1 }) |
144 | expect(res.body.likes).to.equal(0) | 139 | expect(video.likes).to.equal(0) |
145 | expect(res.body.dislikes).to.equal(2) | 140 | expect(video.dislikes).to.equal(2) |
146 | } | 141 | } |
147 | 142 | ||
148 | // Did not update rates of a remote video | 143 | // Did not update rates of a remote video |
149 | { | 144 | { |
150 | const res = await getVideo(servers[0].url, videoUUID2) | 145 | const video = await servers[0].videos.get({ id: videoUUID2 }) |
151 | expect(res.body.likes).to.equal(0) | 146 | expect(video.likes).to.equal(0) |
152 | expect(res.body.dislikes).to.equal(3) | 147 | expect(video.dislikes).to.equal(3) |
153 | } | 148 | } |
154 | }) | 149 | }) |
155 | 150 | ||
156 | it('Should destroy server 3 internal shares and correctly clean them', async function () { | 151 | it('Should destroy server 3 internal shares and correctly clean them', async function () { |
157 | this.timeout(20000) | 152 | this.timeout(20000) |
158 | 153 | ||
159 | const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') | 154 | const preCount = await servers[0].sql.getCount('videoShare') |
160 | expect(preCount).to.equal(6) | 155 | expect(preCount).to.equal(6) |
161 | 156 | ||
162 | await deleteAll(servers[2].internalServerNumber, 'videoShare') | 157 | await servers[2].sql.deleteAll('videoShare') |
163 | await wait(5000) | 158 | await wait(5000) |
164 | await waitJobs(servers) | 159 | await waitJobs(servers) |
165 | 160 | ||
166 | // Still 6 because we don't have remote shares on local videos | 161 | // Still 6 because we don't have remote shares on local videos |
167 | const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') | 162 | const postCount = await servers[0].sql.getCount('videoShare') |
168 | expect(postCount).to.equal(6) | 163 | expect(postCount).to.equal(6) |
169 | }) | 164 | }) |
170 | 165 | ||
@@ -172,18 +167,18 @@ describe('Test AP cleaner', function () { | |||
172 | this.timeout(20000) | 167 | this.timeout(20000) |
173 | 168 | ||
174 | { | 169 | { |
175 | const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) | 170 | const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) |
176 | expect(res.body.total).to.equal(3) | 171 | expect(total).to.equal(3) |
177 | } | 172 | } |
178 | 173 | ||
179 | await deleteAll(servers[2].internalServerNumber, 'videoComment') | 174 | await servers[2].sql.deleteAll('videoComment') |
180 | 175 | ||
181 | await wait(5000) | 176 | await wait(5000) |
182 | await waitJobs(servers) | 177 | await waitJobs(servers) |
183 | 178 | ||
184 | { | 179 | { |
185 | const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) | 180 | const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 }) |
186 | expect(res.body.total).to.equal(2) | 181 | expect(total).to.equal(2) |
187 | } | 182 | } |
188 | }) | 183 | }) |
189 | 184 | ||
@@ -193,7 +188,7 @@ describe('Test AP cleaner', function () { | |||
193 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { | 188 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { |
194 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + | 189 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + |
195 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` | 190 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` |
196 | const res = await selectQuery(servers[0].internalServerNumber, query) | 191 | const res = await servers[0].sql.selectQuery(query) |
197 | 192 | ||
198 | for (const rate of res) { | 193 | for (const rate of res) { |
199 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) | 194 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) |
@@ -222,7 +217,7 @@ describe('Test AP cleaner', function () { | |||
222 | 217 | ||
223 | { | 218 | { |
224 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` | 219 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` |
225 | await updateQuery(servers[1].internalServerNumber, query) | 220 | await servers[1].sql.updateQuery(query) |
226 | 221 | ||
227 | await wait(5000) | 222 | await wait(5000) |
228 | await waitJobs(servers) | 223 | await waitJobs(servers) |
@@ -239,7 +234,7 @@ describe('Test AP cleaner', function () { | |||
239 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + | 234 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + |
240 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` | 235 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` |
241 | 236 | ||
242 | const res = await selectQuery(servers[0].internalServerNumber, query) | 237 | const res = await servers[0].sql.selectQuery(query) |
243 | 238 | ||
244 | for (const comment of res) { | 239 | for (const comment of res) { |
245 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) | 240 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) |
@@ -265,7 +260,7 @@ describe('Test AP cleaner', function () { | |||
265 | 260 | ||
266 | { | 261 | { |
267 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` | 262 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` |
268 | await updateQuery(servers[1].internalServerNumber, query) | 263 | await servers[1].sql.updateQuery(query) |
269 | 264 | ||
270 | await wait(5000) | 265 | await wait(5000) |
271 | await waitJobs(servers) | 266 | await waitJobs(servers) |
@@ -277,7 +272,5 @@ describe('Test AP cleaner', function () { | |||
277 | 272 | ||
278 | after(async function () { | 273 | after(async function () { |
279 | await cleanupTests(servers) | 274 | await cleanupTests(servers) |
280 | |||
281 | await closeAllSequelize(servers) | ||
282 | }) | 275 | }) |
283 | }) | 276 | }) |