aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/external-plugins/auto-block-videos.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/external-plugins/auto-block-videos.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/external-plugins/auto-block-videos.ts')
-rw-r--r--server/tests/external-plugins/auto-block-videos.ts167
1 files changed, 0 insertions, 167 deletions
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts
deleted file mode 100644
index 95d7a4b58..000000000
--- a/server/tests/external-plugins/auto-block-videos.ts
+++ /dev/null
@@ -1,167 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import { wait } from '@shared/core-utils'
5import { Video } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/server-commands'
14import { MockBlocklist } from '../shared'
15
16async function check (server: PeerTubeServer, videoUUID: string, exists = true) {
17 const { data } = await server.videos.list()
18
19 const video = data.find(v => v.uuid === videoUUID)
20
21 if (exists) expect(video).to.not.be.undefined
22 else expect(video).to.be.undefined
23}
24
25describe('Official plugin auto-block videos', function () {
26 let servers: PeerTubeServer[]
27 let blocklistServer: MockBlocklist
28 let server1Videos: Video[] = []
29 let server2Videos: Video[] = []
30 let port: number
31
32 before(async function () {
33 this.timeout(120000)
34
35 servers = await createMultipleServers(2)
36 await setAccessTokensToServers(servers)
37
38 for (const server of servers) {
39 await server.plugins.install({ npmName: 'peertube-plugin-auto-block-videos' })
40 }
41
42 blocklistServer = new MockBlocklist()
43 port = await blocklistServer.initialize()
44
45 await servers[0].videos.quickUpload({ name: 'video server 1' })
46 await servers[1].videos.quickUpload({ name: 'video server 2' })
47 await servers[1].videos.quickUpload({ name: 'video 2 server 2' })
48 await servers[1].videos.quickUpload({ name: 'video 3 server 2' })
49
50 {
51 const { data } = await servers[0].videos.list()
52 server1Videos = data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
53 }
54
55 {
56 const { data } = await servers[1].videos.list()
57 server2Videos = data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
58 }
59
60 await doubleFollow(servers[0], servers[1])
61 })
62
63 it('Should update plugin settings', async function () {
64 await servers[0].plugins.updateSettings({
65 npmName: 'peertube-plugin-auto-block-videos',
66 settings: {
67 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
68 'check-seconds-interval': 1
69 }
70 })
71 })
72
73 it('Should auto block a video', async function () {
74 await check(servers[0], server2Videos[0].uuid, true)
75
76 blocklistServer.replace({
77 data: [
78 {
79 value: server2Videos[0].url
80 }
81 ]
82 })
83
84 await wait(2000)
85
86 await check(servers[0], server2Videos[0].uuid, false)
87 })
88
89 it('Should have video in blacklists', async function () {
90 const body = await servers[0].blacklist.list()
91
92 const videoBlacklists = body.data
93 expect(videoBlacklists).to.have.lengthOf(1)
94 expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin')
95 expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name)
96 })
97
98 it('Should not block a local video', async function () {
99 await check(servers[0], server1Videos[0].uuid, true)
100
101 blocklistServer.replace({
102 data: [
103 {
104 value: server1Videos[0].url
105 }
106 ]
107 })
108
109 await wait(2000)
110
111 await check(servers[0], server1Videos[0].uuid, true)
112 })
113
114 it('Should remove a video block', async function () {
115 await check(servers[0], server2Videos[0].uuid, false)
116
117 blocklistServer.replace({
118 data: [
119 {
120 value: server2Videos[0].url,
121 action: 'remove'
122 }
123 ]
124 })
125
126 await wait(2000)
127
128 await check(servers[0], server2Videos[0].uuid, true)
129 })
130
131 it('Should auto block a video, manually unblock it and do not reblock it automatically', async function () {
132 this.timeout(20000)
133
134 const video = server2Videos[1]
135
136 await check(servers[0], video.uuid, true)
137
138 blocklistServer.replace({
139 data: [
140 {
141 value: video.url,
142 updatedAt: new Date().toISOString()
143 }
144 ]
145 })
146
147 await wait(2000)
148
149 await check(servers[0], video.uuid, false)
150
151 await servers[0].blacklist.remove({ videoId: video.uuid })
152
153 await check(servers[0], video.uuid, true)
154
155 await killallServers([ servers[0] ])
156 await servers[0].run()
157 await wait(2000)
158
159 await check(servers[0], video.uuid, true)
160 })
161
162 after(async function () {
163 await blocklistServer.terminate()
164
165 await cleanupTests(servers)
166 })
167})