diff options
Diffstat (limited to 'server/tests/external-plugins/auto-block-videos.ts')
-rw-r--r-- | server/tests/external-plugins/auto-block-videos.ts | 75 |
1 files changed, 28 insertions, 47 deletions
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts index 18ea17d78..0eb4bda9a 100644 --- a/server/tests/external-plugins/auto-block-videos.ts +++ b/server/tests/external-plugins/auto-block-videos.ts | |||
@@ -2,41 +2,29 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { Video, VideoBlacklist } from '@shared/models' | ||
6 | import { | 5 | import { |
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
7 | doubleFollow, | 8 | doubleFollow, |
8 | getBlacklistedVideosList, | 9 | killallServers, |
9 | getVideosList, | ||
10 | installPlugin, | ||
11 | MockBlocklist, | 10 | MockBlocklist, |
12 | removeVideoFromBlacklist, | 11 | PeerTubeServer, |
13 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
14 | updatePluginSettings, | ||
15 | uploadVideoAndGetId, | ||
16 | wait | 13 | wait |
17 | } from '../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
18 | import { | 15 | import { Video } from '@shared/models' |
19 | cleanupTests, | ||
20 | flushAndRunMultipleServers, | ||
21 | killallServers, | ||
22 | reRunServer, | ||
23 | ServerInfo | ||
24 | } from '../../../shared/extra-utils/server/servers' | ||
25 | 16 | ||
26 | async function check (server: ServerInfo, videoUUID: string, exists = true) { | 17 | async function check (server: PeerTubeServer, videoUUID: string, exists = true) { |
27 | const res = await getVideosList(server.url) | 18 | const { data } = await server.videos.list() |
28 | 19 | ||
29 | const video = res.body.data.find(v => v.uuid === videoUUID) | 20 | const video = data.find(v => v.uuid === videoUUID) |
30 | 21 | ||
31 | if (exists) { | 22 | if (exists) expect(video).to.not.be.undefined |
32 | expect(video).to.not.be.undefined | 23 | else expect(video).to.be.undefined |
33 | } else { | ||
34 | expect(video).to.be.undefined | ||
35 | } | ||
36 | } | 24 | } |
37 | 25 | ||
38 | describe('Official plugin auto-block videos', function () { | 26 | describe('Official plugin auto-block videos', function () { |
39 | let servers: ServerInfo[] | 27 | let servers: PeerTubeServer[] |
40 | let blocklistServer: MockBlocklist | 28 | let blocklistServer: MockBlocklist |
41 | let server1Videos: Video[] = [] | 29 | let server1Videos: Video[] = [] |
42 | let server2Videos: Video[] = [] | 30 | let server2Videos: Video[] = [] |
@@ -45,42 +33,36 @@ describe('Official plugin auto-block videos', function () { | |||
45 | before(async function () { | 33 | before(async function () { |
46 | this.timeout(60000) | 34 | this.timeout(60000) |
47 | 35 | ||
48 | servers = await flushAndRunMultipleServers(2) | 36 | servers = await createMultipleServers(2) |
49 | await setAccessTokensToServers(servers) | 37 | await setAccessTokensToServers(servers) |
50 | 38 | ||
51 | for (const server of servers) { | 39 | for (const server of servers) { |
52 | await installPlugin({ | 40 | await server.plugins.install({ npmName: 'peertube-plugin-auto-block-videos' }) |
53 | url: server.url, | ||
54 | accessToken: server.accessToken, | ||
55 | npmName: 'peertube-plugin-auto-block-videos' | ||
56 | }) | ||
57 | } | 41 | } |
58 | 42 | ||
59 | blocklistServer = new MockBlocklist() | 43 | blocklistServer = new MockBlocklist() |
60 | port = await blocklistServer.initialize() | 44 | port = await blocklistServer.initialize() |
61 | 45 | ||
62 | await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) | 46 | await servers[0].videos.quickUpload({ name: 'video server 1' }) |
63 | await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) | 47 | await servers[1].videos.quickUpload({ name: 'video server 2' }) |
64 | await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2 server 2' }) | 48 | await servers[1].videos.quickUpload({ name: 'video 2 server 2' }) |
65 | await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2' }) | 49 | await servers[1].videos.quickUpload({ name: 'video 3 server 2' }) |
66 | 50 | ||
67 | { | 51 | { |
68 | const res = await getVideosList(servers[0].url) | 52 | const { data } = await servers[0].videos.list() |
69 | server1Videos = res.body.data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) | 53 | server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid })) |
70 | } | 54 | } |
71 | 55 | ||
72 | { | 56 | { |
73 | const res = await getVideosList(servers[1].url) | 57 | const { data } = await servers[1].videos.list() |
74 | server2Videos = res.body.data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) | 58 | server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid })) |
75 | } | 59 | } |
76 | 60 | ||
77 | await doubleFollow(servers[0], servers[1]) | 61 | await doubleFollow(servers[0], servers[1]) |
78 | }) | 62 | }) |
79 | 63 | ||
80 | it('Should update plugin settings', async function () { | 64 | it('Should update plugin settings', async function () { |
81 | await updatePluginSettings({ | 65 | await servers[0].plugins.updateSettings({ |
82 | url: servers[0].url, | ||
83 | accessToken: servers[0].accessToken, | ||
84 | npmName: 'peertube-plugin-auto-block-videos', | 66 | npmName: 'peertube-plugin-auto-block-videos', |
85 | settings: { | 67 | settings: { |
86 | 'blocklist-urls': `http://localhost:${port}/blocklist`, | 68 | 'blocklist-urls': `http://localhost:${port}/blocklist`, |
@@ -108,10 +90,9 @@ describe('Official plugin auto-block videos', function () { | |||
108 | }) | 90 | }) |
109 | 91 | ||
110 | it('Should have video in blacklists', async function () { | 92 | it('Should have video in blacklists', async function () { |
111 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) | 93 | const body = await servers[0].blacklist.list() |
112 | |||
113 | const videoBlacklists = res.body.data as VideoBlacklist[] | ||
114 | 94 | ||
95 | const videoBlacklists = body.data | ||
115 | expect(videoBlacklists).to.have.lengthOf(1) | 96 | expect(videoBlacklists).to.have.lengthOf(1) |
116 | expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin') | 97 | expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin') |
117 | expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name) | 98 | expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name) |
@@ -174,12 +155,12 @@ describe('Official plugin auto-block videos', function () { | |||
174 | 155 | ||
175 | await check(servers[0], video.uuid, false) | 156 | await check(servers[0], video.uuid, false) |
176 | 157 | ||
177 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video.uuid) | 158 | await servers[0].blacklist.remove({ videoId: video.uuid }) |
178 | 159 | ||
179 | await check(servers[0], video.uuid, true) | 160 | await check(servers[0], video.uuid, true) |
180 | 161 | ||
181 | killallServers([ servers[0] ]) | 162 | await killallServers([ servers[0] ]) |
182 | await reRunServer(servers[0]) | 163 | await servers[0].run() |
183 | await wait(2000) | 164 | await wait(2000) |
184 | 165 | ||
185 | await check(servers[0], video.uuid, true) | 166 | await check(servers[0], video.uuid, true) |