]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
a1587156 | 5 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' |
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' |
6691c522 C |
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' | |
4ce7eb71 | 29 | import { ServerConfig } from '@shared/models' |
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 | ||
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) | |
92 | }) | |
93 | ||
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 | |
97 | ||
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) | |
100 | }) | |
101 | ||
102 | it('Should run filter:api.video-threads.list.params', async function () { | |
103 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
104 | ||
105 | // our plugin do +1 to the count parameter | |
106 | expect(res.body.data).to.have.lengthOf(1) | |
107 | }) | |
108 | ||
109 | it('Should run filter:api.video-threads.list.result', async function () { | |
110 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
111 | ||
112 | // Plugin do +1 to the total result | |
113 | expect(res.body.total).to.equal(2) | |
114 | }) | |
115 | ||
116 | it('Should run filter:api.video-thread-comments.list.params') | |
117 | ||
118 | it('Should run filter:api.video-thread-comments.list.result', async function () { | |
119 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | |
120 | ||
121 | const thread = res.body as VideoCommentThreadTree | |
122 | expect(thread.comment.text.endsWith(' <3')).to.be.true | |
123 | }) | |
124 | ||
125 | describe('Should run filter:video.auto-blacklist.result', function () { | |
126 | ||
127 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | |
128 | const videoId = oldRes.body.video.uuid | |
129 | ||
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) | |
133 | } | |
134 | ||
135 | it('Should blacklist on upload', async function () { | |
a1587156 | 136 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
6691c522 C |
137 | await checkIsBlacklisted(res, true) |
138 | }) | |
139 | ||
140 | it('Should blacklist on import', async function () { | |
89566f77 C |
141 | this.timeout(15000) |
142 | ||
6691c522 C |
143 | const attributes = { |
144 | name: 'video please blacklist me', | |
145 | targetUrl: getYoutubeVideoUrl(), | |
146 | channelId: servers[0].videoChannel.id | |
147 | } | |
148 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
149 | await checkIsBlacklisted(res, true) | |
150 | }) | |
151 | ||
152 | it('Should blacklist on update', async function () { | |
a1587156 | 153 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
6691c522 C |
154 | const videoId = res.body.video.uuid |
155 | await checkIsBlacklisted(res, false) | |
156 | ||
a1587156 | 157 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
6691c522 C |
158 | await checkIsBlacklisted(res, true) |
159 | }) | |
160 | ||
161 | it('Should blacklist on remote upload', async function () { | |
162 | this.timeout(45000) | |
163 | ||
a1587156 | 164 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
6691c522 C |
165 | await waitJobs(servers) |
166 | ||
167 | await checkIsBlacklisted(res, true) | |
168 | }) | |
169 | ||
170 | it('Should blacklist on remote update', async function () { | |
171 | this.timeout(45000) | |
172 | ||
a1587156 | 173 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) |
6691c522 C |
174 | await waitJobs(servers) |
175 | ||
176 | const videoId = res.body.video.uuid | |
177 | await checkIsBlacklisted(res, false) | |
178 | ||
179 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | |
180 | await waitJobs(servers) | |
181 | ||
182 | await checkIsBlacklisted(res, true) | |
183 | }) | |
184 | }) | |
185 | ||
4ce7eb71 C |
186 | describe('Should run filter:api.user.signup.allowed.result', function () { |
187 | ||
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 | |
191 | }) | |
192 | ||
193 | it('Should allow a signup', async function () { | |
194 | await registerUser(servers[0].url, 'john', 'password') | |
195 | }) | |
196 | ||
197 | it('Should not allow a signup', async function () { | |
198 | const res = await registerUser(servers[0].url, 'jma', 'password', 403) | |
199 | ||
200 | expect(res.body.error).to.equal('No jma') | |
201 | }) | |
202 | }) | |
203 | ||
9b474844 | 204 | after(async function () { |
89cd1275 | 205 | await cleanupTests(servers) |
9b474844 C |
206 | }) |
207 | }) |