]>
Commit | Line | Data |
---|---|---|
9b474844 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
89cd1275 C |
5 | import { |
6 | cleanupTests, | |
7 | flushAndRunMultipleServers, | |
8 | flushAndRunServer, killallServers, reRunServer, | |
9 | ServerInfo, | |
10 | waitUntilLog | |
11 | } from '../../../shared/extra-utils/server/servers' | |
12 | import { | |
13 | addVideoCommentReply, | |
6691c522 C |
14 | addVideoCommentThread, |
15 | deleteVideoComment, | |
16 | getPluginTestPath, | |
17 | getVideosList, | |
18 | installPlugin, | |
19 | removeVideo, | |
89cd1275 C |
20 | setAccessTokensToServers, |
21 | updateVideo, | |
22 | uploadVideo, | |
23 | viewVideo, | |
6691c522 C |
24 | getVideosListPagination, |
25 | getVideo, | |
26 | getVideoCommentThreads, | |
27 | getVideoThreadComments, | |
28 | getVideoWithToken, | |
29 | setDefaultVideoChannel, | |
30 | waitJobs, | |
31 | doubleFollow | |
89cd1275 | 32 | } from '../../../shared/extra-utils' |
6691c522 C |
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' | |
9b474844 C |
36 | |
37 | const expect = chai.expect | |
38 | ||
39 | describe('Test plugin filter hooks', function () { | |
89cd1275 C |
40 | let servers: ServerInfo[] |
41 | let videoUUID: string | |
42 | let threadId: number | |
9b474844 C |
43 | |
44 | before(async function () { | |
45 | this.timeout(30000) | |
9b474844 | 46 | |
89cd1275 C |
47 | servers = await flushAndRunMultipleServers(2) |
48 | await setAccessTokensToServers(servers) | |
6691c522 C |
49 | await setDefaultVideoChannel(servers) |
50 | await doubleFollow(servers[0], servers[1]) | |
89cd1275 C |
51 | |
52 | await installPlugin({ | |
53 | url: servers[0].url, | |
54 | accessToken: servers[0].accessToken, | |
55 | path: getPluginTestPath() | |
56 | }) | |
57 | ||
58 | await installPlugin({ | |
59 | url: servers[0].url, | |
60 | accessToken: servers[0].accessToken, | |
61 | path: getPluginTestPath('-two') | |
62 | }) | |
63 | ||
64 | for (let i = 0; i < 10; i++) { | |
65 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | |
66 | } | |
67 | ||
68 | const res = await getVideosList(servers[0].url) | |
69 | videoUUID = res.body.data[0].uuid | |
9b474844 C |
70 | }) |
71 | ||
6691c522 | 72 | it('Should run filter:api.videos.list.params', async function () { |
89cd1275 C |
73 | const res = await getVideosListPagination(servers[0].url, 0, 2) |
74 | ||
75 | // 2 plugins do +1 to the count parameter | |
76 | expect(res.body.data).to.have.lengthOf(4) | |
77 | }) | |
78 | ||
79 | it('Should run filter:api.videos.list.result', async function () { | |
80 | const res = await getVideosListPagination(servers[0].url, 0, 0) | |
81 | ||
82 | // Plugin do +1 to the total result | |
83 | expect(res.body.total).to.equal(11) | |
84 | }) | |
85 | ||
86 | it('Should run filter:api.video.get.result', async function () { | |
87 | const res = await getVideo(servers[0].url, videoUUID) | |
88 | ||
89 | expect(res.body.name).to.contain('<3') | |
9b474844 C |
90 | }) |
91 | ||
6691c522 C |
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 | ||
9b474844 | 190 | after(async function () { |
89cd1275 | 191 | await cleanupTests(servers) |
9b474844 C |
192 | }) |
193 | }) |