]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 | 2 | |
9b474844 | 3 | import 'mocha' |
2158ac90 RK |
4 | import * as chai from 'chai' |
5 | import { ServerConfig } from '@shared/models' | |
89cd1275 C |
6 | import { |
7 | addVideoCommentReply, | |
6691c522 | 8 | addVideoCommentThread, |
a1587156 C |
9 | doubleFollow, |
10 | getConfig, | |
6691c522 | 11 | getPluginTestPath, |
6691c522 C |
12 | getVideo, |
13 | getVideoCommentThreads, | |
a1587156 C |
14 | getVideosList, |
15 | getVideosListPagination, | |
6691c522 C |
16 | getVideoThreadComments, |
17 | getVideoWithToken, | |
a1587156 C |
18 | installPlugin, |
19 | registerUser, | |
20 | setAccessTokensToServers, | |
6691c522 | 21 | setDefaultVideoChannel, |
a1587156 C |
22 | updateVideo, |
23 | uploadVideo, | |
24 | waitJobs | |
89cd1275 | 25 | } from '../../../shared/extra-utils' |
2158ac90 | 26 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' |
b488ba1e | 27 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' |
2158ac90 | 28 | import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' |
6691c522 | 29 | import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' |
9b474844 C |
30 | |
31 | const expect = chai.expect | |
32 | ||
33 | describe('Test plugin filter hooks', function () { | |
89cd1275 C |
34 | let servers: ServerInfo[] |
35 | let videoUUID: string | |
36 | let threadId: number | |
9b474844 C |
37 | |
38 | before(async function () { | |
39 | this.timeout(30000) | |
9b474844 | 40 | |
89cd1275 C |
41 | servers = await flushAndRunMultipleServers(2) |
42 | await setAccessTokensToServers(servers) | |
6691c522 C |
43 | await setDefaultVideoChannel(servers) |
44 | await doubleFollow(servers[0], servers[1]) | |
89cd1275 C |
45 | |
46 | await installPlugin({ | |
47 | url: servers[0].url, | |
48 | accessToken: servers[0].accessToken, | |
49 | path: getPluginTestPath() | |
50 | }) | |
51 | ||
52 | await installPlugin({ | |
53 | url: servers[0].url, | |
54 | accessToken: servers[0].accessToken, | |
55 | path: getPluginTestPath('-two') | |
56 | }) | |
57 | ||
58 | for (let i = 0; i < 10; i++) { | |
59 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | |
60 | } | |
61 | ||
62 | const res = await getVideosList(servers[0].url) | |
63 | videoUUID = res.body.data[0].uuid | |
9b474844 C |
64 | }) |
65 | ||
6691c522 | 66 | it('Should run filter:api.videos.list.params', async function () { |
89cd1275 C |
67 | const res = await getVideosListPagination(servers[0].url, 0, 2) |
68 | ||
69 | // 2 plugins do +1 to the count parameter | |
70 | expect(res.body.data).to.have.lengthOf(4) | |
71 | }) | |
72 | ||
73 | it('Should run filter:api.videos.list.result', async function () { | |
74 | const res = await getVideosListPagination(servers[0].url, 0, 0) | |
75 | ||
76 | // Plugin do +1 to the total result | |
77 | expect(res.body.total).to.equal(11) | |
78 | }) | |
79 | ||
80 | it('Should run filter:api.video.get.result', async function () { | |
81 | const res = await getVideo(servers[0].url, videoUUID) | |
82 | ||
83 | expect(res.body.name).to.contain('<3') | |
9b474844 C |
84 | }) |
85 | ||
6691c522 C |
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) | |
88 | }) | |
89 | ||
2158ac90 RK |
90 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
91 | const baseAttributes = { | |
92 | name: 'normal title', | |
93 | privacy: VideoPrivacy.PUBLIC, | |
94 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 95 | targetUrl: getGoodVideoUrl() + 'bad' |
2158ac90 RK |
96 | } |
97 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) | |
98 | }) | |
99 | ||
100 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | |
101 | const baseAttributes = { | |
102 | name: 'bad torrent', | |
103 | privacy: VideoPrivacy.PUBLIC, | |
104 | channelId: servers[0].videoChannel.id, | |
105 | torrentfile: 'video-720p.torrent' as any | |
106 | } | |
107 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) | |
108 | }) | |
109 | ||
110 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | |
111 | this.timeout(60000) | |
112 | ||
113 | let videoImportId: number | |
114 | ||
115 | { | |
116 | const baseAttributes = { | |
117 | name: 'title with bad word', | |
118 | privacy: VideoPrivacy.PUBLIC, | |
119 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 120 | targetUrl: getGoodVideoUrl() |
2158ac90 RK |
121 | } |
122 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
123 | videoImportId = res.body.id | |
124 | } | |
125 | ||
126 | await waitJobs(servers) | |
127 | ||
128 | { | |
129 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
130 | const videoImports = res.body.data as VideoImport[] | |
131 | ||
132 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
133 | ||
134 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
135 | expect(videoImport.state.label).to.equal('Rejected') | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should run filter:api.video.post-import-torrent.accept.result', async function () { | |
140 | this.timeout(60000) | |
141 | ||
142 | let videoImportId: number | |
143 | ||
144 | { | |
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 | |
150 | } | |
151 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
152 | videoImportId = res.body.id | |
153 | } | |
154 | ||
155 | await waitJobs(servers) | |
156 | ||
157 | { | |
158 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
159 | const videoImports = res.body.data as VideoImport[] | |
160 | ||
161 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
162 | ||
163 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
164 | expect(videoImport.state.label).to.equal('Rejected') | |
165 | } | |
166 | }) | |
167 | ||
6691c522 C |
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) | |
170 | }) | |
171 | ||
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 | |
175 | ||
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) | |
178 | }) | |
179 | ||
180 | it('Should run filter:api.video-threads.list.params', async function () { | |
181 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
182 | ||
183 | // our plugin do +1 to the count parameter | |
184 | expect(res.body.data).to.have.lengthOf(1) | |
185 | }) | |
186 | ||
187 | it('Should run filter:api.video-threads.list.result', async function () { | |
188 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
189 | ||
190 | // Plugin do +1 to the total result | |
191 | expect(res.body.total).to.equal(2) | |
192 | }) | |
193 | ||
194 | it('Should run filter:api.video-thread-comments.list.params') | |
195 | ||
196 | it('Should run filter:api.video-thread-comments.list.result', async function () { | |
197 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | |
198 | ||
199 | const thread = res.body as VideoCommentThreadTree | |
200 | expect(thread.comment.text.endsWith(' <3')).to.be.true | |
201 | }) | |
202 | ||
203 | describe('Should run filter:video.auto-blacklist.result', function () { | |
204 | ||
205 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | |
206 | const videoId = oldRes.body.video.uuid | |
207 | ||
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) | |
211 | } | |
212 | ||
213 | it('Should blacklist on upload', async function () { | |
a1587156 | 214 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
6691c522 C |
215 | await checkIsBlacklisted(res, true) |
216 | }) | |
217 | ||
218 | it('Should blacklist on import', async function () { | |
89566f77 C |
219 | this.timeout(15000) |
220 | ||
6691c522 C |
221 | const attributes = { |
222 | name: 'video please blacklist me', | |
b488ba1e | 223 | targetUrl: getGoodVideoUrl(), |
6691c522 C |
224 | channelId: servers[0].videoChannel.id |
225 | } | |
226 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
227 | await checkIsBlacklisted(res, true) | |
228 | }) | |
229 | ||
230 | it('Should blacklist on update', async function () { | |
a1587156 | 231 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
6691c522 C |
232 | const videoId = res.body.video.uuid |
233 | await checkIsBlacklisted(res, false) | |
234 | ||
a1587156 | 235 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
6691c522 C |
236 | await checkIsBlacklisted(res, true) |
237 | }) | |
238 | ||
239 | it('Should blacklist on remote upload', async function () { | |
240 | this.timeout(45000) | |
241 | ||
a1587156 | 242 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
6691c522 C |
243 | await waitJobs(servers) |
244 | ||
245 | await checkIsBlacklisted(res, true) | |
246 | }) | |
247 | ||
248 | it('Should blacklist on remote update', async function () { | |
249 | this.timeout(45000) | |
250 | ||
a1587156 | 251 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) |
6691c522 C |
252 | await waitJobs(servers) |
253 | ||
254 | const videoId = res.body.video.uuid | |
255 | await checkIsBlacklisted(res, false) | |
256 | ||
257 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | |
258 | await waitJobs(servers) | |
259 | ||
260 | await checkIsBlacklisted(res, true) | |
261 | }) | |
262 | }) | |
263 | ||
4ce7eb71 C |
264 | describe('Should run filter:api.user.signup.allowed.result', function () { |
265 | ||
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 | |
269 | }) | |
270 | ||
271 | it('Should allow a signup', async function () { | |
272 | await registerUser(servers[0].url, 'john', 'password') | |
273 | }) | |
274 | ||
275 | it('Should not allow a signup', async function () { | |
276 | const res = await registerUser(servers[0].url, 'jma', 'password', 403) | |
277 | ||
278 | expect(res.body.error).to.equal('No jma') | |
279 | }) | |
280 | }) | |
281 | ||
9b474844 | 282 | after(async function () { |
89cd1275 | 283 | await cleanupTests(servers) |
9b474844 C |
284 | }) |
285 | }) |