1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { ServerConfig } from '@shared/models'
13 getVideoCommentThreads,
15 getVideosListPagination,
16 getVideoThreadComments,
20 setAccessTokensToServers,
21 setDefaultVideoChannel,
25 } from '../../../shared/extra-utils'
26 import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
27 import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
28 import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos'
29 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
31 const expect = chai.expect
33 describe('Test plugin filter hooks', function () {
34 let servers: ServerInfo[]
38 before(async function () {
41 servers = await flushAndRunMultipleServers(2)
42 await setAccessTokensToServers(servers)
43 await setDefaultVideoChannel(servers)
44 await doubleFollow(servers[0], servers[1])
48 accessToken: servers[0].accessToken,
49 path: getPluginTestPath()
54 accessToken: servers[0].accessToken,
55 path: getPluginTestPath('-two')
58 for (let i = 0; i < 10; i++) {
59 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
62 const res = await getVideosList(servers[0].url)
63 videoUUID = res.body.data[0].uuid
66 it('Should run filter:api.videos.list.params', async function () {
67 const res = await getVideosListPagination(servers[0].url, 0, 2)
69 // 2 plugins do +1 to the count parameter
70 expect(res.body.data).to.have.lengthOf(4)
73 it('Should run filter:api.videos.list.result', async function () {
74 const res = await getVideosListPagination(servers[0].url, 0, 0)
76 // Plugin do +1 to the total result
77 expect(res.body.total).to.equal(11)
80 it('Should run filter:api.video.get.result', async function () {
81 const res = await getVideo(servers[0].url, videoUUID)
83 expect(res.body.name).to.contain('<3')
86 it('Should run filter:api.video.upload.accept.result', async function () {
87 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403)
90 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
91 const baseAttributes = {
93 privacy: VideoPrivacy.PUBLIC,
94 channelId: servers[0].videoChannel.id,
95 targetUrl: getGoodVideoUrl() + 'bad'
97 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403)
100 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
101 const baseAttributes = {
103 privacy: VideoPrivacy.PUBLIC,
104 channelId: servers[0].videoChannel.id,
105 torrentfile: 'video-720p.torrent' as any
107 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403)
110 it('Should run filter:api.video.post-import-url.accept.result', async function () {
113 let videoImportId: number
116 const baseAttributes = {
117 name: 'title with bad word',
118 privacy: VideoPrivacy.PUBLIC,
119 channelId: servers[0].videoChannel.id,
120 targetUrl: getGoodVideoUrl()
122 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
123 videoImportId = res.body.id
126 await waitJobs(servers)
129 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
130 const videoImports = res.body.data as VideoImport[]
132 const videoImport = videoImports.find(i => i.id === videoImportId)
134 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
135 expect(videoImport.state.label).to.equal('Rejected')
139 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
142 let videoImportId: number
145 const baseAttributes = {
146 name: 'title with bad word',
147 privacy: VideoPrivacy.PUBLIC,
148 channelId: servers[0].videoChannel.id,
149 torrentfile: 'video-720p.torrent' as any
151 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
152 videoImportId = res.body.id
155 await waitJobs(servers)
158 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
159 const videoImports = res.body.data as VideoImport[]
161 const videoImport = videoImports.find(i => i.id === videoImportId)
163 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
164 expect(videoImport.state.label).to.equal('Rejected')
168 it('Should run filter:api.video-thread.create.accept.result', async function () {
169 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403)
172 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
173 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
174 threadId = res.body.comment.id
176 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with bad word', 403)
177 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', 200)
180 it('Should run filter:api.video-threads.list.params', async function () {
181 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
183 // our plugin do +1 to the count parameter
184 expect(res.body.data).to.have.lengthOf(1)
187 it('Should run filter:api.video-threads.list.result', async function () {
188 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
190 // Plugin do +1 to the total result
191 expect(res.body.total).to.equal(2)
194 it('Should run filter:api.video-thread-comments.list.params')
196 it('Should run filter:api.video-thread-comments.list.result', async function () {
197 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
199 const thread = res.body as VideoCommentThreadTree
200 expect(thread.comment.text.endsWith(' <3')).to.be.true
203 describe('Should run filter:video.auto-blacklist.result', function () {
205 async function checkIsBlacklisted (oldRes: any, value: boolean) {
206 const videoId = oldRes.body.video.uuid
208 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
209 const video: VideoDetails = res.body
210 expect(video.blacklisted).to.equal(value)
213 it('Should blacklist on upload', async function () {
214 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
215 await checkIsBlacklisted(res, true)
218 it('Should blacklist on import', async function () {
222 name: 'video please blacklist me',
223 targetUrl: getGoodVideoUrl(),
224 channelId: servers[0].videoChannel.id
226 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
227 await checkIsBlacklisted(res, true)
230 it('Should blacklist on update', async function () {
231 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
232 const videoId = res.body.video.uuid
233 await checkIsBlacklisted(res, false)
235 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
236 await checkIsBlacklisted(res, true)
239 it('Should blacklist on remote upload', async function () {
242 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
243 await waitJobs(servers)
245 await checkIsBlacklisted(res, true)
248 it('Should blacklist on remote update', async function () {
251 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
252 await waitJobs(servers)
254 const videoId = res.body.video.uuid
255 await checkIsBlacklisted(res, false)
257 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
258 await waitJobs(servers)
260 await checkIsBlacklisted(res, true)
264 describe('Should run filter:api.user.signup.allowed.result', function () {
266 it('Should run on config endpoint', async function () {
267 const res = await getConfig(servers[0].url)
268 expect((res.body as ServerConfig).signup.allowed).to.be.true
271 it('Should allow a signup', async function () {
272 await registerUser(servers[0].url, 'john', 'password')
275 it('Should not allow a signup', async function () {
276 const res = await registerUser(servers[0].url, 'jma', 'password', 403)
278 expect(res.body.error).to.equal('No jma')
282 after(async function () {
283 await cleanupTests(servers)