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,
31 doubleFollow, getConfig, registerUser
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'
36 import { ServerConfig } from '@shared/models'
38 const expect = chai.expect
40 describe('Test plugin filter hooks', function () {
41 let servers: ServerInfo[]
45 before(async function () {
48 servers = await flushAndRunMultipleServers(2)
49 await setAccessTokensToServers(servers)
50 await setDefaultVideoChannel(servers)
51 await doubleFollow(servers[0], servers[1])
55 accessToken: servers[0].accessToken,
56 path: getPluginTestPath()
61 accessToken: servers[0].accessToken,
62 path: getPluginTestPath('-two')
65 for (let i = 0; i < 10; i++) {
66 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
69 const res = await getVideosList(servers[0].url)
70 videoUUID = res.body.data[0].uuid
73 it('Should run filter:api.videos.list.params', async function () {
74 const res = await getVideosListPagination(servers[0].url, 0, 2)
76 // 2 plugins do +1 to the count parameter
77 expect(res.body.data).to.have.lengthOf(4)
80 it('Should run filter:api.videos.list.result', async function () {
81 const res = await getVideosListPagination(servers[0].url, 0, 0)
83 // Plugin do +1 to the total result
84 expect(res.body.total).to.equal(11)
87 it('Should run filter:api.video.get.result', async function () {
88 const res = await getVideo(servers[0].url, videoUUID)
90 expect(res.body.name).to.contain('<3')
93 it('Should run filter:api.video.upload.accept.result', async function () {
94 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403)
97 it('Should run filter:api.video-thread.create.accept.result', async function () {
98 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403)
101 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
102 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
103 threadId = res.body.comment.id
105 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with bad word', 403)
106 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', 200)
109 it('Should run filter:api.video-threads.list.params', async function () {
110 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
112 // our plugin do +1 to the count parameter
113 expect(res.body.data).to.have.lengthOf(1)
116 it('Should run filter:api.video-threads.list.result', async function () {
117 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
119 // Plugin do +1 to the total result
120 expect(res.body.total).to.equal(2)
123 it('Should run filter:api.video-thread-comments.list.params')
125 it('Should run filter:api.video-thread-comments.list.result', async function () {
126 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
128 const thread = res.body as VideoCommentThreadTree
129 expect(thread.comment.text.endsWith(' <3')).to.be.true
132 describe('Should run filter:video.auto-blacklist.result', function () {
134 async function checkIsBlacklisted (oldRes: any, value: boolean) {
135 const videoId = oldRes.body.video.uuid
137 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
138 const video: VideoDetails = res.body
139 expect(video.blacklisted).to.equal(value)
142 it('Should blacklist on upload', async function () {
143 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video please blacklist me' })
144 await checkIsBlacklisted(res, true)
147 it('Should blacklist on import', async function () {
149 name: 'video please blacklist me',
150 targetUrl: getYoutubeVideoUrl(),
151 channelId: servers[0].videoChannel.id
153 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
154 await checkIsBlacklisted(res, true)
157 it('Should blacklist on update', async function () {
158 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'video' })
159 const videoId = res.body.video.uuid
160 await checkIsBlacklisted(res, false)
162 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, { name: 'please blacklist me' })
163 await checkIsBlacklisted(res, true)
166 it('Should blacklist on remote upload', async function () {
169 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'remote please blacklist me' })
170 await waitJobs(servers)
172 await checkIsBlacklisted(res, true)
175 it('Should blacklist on remote update', async function () {
178 const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video' })
179 await waitJobs(servers)
181 const videoId = res.body.video.uuid
182 await checkIsBlacklisted(res, false)
184 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
185 await waitJobs(servers)
187 await checkIsBlacklisted(res, true)
191 describe('Should run filter:api.user.signup.allowed.result', function () {
193 it('Should run on config endpoint', async function () {
194 const res = await getConfig(servers[0].url)
195 expect((res.body as ServerConfig).signup.allowed).to.be.true
198 it('Should allow a signup', async function () {
199 await registerUser(servers[0].url, 'john', 'password')
202 it('Should not allow a signup', async function () {
203 const res = await registerUser(servers[0].url, 'jma', 'password', 403)
205 expect(res.body.error).to.equal('No jma')
209 after(async function () {
210 await cleanupTests(servers)