diff options
Diffstat (limited to 'server/tests/api/moderation/blocklist.ts')
-rw-r--r-- | server/tests/api/moderation/blocklist.ts | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 3c3b2d6fd..9a4a3b3b9 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts | |||
@@ -18,24 +18,24 @@ const expect = chai.expect | |||
18 | 18 | ||
19 | async function checkAllVideos (server: ServerInfo, token: string) { | 19 | async function checkAllVideos (server: ServerInfo, token: string) { |
20 | { | 20 | { |
21 | const { data } = await server.videosCommand.listWithToken({ token }) | 21 | const { data } = await server.videos.listWithToken({ token }) |
22 | expect(data).to.have.lengthOf(5) | 22 | expect(data).to.have.lengthOf(5) |
23 | } | 23 | } |
24 | 24 | ||
25 | { | 25 | { |
26 | const { data } = await server.videosCommand.list() | 26 | const { data } = await server.videos.list() |
27 | expect(data).to.have.lengthOf(5) | 27 | expect(data).to.have.lengthOf(5) |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { | 31 | async function checkAllComments (server: ServerInfo, token: string, videoUUID: string) { |
32 | const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) | 32 | const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) |
33 | 33 | ||
34 | const threads = data.filter(t => t.isDeleted === false) | 34 | const threads = data.filter(t => t.isDeleted === false) |
35 | expect(threads).to.have.lengthOf(2) | 35 | expect(threads).to.have.lengthOf(2) |
36 | 36 | ||
37 | for (const thread of threads) { | 37 | for (const thread of threads) { |
38 | const tree = await server.commentsCommand.getThread({ videoId: videoUUID, threadId: thread.id, token }) | 38 | const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token }) |
39 | expect(tree.children).to.have.lengthOf(1) | 39 | expect(tree.children).to.have.lengthOf(1) |
40 | } | 40 | } |
41 | } | 41 | } |
@@ -45,13 +45,13 @@ async function checkCommentNotification ( | |||
45 | comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, | 45 | comment: { server: ServerInfo, token: string, videoUUID: string, text: string }, |
46 | check: 'presence' | 'absence' | 46 | check: 'presence' | 'absence' |
47 | ) { | 47 | ) { |
48 | const command = comment.server.commentsCommand | 48 | const command = comment.server.comments |
49 | 49 | ||
50 | const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) | 50 | const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) |
51 | 51 | ||
52 | await waitJobs([ mainServer, comment.server ]) | 52 | await waitJobs([ mainServer, comment.server ]) |
53 | 53 | ||
54 | const { data } = await mainServer.notificationsCommand.list({ start: 0, count: 30 }) | 54 | const { data } = await mainServer.notifications.list({ start: 0, count: 30 }) |
55 | const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) | 55 | const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) |
56 | 56 | ||
57 | if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) | 57 | if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) |
@@ -80,44 +80,44 @@ describe('Test blocklist', function () { | |||
80 | servers = await flushAndRunMultipleServers(3) | 80 | servers = await flushAndRunMultipleServers(3) |
81 | await setAccessTokensToServers(servers) | 81 | await setAccessTokensToServers(servers) |
82 | 82 | ||
83 | command = servers[0].blocklistCommand | 83 | command = servers[0].blocklist |
84 | commentsCommand = servers.map(s => s.commentsCommand) | 84 | commentsCommand = servers.map(s => s.comments) |
85 | 85 | ||
86 | { | 86 | { |
87 | const user = { username: 'user1', password: 'password' } | 87 | const user = { username: 'user1', password: 'password' } |
88 | await servers[0].usersCommand.create({ username: user.username, password: user.password }) | 88 | await servers[0].users.create({ username: user.username, password: user.password }) |
89 | 89 | ||
90 | userToken1 = await servers[0].loginCommand.getAccessToken(user) | 90 | userToken1 = await servers[0].login.getAccessToken(user) |
91 | await servers[0].videosCommand.upload({ token: userToken1, attributes: { name: 'video user 1' } }) | 91 | await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) |
92 | } | 92 | } |
93 | 93 | ||
94 | { | 94 | { |
95 | const user = { username: 'moderator', password: 'password' } | 95 | const user = { username: 'moderator', password: 'password' } |
96 | await servers[0].usersCommand.create({ username: user.username, password: user.password }) | 96 | await servers[0].users.create({ username: user.username, password: user.password }) |
97 | 97 | ||
98 | userModeratorToken = await servers[0].loginCommand.getAccessToken(user) | 98 | userModeratorToken = await servers[0].login.getAccessToken(user) |
99 | } | 99 | } |
100 | 100 | ||
101 | { | 101 | { |
102 | const user = { username: 'user2', password: 'password' } | 102 | const user = { username: 'user2', password: 'password' } |
103 | await servers[1].usersCommand.create({ username: user.username, password: user.password }) | 103 | await servers[1].users.create({ username: user.username, password: user.password }) |
104 | 104 | ||
105 | userToken2 = await servers[1].loginCommand.getAccessToken(user) | 105 | userToken2 = await servers[1].login.getAccessToken(user) |
106 | await servers[1].videosCommand.upload({ token: userToken2, attributes: { name: 'video user 2' } }) | 106 | await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } }) |
107 | } | 107 | } |
108 | 108 | ||
109 | { | 109 | { |
110 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } }) | 110 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) |
111 | videoUUID1 = uuid | 111 | videoUUID1 = uuid |
112 | } | 112 | } |
113 | 113 | ||
114 | { | 114 | { |
115 | const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } }) | 115 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) |
116 | videoUUID2 = uuid | 116 | videoUUID2 = uuid |
117 | } | 117 | } |
118 | 118 | ||
119 | { | 119 | { |
120 | const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video 2 server 1' } }) | 120 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) |
121 | videoUUID3 = uuid | 121 | videoUUID3 = uuid |
122 | } | 122 | } |
123 | 123 | ||
@@ -159,7 +159,7 @@ describe('Test blocklist', function () { | |||
159 | }) | 159 | }) |
160 | 160 | ||
161 | it('Should hide its videos', async function () { | 161 | it('Should hide its videos', async function () { |
162 | const { data } = await servers[0].videosCommand.listWithToken() | 162 | const { data } = await servers[0].videos.listWithToken() |
163 | 163 | ||
164 | expect(data).to.have.lengthOf(4) | 164 | expect(data).to.have.lengthOf(4) |
165 | 165 | ||
@@ -172,7 +172,7 @@ describe('Test blocklist', function () { | |||
172 | }) | 172 | }) |
173 | 173 | ||
174 | it('Should hide its videos', async function () { | 174 | it('Should hide its videos', async function () { |
175 | const { data } = await servers[0].videosCommand.listWithToken() | 175 | const { data } = await servers[0].videos.listWithToken() |
176 | 176 | ||
177 | expect(data).to.have.lengthOf(3) | 177 | expect(data).to.have.lengthOf(3) |
178 | 178 | ||
@@ -289,12 +289,12 @@ describe('Test blocklist', function () { | |||
289 | 289 | ||
290 | // Server 1 and 3 should only have uploader comments | 290 | // Server 1 and 3 should only have uploader comments |
291 | for (const server of [ servers[0], servers[2] ]) { | 291 | for (const server of [ servers[0], servers[2] ]) { |
292 | const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) | 292 | const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) |
293 | 293 | ||
294 | expect(data).to.have.lengthOf(1) | 294 | expect(data).to.have.lengthOf(1) |
295 | expect(data[0].text).to.equal('uploader') | 295 | expect(data[0].text).to.equal('uploader') |
296 | 296 | ||
297 | const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) | 297 | const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) |
298 | 298 | ||
299 | if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) | 299 | if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) |
300 | else expect(tree.children).to.have.lengthOf(1) | 300 | else expect(tree.children).to.have.lengthOf(1) |
@@ -306,7 +306,7 @@ describe('Test blocklist', function () { | |||
306 | }) | 306 | }) |
307 | 307 | ||
308 | it('Should display its videos', async function () { | 308 | it('Should display its videos', async function () { |
309 | const { data } = await servers[0].videosCommand.listWithToken() | 309 | const { data } = await servers[0].videos.listWithToken() |
310 | expect(data).to.have.lengthOf(4) | 310 | expect(data).to.have.lengthOf(4) |
311 | 311 | ||
312 | const v = data.find(v => v.name === 'video user 2') | 312 | const v = data.find(v => v.name === 'video user 2') |
@@ -315,7 +315,7 @@ describe('Test blocklist', function () { | |||
315 | 315 | ||
316 | it('Should display its comments on my video', async function () { | 316 | it('Should display its comments on my video', async function () { |
317 | for (const server of servers) { | 317 | for (const server of servers) { |
318 | const { data } = await server.commentsCommand.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) | 318 | const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) |
319 | 319 | ||
320 | // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment | 320 | // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment |
321 | if (server.serverNumber === 3) { | 321 | if (server.serverNumber === 3) { |
@@ -327,7 +327,7 @@ describe('Test blocklist', function () { | |||
327 | expect(data[0].text).to.equal('uploader') | 327 | expect(data[0].text).to.equal('uploader') |
328 | expect(data[1].text).to.equal('comment user 2') | 328 | expect(data[1].text).to.equal('comment user 2') |
329 | 329 | ||
330 | const tree = await server.commentsCommand.getThread({ videoId: videoUUID3, threadId: data[0].id }) | 330 | const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) |
331 | expect(tree.children).to.have.lengthOf(1) | 331 | expect(tree.children).to.have.lengthOf(1) |
332 | expect(tree.children[0].comment.text).to.equal('reply by user 2') | 332 | expect(tree.children[0].comment.text).to.equal('reply by user 2') |
333 | expect(tree.children[0].children).to.have.lengthOf(1) | 333 | expect(tree.children[0].children).to.have.lengthOf(1) |
@@ -378,7 +378,7 @@ describe('Test blocklist', function () { | |||
378 | }) | 378 | }) |
379 | 379 | ||
380 | it('Should hide its videos', async function () { | 380 | it('Should hide its videos', async function () { |
381 | const { data } = await servers[0].videosCommand.listWithToken() | 381 | const { data } = await servers[0].videos.listWithToken() |
382 | 382 | ||
383 | expect(data).to.have.lengthOf(3) | 383 | expect(data).to.have.lengthOf(3) |
384 | 384 | ||
@@ -488,7 +488,7 @@ describe('Test blocklist', function () { | |||
488 | 488 | ||
489 | it('Should hide its videos', async function () { | 489 | it('Should hide its videos', async function () { |
490 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 490 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
491 | const { data } = await servers[0].videosCommand.listWithToken({ token }) | 491 | const { data } = await servers[0].videos.listWithToken({ token }) |
492 | 492 | ||
493 | expect(data).to.have.lengthOf(4) | 493 | expect(data).to.have.lengthOf(4) |
494 | 494 | ||
@@ -503,7 +503,7 @@ describe('Test blocklist', function () { | |||
503 | 503 | ||
504 | it('Should hide its videos', async function () { | 504 | it('Should hide its videos', async function () { |
505 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 505 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
506 | const { data } = await servers[0].videosCommand.listWithToken({ token }) | 506 | const { data } = await servers[0].videos.listWithToken({ token }) |
507 | 507 | ||
508 | expect(data).to.have.lengthOf(3) | 508 | expect(data).to.have.lengthOf(3) |
509 | 509 | ||
@@ -581,7 +581,7 @@ describe('Test blocklist', function () { | |||
581 | 581 | ||
582 | it('Should display its videos', async function () { | 582 | it('Should display its videos', async function () { |
583 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 583 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
584 | const { data } = await servers[0].videosCommand.listWithToken({ token }) | 584 | const { data } = await servers[0].videos.listWithToken({ token }) |
585 | expect(data).to.have.lengthOf(4) | 585 | expect(data).to.have.lengthOf(4) |
586 | 586 | ||
587 | const v = data.find(v => v.name === 'video user 2') | 587 | const v = data.find(v => v.name === 'video user 2') |
@@ -639,8 +639,8 @@ describe('Test blocklist', function () { | |||
639 | it('Should hide its videos', async function () { | 639 | it('Should hide its videos', async function () { |
640 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 640 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
641 | const requests = [ | 641 | const requests = [ |
642 | servers[0].videosCommand.list(), | 642 | servers[0].videos.list(), |
643 | servers[0].videosCommand.listWithToken({ token }) | 643 | servers[0].videos.listWithToken({ token }) |
644 | ] | 644 | ] |
645 | 645 | ||
646 | for (const req of requests) { | 646 | for (const req of requests) { |
@@ -688,13 +688,13 @@ describe('Test blocklist', function () { | |||
688 | 688 | ||
689 | { | 689 | { |
690 | const now = new Date() | 690 | const now = new Date() |
691 | await servers[1].followsCommand.unfollow({ target: servers[0] }) | 691 | await servers[1].follows.unfollow({ target: servers[0] }) |
692 | await waitJobs(servers) | 692 | await waitJobs(servers) |
693 | await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) | 693 | await servers[1].follows.follow({ targets: [ servers[0].host ] }) |
694 | 694 | ||
695 | await waitJobs(servers) | 695 | await waitJobs(servers) |
696 | 696 | ||
697 | const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) | 697 | const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) |
698 | const commentNotifications = data.filter(n => { | 698 | const commentNotifications = data.filter(n => { |
699 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() | 699 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() |
700 | }) | 700 | }) |
@@ -749,13 +749,13 @@ describe('Test blocklist', function () { | |||
749 | 749 | ||
750 | { | 750 | { |
751 | const now = new Date() | 751 | const now = new Date() |
752 | await servers[1].followsCommand.unfollow({ target: servers[0] }) | 752 | await servers[1].follows.unfollow({ target: servers[0] }) |
753 | await waitJobs(servers) | 753 | await waitJobs(servers) |
754 | await servers[1].followsCommand.follow({ targets: [ servers[0].host ] }) | 754 | await servers[1].follows.follow({ targets: [ servers[0].host ] }) |
755 | 755 | ||
756 | await waitJobs(servers) | 756 | await waitJobs(servers) |
757 | 757 | ||
758 | const { data } = await servers[0].notificationsCommand.list({ start: 0, count: 30 }) | 758 | const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) |
759 | const commentNotifications = data.filter(n => { | 759 | const commentNotifications = data.filter(n => { |
760 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() | 760 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() |
761 | }) | 761 | }) |