diff options
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r-- | server/tests/api/moderation/abuses.ts | 57 | ||||
-rw-r--r-- | server/tests/api/moderation/blocklist-notification.ts | 16 | ||||
-rw-r--r-- | server/tests/api/moderation/blocklist.ts | 100 | ||||
-rw-r--r-- | server/tests/api/moderation/video-blacklist.ts | 92 |
4 files changed, 118 insertions, 147 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts index a7119263c..7574b8f4a 100644 --- a/server/tests/api/moderation/abuses.ts +++ b/server/tests/api/moderation/abuses.ts | |||
@@ -7,13 +7,8 @@ import { | |||
7 | cleanupTests, | 7 | cleanupTests, |
8 | doubleFollow, | 8 | doubleFollow, |
9 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
10 | getVideoIdFromUUID, | ||
11 | getVideosList, | ||
12 | removeVideo, | ||
13 | ServerInfo, | 10 | ServerInfo, |
14 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
15 | uploadVideo, | ||
16 | uploadVideoAndGetId, | ||
17 | waitJobs | 12 | waitJobs |
18 | } from '@shared/extra-utils' | 13 | } from '@shared/extra-utils' |
19 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' | 14 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' |
@@ -47,28 +42,30 @@ describe('Test abuses', function () { | |||
47 | this.timeout(50000) | 42 | this.timeout(50000) |
48 | 43 | ||
49 | // Upload some videos on each servers | 44 | // Upload some videos on each servers |
50 | const video1Attributes = { | 45 | { |
51 | name: 'my super name for server 1', | 46 | const attributes = { |
52 | description: 'my super description for server 1' | 47 | name: 'my super name for server 1', |
48 | description: 'my super description for server 1' | ||
49 | } | ||
50 | await servers[0].videosCommand.upload({ attributes }) | ||
53 | } | 51 | } |
54 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | ||
55 | 52 | ||
56 | const video2Attributes = { | 53 | { |
57 | name: 'my super name for server 2', | 54 | const attributes = { |
58 | description: 'my super description for server 2' | 55 | name: 'my super name for server 2', |
56 | description: 'my super description for server 2' | ||
57 | } | ||
58 | await servers[1].videosCommand.upload({ attributes }) | ||
59 | } | 59 | } |
60 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | ||
61 | 60 | ||
62 | // Wait videos propagation, server 2 has transcoding enabled | 61 | // Wait videos propagation, server 2 has transcoding enabled |
63 | await waitJobs(servers) | 62 | await waitJobs(servers) |
64 | 63 | ||
65 | const res = await getVideosList(servers[0].url) | 64 | const { data } = await servers[0].videosCommand.list() |
66 | const videos = res.body.data | 65 | expect(data.length).to.equal(2) |
67 | |||
68 | expect(videos.length).to.equal(2) | ||
69 | 66 | ||
70 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') | 67 | servers[0].video = data.find(video => video.name === 'my super name for server 1') |
71 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | 68 | servers[1].video = data.find(video => video.name === 'my super name for server 2') |
72 | }) | 69 | }) |
73 | 70 | ||
74 | it('Should not have abuses', async function () { | 71 | it('Should not have abuses', async function () { |
@@ -130,7 +127,7 @@ describe('Test abuses', function () { | |||
130 | this.timeout(10000) | 127 | this.timeout(10000) |
131 | 128 | ||
132 | const reason = 'my super bad reason 2' | 129 | const reason = 'my super bad reason 2' |
133 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) | 130 | const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) |
134 | await commands[0].report({ videoId, reason }) | 131 | await commands[0].report({ videoId, reason }) |
135 | 132 | ||
136 | // We wait requests propagation | 133 | // We wait requests propagation |
@@ -203,7 +200,7 @@ describe('Test abuses', function () { | |||
203 | this.timeout(10000) | 200 | this.timeout(10000) |
204 | 201 | ||
205 | { | 202 | { |
206 | const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid) | 203 | const videoId = await servers[1].videosCommand.getId({ uuid: servers[0].video.uuid }) |
207 | await commands[1].report({ videoId, reason: 'will mute this' }) | 204 | await commands[1].report({ videoId, reason: 'will mute this' }) |
208 | await waitJobs(servers) | 205 | await waitJobs(servers) |
209 | 206 | ||
@@ -255,7 +252,7 @@ describe('Test abuses', function () { | |||
255 | it('Should keep the video abuse when deleting the video', async function () { | 252 | it('Should keep the video abuse when deleting the video', async function () { |
256 | this.timeout(10000) | 253 | this.timeout(10000) |
257 | 254 | ||
258 | await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) | 255 | await servers[1].videosCommand.remove({ id: abuseServer2.video.uuid }) |
259 | 256 | ||
260 | await waitJobs(servers) | 257 | await waitJobs(servers) |
261 | 258 | ||
@@ -279,12 +276,12 @@ describe('Test abuses', function () { | |||
279 | const userAccessToken = await servers[0].loginCommand.getAccessToken(user) | 276 | const userAccessToken = await servers[0].loginCommand.getAccessToken(user) |
280 | 277 | ||
281 | // upload a third video via this user | 278 | // upload a third video via this user |
282 | const video3Attributes = { | 279 | const attributes = { |
283 | name: 'my second super name for server 1', | 280 | name: 'my second super name for server 1', |
284 | description: 'my second super description for server 1' | 281 | description: 'my second super description for server 1' |
285 | } | 282 | } |
286 | const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes) | 283 | const { id } = await servers[0].videosCommand.upload({ token: userAccessToken, attributes }) |
287 | const video3Id = resUpload.body.video.id | 284 | const video3Id = id |
288 | 285 | ||
289 | // resume with the test | 286 | // resume with the test |
290 | const reason3 = 'my super bad reason 3' | 287 | const reason3 = 'my super bad reason 3' |
@@ -394,7 +391,7 @@ describe('Test abuses', function () { | |||
394 | 391 | ||
395 | async function getComment (server: ServerInfo, videoIdArg: number | string) { | 392 | async function getComment (server: ServerInfo, videoIdArg: number | string) { |
396 | const videoId = typeof videoIdArg === 'string' | 393 | const videoId = typeof videoIdArg === 'string' |
397 | ? await getVideoIdFromUUID(server.url, videoIdArg) | 394 | ? await server.videosCommand.getId({ uuid: videoIdArg }) |
398 | : videoIdArg | 395 | : videoIdArg |
399 | 396 | ||
400 | const { data } = await server.commentsCommand.listThreads({ videoId }) | 397 | const { data } = await server.commentsCommand.listThreads({ videoId }) |
@@ -405,8 +402,8 @@ describe('Test abuses', function () { | |||
405 | before(async function () { | 402 | before(async function () { |
406 | this.timeout(50000) | 403 | this.timeout(50000) |
407 | 404 | ||
408 | servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' }) | 405 | servers[0].video = await await servers[0].videosCommand.quickUpload({ name: 'server 1' }) |
409 | servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' }) | 406 | servers[1].video = await await servers[1].videosCommand.quickUpload({ name: 'server 2' }) |
410 | 407 | ||
411 | await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) | 408 | await servers[0].commentsCommand.createThread({ videoId: servers[0].video.id, text: 'comment server 1' }) |
412 | await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) | 409 | await servers[1].commentsCommand.createThread({ videoId: servers[1].video.id, text: 'comment server 2' }) |
@@ -604,7 +601,7 @@ describe('Test abuses', function () { | |||
604 | await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) | 601 | await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' }) |
605 | 602 | ||
606 | const token = await servers[1].usersCommand.generateUserAndToken('user_2') | 603 | const token = await servers[1].usersCommand.generateUserAndToken('user_2') |
607 | await uploadVideo(servers[1].url, token, { name: 'super video' }) | 604 | await servers[1].videosCommand.upload({ token, attributes: { name: 'super video' } }) |
608 | 605 | ||
609 | await waitJobs(servers) | 606 | await waitJobs(servers) |
610 | }) | 607 | }) |
@@ -766,7 +763,7 @@ describe('Test abuses', function () { | |||
766 | 763 | ||
767 | await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) | 764 | await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) |
768 | 765 | ||
769 | const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid) | 766 | const videoId = await servers[0].videosCommand.getId({ uuid: servers[1].video.uuid }) |
770 | await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) | 767 | await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) |
771 | }) | 768 | }) |
772 | 769 | ||
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index b44bcb012..92a0ec681 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts | |||
@@ -2,15 +2,7 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' |
6 | cleanupTests, | ||
7 | doubleFollow, | ||
8 | flushAndRunMultipleServers, | ||
9 | ServerInfo, | ||
10 | setAccessTokensToServers, | ||
11 | uploadVideo, | ||
12 | waitJobs | ||
13 | } from '@shared/extra-utils' | ||
14 | import { UserNotificationType } from '@shared/models' | 6 | import { UserNotificationType } from '@shared/models' |
15 | 7 | ||
16 | const expect = chai.expect | 8 | const expect = chai.expect |
@@ -44,8 +36,8 @@ describe('Test blocklist', function () { | |||
44 | await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) | 36 | await servers[0].notificationsCommand.markAsReadAll({ token: userToken2 }) |
45 | 37 | ||
46 | { | 38 | { |
47 | const res = await uploadVideo(servers[0].url, userToken1, { name: 'video' }) | 39 | const { uuid } = await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video' } }) |
48 | videoUUID = res.body.video.uuid | 40 | videoUUID = uuid |
49 | 41 | ||
50 | await waitJobs(servers) | 42 | await waitJobs(servers) |
51 | } | 43 | } |
@@ -83,7 +75,7 @@ describe('Test blocklist', function () { | |||
83 | }) | 75 | }) |
84 | 76 | ||
85 | userToken1 = await servers[0].loginCommand.getAccessToken(user) | 77 | userToken1 = await servers[0].loginCommand.getAccessToken(user) |
86 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) | 78 | await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) |
87 | } | 79 | } |
88 | 80 | ||
89 | { | 81 | { |
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index c253b5c11..3c3b2d6fd 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts | |||
@@ -8,28 +8,23 @@ import { | |||
8 | CommentsCommand, | 8 | CommentsCommand, |
9 | doubleFollow, | 9 | doubleFollow, |
10 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
11 | getVideosList, | ||
12 | getVideosListWithToken, | ||
13 | ServerInfo, | 11 | ServerInfo, |
14 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
15 | uploadVideo, | ||
16 | waitJobs | 13 | waitJobs |
17 | } from '@shared/extra-utils' | 14 | } from '@shared/extra-utils' |
18 | import { UserNotificationType, Video } from '@shared/models' | 15 | import { UserNotificationType } from '@shared/models' |
19 | 16 | ||
20 | const expect = chai.expect | 17 | const expect = chai.expect |
21 | 18 | ||
22 | async function checkAllVideos (server: ServerInfo, token: string) { | 19 | async function checkAllVideos (server: ServerInfo, token: string) { |
23 | { | 20 | { |
24 | const res = await getVideosListWithToken(server.url, token) | 21 | const { data } = await server.videosCommand.listWithToken({ token }) |
25 | 22 | expect(data).to.have.lengthOf(5) | |
26 | expect(res.body.data).to.have.lengthOf(5) | ||
27 | } | 23 | } |
28 | 24 | ||
29 | { | 25 | { |
30 | const res = await getVideosList(server.url) | 26 | const { data } = await server.videosCommand.list() |
31 | 27 | expect(data).to.have.lengthOf(5) | |
32 | expect(res.body.data).to.have.lengthOf(5) | ||
33 | } | 28 | } |
34 | } | 29 | } |
35 | 30 | ||
@@ -93,7 +88,7 @@ describe('Test blocklist', function () { | |||
93 | await servers[0].usersCommand.create({ username: user.username, password: user.password }) | 88 | await servers[0].usersCommand.create({ username: user.username, password: user.password }) |
94 | 89 | ||
95 | userToken1 = await servers[0].loginCommand.getAccessToken(user) | 90 | userToken1 = await servers[0].loginCommand.getAccessToken(user) |
96 | await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) | 91 | await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) |
97 | } | 92 | } |
98 | 93 | ||
99 | { | 94 | { |
@@ -108,22 +103,22 @@ describe('Test blocklist', function () { | |||
108 | await servers[1].usersCommand.create({ username: user.username, password: user.password }) | 103 | await servers[1].usersCommand.create({ username: user.username, password: user.password }) |
109 | 104 | ||
110 | userToken2 = await servers[1].loginCommand.getAccessToken(user) | 105 | userToken2 = await servers[1].loginCommand.getAccessToken(user) |
111 | await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) | 106 | await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) |
112 | } | 107 | } |
113 | 108 | ||
114 | { | 109 | { |
115 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video server 1' }) | 110 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) |
116 | videoUUID1 = res.body.video.uuid | 111 | videoUUID1 = uuid |
117 | } | 112 | } |
118 | 113 | ||
119 | { | 114 | { |
120 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video server 2' }) | 115 | const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) |
121 | videoUUID2 = res.body.video.uuid | 116 | videoUUID2 = uuid |
122 | } | 117 | } |
123 | 118 | ||
124 | { | 119 | { |
125 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video 2 server 1' }) | 120 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) |
126 | videoUUID3 = res.body.video.uuid | 121 | videoUUID3 = uuid |
127 | } | 122 | } |
128 | 123 | ||
129 | await doubleFollow(servers[0], servers[1]) | 124 | await doubleFollow(servers[0], servers[1]) |
@@ -164,12 +159,11 @@ describe('Test blocklist', function () { | |||
164 | }) | 159 | }) |
165 | 160 | ||
166 | it('Should hide its videos', async function () { | 161 | it('Should hide its videos', async function () { |
167 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | 162 | const { data } = await servers[0].videosCommand.listWithToken() |
168 | 163 | ||
169 | const videos: Video[] = res.body.data | 164 | expect(data).to.have.lengthOf(4) |
170 | expect(videos).to.have.lengthOf(4) | ||
171 | 165 | ||
172 | const v = videos.find(v => v.name === 'video user 2') | 166 | const v = data.find(v => v.name === 'video user 2') |
173 | expect(v).to.be.undefined | 167 | expect(v).to.be.undefined |
174 | }) | 168 | }) |
175 | 169 | ||
@@ -178,12 +172,11 @@ describe('Test blocklist', function () { | |||
178 | }) | 172 | }) |
179 | 173 | ||
180 | it('Should hide its videos', async function () { | 174 | it('Should hide its videos', async function () { |
181 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | 175 | const { data } = await servers[0].videosCommand.listWithToken() |
182 | 176 | ||
183 | const videos: Video[] = res.body.data | 177 | expect(data).to.have.lengthOf(3) |
184 | expect(videos).to.have.lengthOf(3) | ||
185 | 178 | ||
186 | const v = videos.find(v => v.name === 'video user 1') | 179 | const v = data.find(v => v.name === 'video user 1') |
187 | expect(v).to.be.undefined | 180 | expect(v).to.be.undefined |
188 | }) | 181 | }) |
189 | 182 | ||
@@ -313,12 +306,10 @@ describe('Test blocklist', function () { | |||
313 | }) | 306 | }) |
314 | 307 | ||
315 | it('Should display its videos', async function () { | 308 | it('Should display its videos', async function () { |
316 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | 309 | const { data } = await servers[0].videosCommand.listWithToken() |
310 | expect(data).to.have.lengthOf(4) | ||
317 | 311 | ||
318 | const videos: Video[] = res.body.data | 312 | const v = data.find(v => v.name === 'video user 2') |
319 | expect(videos).to.have.lengthOf(4) | ||
320 | |||
321 | const v = videos.find(v => v.name === 'video user 2') | ||
322 | expect(v).not.to.be.undefined | 313 | expect(v).not.to.be.undefined |
323 | }) | 314 | }) |
324 | 315 | ||
@@ -387,13 +378,12 @@ describe('Test blocklist', function () { | |||
387 | }) | 378 | }) |
388 | 379 | ||
389 | it('Should hide its videos', async function () { | 380 | it('Should hide its videos', async function () { |
390 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | 381 | const { data } = await servers[0].videosCommand.listWithToken() |
391 | 382 | ||
392 | const videos: Video[] = res.body.data | 383 | expect(data).to.have.lengthOf(3) |
393 | expect(videos).to.have.lengthOf(3) | ||
394 | 384 | ||
395 | const v1 = videos.find(v => v.name === 'video user 2') | 385 | const v1 = data.find(v => v.name === 'video user 2') |
396 | const v2 = videos.find(v => v.name === 'video server 2') | 386 | const v2 = data.find(v => v.name === 'video server 2') |
397 | 387 | ||
398 | expect(v1).to.be.undefined | 388 | expect(v1).to.be.undefined |
399 | expect(v2).to.be.undefined | 389 | expect(v2).to.be.undefined |
@@ -498,12 +488,11 @@ describe('Test blocklist', function () { | |||
498 | 488 | ||
499 | it('Should hide its videos', async function () { | 489 | it('Should hide its videos', async function () { |
500 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 490 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
501 | const res = await getVideosListWithToken(servers[0].url, token) | 491 | const { data } = await servers[0].videosCommand.listWithToken({ token }) |
502 | 492 | ||
503 | const videos: Video[] = res.body.data | 493 | expect(data).to.have.lengthOf(4) |
504 | expect(videos).to.have.lengthOf(4) | ||
505 | 494 | ||
506 | const v = videos.find(v => v.name === 'video user 2') | 495 | const v = data.find(v => v.name === 'video user 2') |
507 | expect(v).to.be.undefined | 496 | expect(v).to.be.undefined |
508 | } | 497 | } |
509 | }) | 498 | }) |
@@ -514,12 +503,11 @@ describe('Test blocklist', function () { | |||
514 | 503 | ||
515 | it('Should hide its videos', async function () { | 504 | it('Should hide its videos', async function () { |
516 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 505 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
517 | const res = await getVideosListWithToken(servers[0].url, token) | 506 | const { data } = await servers[0].videosCommand.listWithToken({ token }) |
518 | 507 | ||
519 | const videos: Video[] = res.body.data | 508 | expect(data).to.have.lengthOf(3) |
520 | expect(videos).to.have.lengthOf(3) | ||
521 | 509 | ||
522 | const v = videos.find(v => v.name === 'video user 1') | 510 | const v = data.find(v => v.name === 'video user 1') |
523 | expect(v).to.be.undefined | 511 | expect(v).to.be.undefined |
524 | } | 512 | } |
525 | }) | 513 | }) |
@@ -593,12 +581,10 @@ describe('Test blocklist', function () { | |||
593 | 581 | ||
594 | it('Should display its videos', async function () { | 582 | it('Should display its videos', async function () { |
595 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 583 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
596 | const res = await getVideosListWithToken(servers[0].url, token) | 584 | const { data } = await servers[0].videosCommand.listWithToken({ token }) |
597 | 585 | expect(data).to.have.lengthOf(4) | |
598 | const videos: Video[] = res.body.data | ||
599 | expect(videos).to.have.lengthOf(4) | ||
600 | 586 | ||
601 | const v = videos.find(v => v.name === 'video user 2') | 587 | const v = data.find(v => v.name === 'video user 2') |
602 | expect(v).not.to.be.undefined | 588 | expect(v).not.to.be.undefined |
603 | } | 589 | } |
604 | }) | 590 | }) |
@@ -652,15 +638,17 @@ describe('Test blocklist', function () { | |||
652 | 638 | ||
653 | it('Should hide its videos', async function () { | 639 | it('Should hide its videos', async function () { |
654 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 640 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
655 | const res1 = await getVideosList(servers[0].url) | 641 | const requests = [ |
656 | const res2 = await getVideosListWithToken(servers[0].url, token) | 642 | servers[0].videosCommand.list(), |
643 | servers[0].videosCommand.listWithToken({ token }) | ||
644 | ] | ||
657 | 645 | ||
658 | for (const res of [ res1, res2 ]) { | 646 | for (const req of requests) { |
659 | const videos: Video[] = res.body.data | 647 | const { data } = await req |
660 | expect(videos).to.have.lengthOf(3) | 648 | expect(data).to.have.lengthOf(3) |
661 | 649 | ||
662 | const v1 = videos.find(v => v.name === 'video user 2') | 650 | const v1 = data.find(v => v.name === 'video user 2') |
663 | const v2 = videos.find(v => v.name === 'video server 2') | 651 | const v2 = data.find(v => v.name === 'video server 2') |
664 | 652 | ||
665 | expect(v1).to.be.undefined | 653 | expect(v1).to.be.undefined |
666 | expect(v2).to.be.undefined | 654 | expect(v2).to.be.undefined |
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index ef25cfb8e..2f2e678e7 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts | |||
@@ -8,15 +8,11 @@ import { | |||
8 | cleanupTests, | 8 | cleanupTests, |
9 | doubleFollow, | 9 | doubleFollow, |
10 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
11 | getMyVideos, | ||
12 | getVideosList, | ||
13 | ImportsCommand, | 11 | ImportsCommand, |
14 | killallServers, | 12 | killallServers, |
15 | reRunServer, | 13 | reRunServer, |
16 | ServerInfo, | 14 | ServerInfo, |
17 | setAccessTokensToServers, | 15 | setAccessTokensToServers, |
18 | updateVideo, | ||
19 | uploadVideo, | ||
20 | waitJobs | 16 | waitJobs |
21 | } from '@shared/extra-utils' | 17 | } from '@shared/extra-utils' |
22 | import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' | 18 | import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' |
@@ -29,10 +25,9 @@ describe('Test video blacklist', function () { | |||
29 | let command: BlacklistCommand | 25 | let command: BlacklistCommand |
30 | 26 | ||
31 | async function blacklistVideosOnServer (server: ServerInfo) { | 27 | async function blacklistVideosOnServer (server: ServerInfo) { |
32 | const res = await getVideosList(server.url) | 28 | const { data } = await server.videosCommand.list() |
33 | 29 | ||
34 | const videos = res.body.data | 30 | for (const video of data) { |
35 | for (const video of videos) { | ||
36 | await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) | 31 | await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) |
37 | } | 32 | } |
38 | } | 33 | } |
@@ -50,8 +45,8 @@ describe('Test video blacklist', function () { | |||
50 | await doubleFollow(servers[0], servers[1]) | 45 | await doubleFollow(servers[0], servers[1]) |
51 | 46 | ||
52 | // Upload 2 videos on server 2 | 47 | // Upload 2 videos on server 2 |
53 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) | 48 | await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } }) |
54 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) | 49 | await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } }) |
55 | 50 | ||
56 | // Wait videos propagation, server 2 has transcoding enabled | 51 | // Wait videos propagation, server 2 has transcoding enabled |
57 | await waitJobs(servers) | 52 | await waitJobs(servers) |
@@ -66,11 +61,11 @@ describe('Test video blacklist', function () { | |||
66 | 61 | ||
67 | it('Should not have the video blacklisted in videos list/search on server 1', async function () { | 62 | it('Should not have the video blacklisted in videos list/search on server 1', async function () { |
68 | { | 63 | { |
69 | const res = await getVideosList(servers[0].url) | 64 | const { total, data } = await servers[0].videosCommand.list() |
70 | 65 | ||
71 | expect(res.body.total).to.equal(0) | 66 | expect(total).to.equal(0) |
72 | expect(res.body.data).to.be.an('array') | 67 | expect(data).to.be.an('array') |
73 | expect(res.body.data.length).to.equal(0) | 68 | expect(data.length).to.equal(0) |
74 | } | 69 | } |
75 | 70 | ||
76 | { | 71 | { |
@@ -84,11 +79,11 @@ describe('Test video blacklist', function () { | |||
84 | 79 | ||
85 | it('Should have the blacklisted video in videos list/search on server 2', async function () { | 80 | it('Should have the blacklisted video in videos list/search on server 2', async function () { |
86 | { | 81 | { |
87 | const res = await getVideosList(servers[1].url) | 82 | const { total, data } = await servers[1].videosCommand.list() |
88 | 83 | ||
89 | expect(res.body.total).to.equal(2) | 84 | expect(total).to.equal(2) |
90 | expect(res.body.data).to.be.an('array') | 85 | expect(data).to.be.an('array') |
91 | expect(res.body.data.length).to.equal(2) | 86 | expect(data.length).to.equal(2) |
92 | } | 87 | } |
93 | 88 | ||
94 | { | 89 | { |
@@ -186,12 +181,12 @@ describe('Test video blacklist', function () { | |||
186 | it('Should display blacklisted videos', async function () { | 181 | it('Should display blacklisted videos', async function () { |
187 | await blacklistVideosOnServer(servers[1]) | 182 | await blacklistVideosOnServer(servers[1]) |
188 | 183 | ||
189 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) | 184 | const { total, data } = await servers[1].videosCommand.listMyVideos() |
190 | 185 | ||
191 | expect(res.body.total).to.equal(2) | 186 | expect(total).to.equal(2) |
192 | expect(res.body.data).to.have.lengthOf(2) | 187 | expect(data).to.have.lengthOf(2) |
193 | 188 | ||
194 | for (const video of res.body.data) { | 189 | for (const video of data) { |
195 | expect(video.blacklisted).to.be.true | 190 | expect(video.blacklisted).to.be.true |
196 | expect(video.blacklistedReason).to.equal('super reason') | 191 | expect(video.blacklistedReason).to.equal('super reason') |
197 | } | 192 | } |
@@ -203,10 +198,10 @@ describe('Test video blacklist', function () { | |||
203 | let blacklist = [] | 198 | let blacklist = [] |
204 | 199 | ||
205 | it('Should not have any video in videos list on server 1', async function () { | 200 | it('Should not have any video in videos list on server 1', async function () { |
206 | const res = await getVideosList(servers[0].url) | 201 | const { total, data } = await servers[0].videosCommand.list() |
207 | expect(res.body.total).to.equal(0) | 202 | expect(total).to.equal(0) |
208 | expect(res.body.data).to.be.an('array') | 203 | expect(data).to.be.an('array') |
209 | expect(res.body.data.length).to.equal(0) | 204 | expect(data.length).to.equal(0) |
210 | }) | 205 | }) |
211 | 206 | ||
212 | it('Should remove a video from the blacklist on server 1', async function () { | 207 | it('Should remove a video from the blacklist on server 1', async function () { |
@@ -220,15 +215,14 @@ describe('Test video blacklist', function () { | |||
220 | }) | 215 | }) |
221 | 216 | ||
222 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { | 217 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { |
223 | const res = await getVideosList(servers[0].url) | 218 | const { total, data } = await servers[0].videosCommand.list() |
224 | expect(res.body.total).to.equal(1) | 219 | expect(total).to.equal(1) |
225 | 220 | ||
226 | const videos = res.body.data | 221 | expect(data).to.be.an('array') |
227 | expect(videos).to.be.an('array') | 222 | expect(data.length).to.equal(1) |
228 | expect(videos.length).to.equal(1) | ||
229 | 223 | ||
230 | expect(videos[0].name).to.equal(videoToRemove.video.name) | 224 | expect(data[0].name).to.equal(videoToRemove.video.name) |
231 | expect(videos[0].id).to.equal(videoToRemove.video.id) | 225 | expect(data[0].id).to.equal(videoToRemove.video.id) |
232 | }) | 226 | }) |
233 | 227 | ||
234 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | 228 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { |
@@ -250,12 +244,12 @@ describe('Test video blacklist', function () { | |||
250 | this.timeout(10000) | 244 | this.timeout(10000) |
251 | 245 | ||
252 | { | 246 | { |
253 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) | 247 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } }) |
254 | video3UUID = res.body.video.uuid | 248 | video3UUID = uuid |
255 | } | 249 | } |
256 | { | 250 | { |
257 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) | 251 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } }) |
258 | video4UUID = res.body.video.uuid | 252 | video4UUID = uuid |
259 | } | 253 | } |
260 | 254 | ||
261 | await waitJobs(servers) | 255 | await waitJobs(servers) |
@@ -269,13 +263,13 @@ describe('Test video blacklist', function () { | |||
269 | await waitJobs(servers) | 263 | await waitJobs(servers) |
270 | 264 | ||
271 | { | 265 | { |
272 | const res = await getVideosList(servers[0].url) | 266 | const { data } = await servers[0].videosCommand.list() |
273 | expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined | 267 | expect(data.find(v => v.uuid === video3UUID)).to.be.undefined |
274 | } | 268 | } |
275 | 269 | ||
276 | { | 270 | { |
277 | const res = await getVideosList(servers[1].url) | 271 | const { data } = await servers[1].videosCommand.list() |
278 | expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined | 272 | expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined |
279 | } | 273 | } |
280 | }) | 274 | }) |
281 | 275 | ||
@@ -287,21 +281,21 @@ describe('Test video blacklist', function () { | |||
287 | await waitJobs(servers) | 281 | await waitJobs(servers) |
288 | 282 | ||
289 | for (const server of servers) { | 283 | for (const server of servers) { |
290 | const res = await getVideosList(server.url) | 284 | const { data } = await server.videosCommand.list() |
291 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined | 285 | expect(data.find(v => v.uuid === video4UUID)).to.be.undefined |
292 | } | 286 | } |
293 | }) | 287 | }) |
294 | 288 | ||
295 | it('Should have the video unfederated even after an Update AP message', async function () { | 289 | it('Should have the video unfederated even after an Update AP message', async function () { |
296 | this.timeout(10000) | 290 | this.timeout(10000) |
297 | 291 | ||
298 | await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) | 292 | await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } }) |
299 | 293 | ||
300 | await waitJobs(servers) | 294 | await waitJobs(servers) |
301 | 295 | ||
302 | for (const server of servers) { | 296 | for (const server of servers) { |
303 | const res = await getVideosList(server.url) | 297 | const { data } = await server.videosCommand.list() |
304 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined | 298 | expect(data.find(v => v.uuid === video4UUID)).to.be.undefined |
305 | } | 299 | } |
306 | }) | 300 | }) |
307 | 301 | ||
@@ -324,8 +318,8 @@ describe('Test video blacklist', function () { | |||
324 | await waitJobs(servers) | 318 | await waitJobs(servers) |
325 | 319 | ||
326 | for (const server of servers) { | 320 | for (const server of servers) { |
327 | const res = await getVideosList(server.url) | 321 | const { data } = await server.videosCommand.list() |
328 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined | 322 | expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined |
329 | } | 323 | } |
330 | }) | 324 | }) |
331 | 325 | ||
@@ -383,7 +377,7 @@ describe('Test video blacklist', function () { | |||
383 | }) | 377 | }) |
384 | 378 | ||
385 | it('Should auto blacklist a video on upload', async function () { | 379 | it('Should auto blacklist a video on upload', async function () { |
386 | await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) | 380 | await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) |
387 | 381 | ||
388 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | 382 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) |
389 | expect(body.total).to.equal(1) | 383 | expect(body.total).to.equal(1) |
@@ -419,7 +413,7 @@ describe('Test video blacklist', function () { | |||
419 | }) | 413 | }) |
420 | 414 | ||
421 | it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { | 415 | it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { |
422 | await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) | 416 | await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) |
423 | 417 | ||
424 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | 418 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) |
425 | expect(body.total).to.equal(3) | 419 | expect(body.total).to.equal(3) |