1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
7 flushAndRunMultipleServers,
8 flushAndRunServer, killallServers, reRunServer,
11 } from '../../../shared/extra-utils/server/servers'
14 addVideoCommentThread,
20 setAccessTokensToServers,
24 getVideosListPagination,
26 getVideoCommentThreads,
27 getVideoThreadComments,
29 setDefaultVideoChannel,
32 } from '../../../shared/extra-utils'
33 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
34 import { VideoDetails } from '../../../shared/models/videos'
35 import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
37 const expect = chai.expect
39 describe('Test plugin filter hooks', function () {
40 let servers: ServerInfo[]
44 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
50 await doubleFollow(servers[0], servers[1])
54 accessToken: servers[0].accessToken,
55 path: getPluginTestPath()
60 accessToken: servers[0].accessToken,
61 path: getPluginTestPath('-two')
64 for (let i = 0; i < 10; i++) {
65 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
68 const res = await getVideosList(servers[0].url)
69 videoUUID = res.body.data[0].uuid
72 it('Should run filter:api.videos.list.params', async function () {
73 const res = await getVideosListPagination(servers[0].url, 0, 2)
75 // 2 plugins do +1 to the count parameter
76 expect(res.body.data).to.have.lengthOf(4)
79 it('Should run filter:api.videos.list.result', async function () {
80 const res = await getVideosListPagination(servers[0].url, 0, 0)
82 // Plugin do +1 to the total result
83 expect(res.body.total).to.equal(11)
86 it('Should run filter:api.video.get.result', async function () {
87 const res = await getVideo(servers[0].url, videoUUID)
89 expect(res.body.name).to.contain('<3')
92 it('Should run filter:api.video.upload.accept.result', async function () {
93 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403)
96 it('Should run filter:api.video-thread.create.accept.result', async function () {
97 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403)
100 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
101 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
102 threadId = res.body.comment.id
104 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with bad word', 403)
105 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', 200)
108 it('Should run filter:api.video-threads.list.params', async function () {
109 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
111 // our plugin do +1 to the count parameter
112 expect(res.body.data).to.have.lengthOf(1)
115 it('Should run filter:api.video-threads.list.result', async function () {
116 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
118 // Plugin do +1 to the total result
119 expect(res.body.total).to.equal(2)
122 it('Should run filter:api.video-thread-comments.list.params')
124 it('Should run filter:api.video-thread-comments.list.result', async function () {
125 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
127 const thread = res.body as VideoCommentThreadTree
128 expect(thread.comment.text.endsWith(' <3')).to.be.true
131 describe('Should run filter:video.auto-blacklist.result', function () {
133 async function checkIsBlacklisted (oldRes: any, value: boolean) {
134 const videoId = oldRes.body.video.uuid
136 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
137 const video: VideoDetails = res.body
138 expect(video.blacklisted).to.equal(value)
141 it('Should blacklist on upload', async function () {
142 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video please blacklist me' })
143 await checkIsBlacklisted(res, true)
146 it('Should blacklist on import', async function () {
148 name: 'video please blacklist me',
149 targetUrl: getYoutubeVideoUrl(),
150 channelId: servers[0].videoChannel.id
152 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
153 await checkIsBlacklisted(res, true)
156 it('Should blacklist on update', async function () {
157 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video' })
158 const videoId = res.body.video.uuid
159 await checkIsBlacklisted(res, false)
161 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, { name: 'please blacklist me' })
162 await checkIsBlacklisted(res, true)
165 it('Should blacklist on remote upload', async function () {
168 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'remote please blacklist me' })
169 await waitJobs(servers)
171 await checkIsBlacklisted(res, true)
174 it('Should blacklist on remote update', async function () {
177 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video' })
178 await waitJobs(servers)
180 const videoId = res.body.video.uuid
181 await checkIsBlacklisted(res, false)
183 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
184 await waitJobs(servers)
186 await checkIsBlacklisted(res, true)
190 after(async function () {
191 await cleanupTests(servers)