1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
13 getVideoCommentThreads,
15 getVideosListPagination,
16 getVideoThreadComments,
20 setAccessTokensToServers,
21 setDefaultVideoChannel,
25 } from '../../../shared/extra-utils'
26 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
27 import { VideoDetails } from '../../../shared/models/videos'
28 import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
29 import { ServerConfig } from '@shared/models'
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-thread.create.accept.result', async function () {
91 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403)
94 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
95 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
96 threadId = res.body.comment.id
98 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with bad word', 403)
99 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', 200)
102 it('Should run filter:api.video-threads.list.params', async function () {
103 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
105 // our plugin do +1 to the count parameter
106 expect(res.body.data).to.have.lengthOf(1)
109 it('Should run filter:api.video-threads.list.result', async function () {
110 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
112 // Plugin do +1 to the total result
113 expect(res.body.total).to.equal(2)
116 it('Should run filter:api.video-thread-comments.list.params')
118 it('Should run filter:api.video-thread-comments.list.result', async function () {
119 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
121 const thread = res.body as VideoCommentThreadTree
122 expect(thread.comment.text.endsWith(' <3')).to.be.true
125 describe('Should run filter:video.auto-blacklist.result', function () {
127 async function checkIsBlacklisted (oldRes: any, value: boolean) {
128 const videoId = oldRes.body.video.uuid
130 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
131 const video: VideoDetails = res.body
132 expect(video.blacklisted).to.equal(value)
135 it('Should blacklist on upload', async function () {
136 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
137 await checkIsBlacklisted(res, true)
140 it('Should blacklist on import', async function () {
144 name: 'video please blacklist me',
145 targetUrl: getYoutubeVideoUrl(),
146 channelId: servers[0].videoChannel.id
148 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
149 await checkIsBlacklisted(res, true)
152 it('Should blacklist on update', async function () {
153 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
154 const videoId = res.body.video.uuid
155 await checkIsBlacklisted(res, false)
157 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
158 await checkIsBlacklisted(res, true)
161 it('Should blacklist on remote upload', async function () {
164 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
165 await waitJobs(servers)
167 await checkIsBlacklisted(res, true)
170 it('Should blacklist on remote update', async function () {
173 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
174 await waitJobs(servers)
176 const videoId = res.body.video.uuid
177 await checkIsBlacklisted(res, false)
179 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
180 await waitJobs(servers)
182 await checkIsBlacklisted(res, true)
186 describe('Should run filter:api.user.signup.allowed.result', function () {
188 it('Should run on config endpoint', async function () {
189 const res = await getConfig(servers[0].url)
190 expect((res.body as ServerConfig).signup.allowed).to.be.true
193 it('Should allow a signup', async function () {
194 await registerUser(servers[0].url, 'john', 'password')
197 it('Should not allow a signup', async function () {
198 const res = await registerUser(servers[0].url, 'jma', 'password', 403)
200 expect(res.body.error).to.equal('No jma')
204 after(async function () {
205 await cleanupTests(servers)