diff options
Diffstat (limited to 'server/tests/plugins')
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 123 |
1 files changed, 118 insertions, 5 deletions
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 4fc2c437b..ec0679b04 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -11,15 +11,28 @@ import { | |||
11 | } from '../../../shared/extra-utils/server/servers' | 11 | } from '../../../shared/extra-utils/server/servers' |
12 | import { | 12 | import { |
13 | addVideoCommentReply, | 13 | addVideoCommentReply, |
14 | addVideoCommentThread, deleteVideoComment, | 14 | addVideoCommentThread, |
15 | getPluginTestPath, getVideosList, | 15 | deleteVideoComment, |
16 | installPlugin, removeVideo, | 16 | getPluginTestPath, |
17 | getVideosList, | ||
18 | installPlugin, | ||
19 | removeVideo, | ||
17 | setAccessTokensToServers, | 20 | setAccessTokensToServers, |
18 | updateVideo, | 21 | updateVideo, |
19 | uploadVideo, | 22 | uploadVideo, |
20 | viewVideo, | 23 | viewVideo, |
21 | getVideosListPagination, getVideo | 24 | getVideosListPagination, |
25 | getVideo, | ||
26 | getVideoCommentThreads, | ||
27 | getVideoThreadComments, | ||
28 | getVideoWithToken, | ||
29 | setDefaultVideoChannel, | ||
30 | waitJobs, | ||
31 | doubleFollow | ||
22 | } from '../../../shared/extra-utils' | 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' | ||
23 | 36 | ||
24 | const expect = chai.expect | 37 | const expect = chai.expect |
25 | 38 | ||
@@ -33,6 +46,8 @@ describe('Test plugin filter hooks', function () { | |||
33 | 46 | ||
34 | servers = await flushAndRunMultipleServers(2) | 47 | servers = await flushAndRunMultipleServers(2) |
35 | await setAccessTokensToServers(servers) | 48 | await setAccessTokensToServers(servers) |
49 | await setDefaultVideoChannel(servers) | ||
50 | await doubleFollow(servers[0], servers[1]) | ||
36 | 51 | ||
37 | await installPlugin({ | 52 | await installPlugin({ |
38 | url: servers[0].url, | 53 | url: servers[0].url, |
@@ -54,7 +69,7 @@ describe('Test plugin filter hooks', function () { | |||
54 | videoUUID = res.body.data[0].uuid | 69 | videoUUID = res.body.data[0].uuid |
55 | }) | 70 | }) |
56 | 71 | ||
57 | it('Should run filter:api.videos.list.params hook', async function () { | 72 | it('Should run filter:api.videos.list.params', async function () { |
58 | const res = await getVideosListPagination(servers[0].url, 0, 2) | 73 | const res = await getVideosListPagination(servers[0].url, 0, 2) |
59 | 74 | ||
60 | // 2 plugins do +1 to the count parameter | 75 | // 2 plugins do +1 to the count parameter |
@@ -74,6 +89,104 @@ describe('Test plugin filter hooks', function () { | |||
74 | expect(res.body.name).to.contain('<3') | 89 | expect(res.body.name).to.contain('<3') |
75 | }) | 90 | }) |
76 | 91 | ||
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) | ||
94 | }) | ||
95 | |||
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) | ||
98 | }) | ||
99 | |||
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 | ||
103 | |||
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) | ||
106 | }) | ||
107 | |||
108 | it('Should run filter:api.video-threads.list.params', async function () { | ||
109 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | ||
110 | |||
111 | // our plugin do +1 to the count parameter | ||
112 | expect(res.body.data).to.have.lengthOf(1) | ||
113 | }) | ||
114 | |||
115 | it('Should run filter:api.video-threads.list.result', async function () { | ||
116 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | ||
117 | |||
118 | // Plugin do +1 to the total result | ||
119 | expect(res.body.total).to.equal(2) | ||
120 | }) | ||
121 | |||
122 | it('Should run filter:api.video-thread-comments.list.params') | ||
123 | |||
124 | it('Should run filter:api.video-thread-comments.list.result', async function () { | ||
125 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | ||
126 | |||
127 | const thread = res.body as VideoCommentThreadTree | ||
128 | expect(thread.comment.text.endsWith(' <3')).to.be.true | ||
129 | }) | ||
130 | |||
131 | describe('Should run filter:video.auto-blacklist.result', function () { | ||
132 | |||
133 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | ||
134 | const videoId = oldRes.body.video.uuid | ||
135 | |||
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) | ||
139 | } | ||
140 | |||
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) | ||
144 | }) | ||
145 | |||
146 | it('Should blacklist on import', async function () { | ||
147 | const attributes = { | ||
148 | name: 'video please blacklist me', | ||
149 | targetUrl: getYoutubeVideoUrl(), | ||
150 | channelId: servers[0].videoChannel.id | ||
151 | } | ||
152 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | ||
153 | await checkIsBlacklisted(res, true) | ||
154 | }) | ||
155 | |||
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) | ||
160 | |||
161 | await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, { name: 'please blacklist me' }) | ||
162 | await checkIsBlacklisted(res, true) | ||
163 | }) | ||
164 | |||
165 | it('Should blacklist on remote upload', async function () { | ||
166 | this.timeout(45000) | ||
167 | |||
168 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'remote please blacklist me' }) | ||
169 | await waitJobs(servers) | ||
170 | |||
171 | await checkIsBlacklisted(res, true) | ||
172 | }) | ||
173 | |||
174 | it('Should blacklist on remote update', async function () { | ||
175 | this.timeout(45000) | ||
176 | |||
177 | const res = await uploadVideo(servers[ 1 ].url, servers[ 1 ].accessToken, { name: 'video' }) | ||
178 | await waitJobs(servers) | ||
179 | |||
180 | const videoId = res.body.video.uuid | ||
181 | await checkIsBlacklisted(res, false) | ||
182 | |||
183 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | ||
184 | await waitJobs(servers) | ||
185 | |||
186 | await checkIsBlacklisted(res, true) | ||
187 | }) | ||
188 | }) | ||
189 | |||
77 | after(async function () { | 190 | after(async function () { |
78 | await cleanupTests(servers) | 191 | await cleanupTests(servers) |
79 | }) | 192 | }) |