]>
Commit | Line | Data |
---|---|---|
2ccaeeb3 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
cc6373e6 | 5 | import { JobState, Video } from '../../../../shared/models' |
2ccaeeb3 | 6 | import { VideoPrivacy } from '../../../../shared/models/videos' |
7bc29171 | 7 | import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' |
cc6373e6 | 8 | import { completeVideoCheck, getVideo, immutableAssign, reRunServer, unfollow, viewVideo } from '../../utils' |
2ccaeeb3 | 9 | import { |
94831479 C |
10 | flushAndRunMultipleServers, |
11 | getVideosList, | |
12 | killallServers, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | uploadVideo, | |
2ccaeeb3 C |
16 | wait |
17 | } from '../../utils/index' | |
18 | import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows' | |
3cd0734f | 19 | import { getJobsListPaginationAndSort, waitJobs } from '../../utils/server/jobs' |
7bc29171 | 20 | import { |
94831479 C |
21 | addVideoCommentReply, |
22 | addVideoCommentThread, | |
23 | getVideoCommentThreads, | |
7bc29171 C |
24 | getVideoThreadComments |
25 | } from '../../utils/videos/video-comments' | |
2ccaeeb3 C |
26 | |
27 | const expect = chai.expect | |
28 | ||
29 | describe('Test handle downs', function () { | |
30 | let servers: ServerInfo[] = [] | |
7bc29171 C |
31 | let threadIdServer1: number |
32 | let threadIdServer2: number | |
33 | let commentIdServer1: number | |
34 | let commentIdServer2: number | |
cc6373e6 C |
35 | let missedVideo1: Video |
36 | let missedVideo2: Video | |
37 | let unlistedVideo: Video | |
2ccaeeb3 C |
38 | |
39 | const videoAttributes = { | |
40 | name: 'my super name for server 1', | |
41 | category: 5, | |
42 | licence: 4, | |
9d3ef9fe | 43 | language: 'ja', |
2ccaeeb3 | 44 | nsfw: true, |
7bc29171 | 45 | privacy: VideoPrivacy.PUBLIC, |
2ccaeeb3 | 46 | description: 'my super description for server 1', |
2422c46b | 47 | support: 'my super support text for server 1', |
2ccaeeb3 C |
48 | tags: [ 'tag1p1', 'tag2p1' ], |
49 | fixture: 'video_short1.webm' | |
50 | } | |
51 | ||
7bc29171 C |
52 | const unlistedVideoAttributes = immutableAssign(videoAttributes, { |
53 | privacy: VideoPrivacy.UNLISTED | |
54 | }) | |
55 | ||
2ccaeeb3 C |
56 | const checkAttributes = { |
57 | name: 'my super name for server 1', | |
58 | category: 5, | |
59 | licence: 4, | |
9d3ef9fe | 60 | language: 'ja', |
2ccaeeb3 C |
61 | nsfw: true, |
62 | description: 'my super description for server 1', | |
2422c46b | 63 | support: 'my super support text for server 1', |
b64c950a C |
64 | account: { |
65 | name: 'root', | |
66 | host: 'localhost:9001' | |
67 | }, | |
2ccaeeb3 C |
68 | isLocal: false, |
69 | duration: 10, | |
70 | tags: [ 'tag1p1', 'tag2p1' ], | |
71 | privacy: VideoPrivacy.PUBLIC, | |
72 | commentsEnabled: true, | |
73 | channel: { | |
74 | name: 'Default root channel', | |
75 | description: '', | |
76 | isLocal: false | |
77 | }, | |
78 | fixture: 'video_short1.webm', | |
79 | files: [ | |
80 | { | |
81 | resolution: 720, | |
82 | size: 572456 | |
83 | } | |
84 | ] | |
85 | } | |
86 | ||
7bc29171 C |
87 | const unlistedCheckAttributes = immutableAssign(checkAttributes, { |
88 | privacy: VideoPrivacy.UNLISTED | |
89 | }) | |
90 | ||
2ccaeeb3 | 91 | before(async function () { |
e212f887 | 92 | this.timeout(30000) |
2ccaeeb3 | 93 | |
cc6373e6 | 94 | servers = await flushAndRunMultipleServers(3) |
2ccaeeb3 C |
95 | |
96 | // Get the access tokens | |
97 | await setAccessTokensToServers(servers) | |
98 | }) | |
99 | ||
100 | it('Should remove followers that are often down', async function () { | |
101 | this.timeout(60000) | |
102 | ||
cc6373e6 | 103 | // Server 2 and 3 follow server 1 |
2ccaeeb3 | 104 | await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) |
cc6373e6 | 105 | await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) |
2ccaeeb3 | 106 | |
3cd0734f | 107 | await waitJobs(servers) |
2ccaeeb3 | 108 | |
cc6373e6 | 109 | // Upload a video to server 1 |
2ccaeeb3 C |
110 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) |
111 | ||
3cd0734f | 112 | await waitJobs(servers) |
2ccaeeb3 | 113 | |
cc6373e6 | 114 | // And check all servers have this video |
2ccaeeb3 C |
115 | for (const server of servers) { |
116 | const res = await getVideosList(server.url) | |
117 | expect(res.body.data).to.be.an('array') | |
118 | expect(res.body.data).to.have.lengthOf(1) | |
119 | } | |
120 | ||
cc6373e6 | 121 | // Kill server 2 |
2ccaeeb3 C |
122 | killallServers([ servers[1] ]) |
123 | ||
124 | // Remove server 2 follower | |
125 | for (let i = 0; i < 10; i++) { | |
cc6373e6 | 126 | await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) |
7bc29171 C |
127 | } |
128 | ||
3cd0734f | 129 | await waitJobs(servers[0]) |
6502c3d4 | 130 | |
cc6373e6 C |
131 | // Kill server 3 |
132 | killallServers([ servers[2] ]) | |
133 | ||
134 | const resLastVideo1 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) | |
135 | missedVideo1 = resLastVideo1.body.video | |
136 | ||
137 | const resLastVideo2 = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) | |
138 | missedVideo2 = resLastVideo2.body.video | |
139 | ||
140 | // Unlisted video | |
141 | let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes) | |
142 | unlistedVideo = resVideo.body.video | |
6502c3d4 | 143 | |
7bc29171 C |
144 | // Add comments to video 2 |
145 | { | |
146 | const text = 'thread 1' | |
cc6373e6 | 147 | let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, missedVideo2.uuid, text) |
7bc29171 C |
148 | let comment = resComment.body.comment |
149 | threadIdServer1 = comment.id | |
150 | ||
cc6373e6 | 151 | resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-1') |
7bc29171 C |
152 | comment = resComment.body.comment |
153 | ||
cc6373e6 | 154 | resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, comment.id, 'comment 1-2') |
7bc29171 | 155 | commentIdServer1 = resComment.body.comment.id |
2ccaeeb3 C |
156 | } |
157 | ||
3cd0734f C |
158 | await waitJobs(servers[0]) |
159 | // Wait scheduler | |
9a4a9b6c | 160 | await wait(11000) |
2ccaeeb3 | 161 | |
cc6373e6 C |
162 | // Only server 3 is still a follower of server 1 |
163 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') | |
2ccaeeb3 | 164 | expect(res.body.data).to.be.an('array') |
cc6373e6 C |
165 | expect(res.body.data).to.have.lengthOf(1) |
166 | expect(res.body.data[0].follower.host).to.equal('localhost:9003') | |
2ccaeeb3 C |
167 | }) |
168 | ||
169 | it('Should not have pending/processing jobs anymore', async function () { | |
94831479 | 170 | const states: JobState[] = [ 'waiting', 'active' ] |
2ccaeeb3 | 171 | |
94a5ff8a C |
172 | for (const state of states) { |
173 | const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt') | |
174 | expect(res.body.data).to.have.length(0) | |
2ccaeeb3 C |
175 | } |
176 | }) | |
177 | ||
cc6373e6 | 178 | it('Should re-follow server 1', async function () { |
cf7a61b5 | 179 | this.timeout(35000) |
7bc29171 C |
180 | |
181 | await reRunServer(servers[1]) | |
cc6373e6 C |
182 | await reRunServer(servers[2]) |
183 | ||
184 | await unfollow(servers[1].url, servers[1].accessToken, servers[0]) | |
185 | await waitJobs(servers) | |
2ccaeeb3 C |
186 | |
187 | await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) | |
188 | ||
3cd0734f | 189 | await waitJobs(servers) |
2ccaeeb3 | 190 | |
cc6373e6 | 191 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') |
2ccaeeb3 | 192 | expect(res.body.data).to.be.an('array') |
cc6373e6 | 193 | expect(res.body.data).to.have.lengthOf(2) |
2ccaeeb3 C |
194 | }) |
195 | ||
cc6373e6 | 196 | it('Should send a view to server 3, and automatically fetch the video', async function () { |
7bc29171 | 197 | this.timeout(15000) |
2ccaeeb3 | 198 | |
cc6373e6 C |
199 | const res1 = await getVideosList(servers[2].url) |
200 | expect(res1.body.data).to.be.an('array') | |
201 | expect(res1.body.data).to.have.lengthOf(11) | |
202 | ||
203 | await viewVideo(servers[0].url, missedVideo1.uuid) | |
204 | await viewVideo(servers[0].url, unlistedVideo.uuid) | |
2ccaeeb3 | 205 | |
3cd0734f | 206 | await waitJobs(servers) |
2ccaeeb3 | 207 | |
cc6373e6 | 208 | const res = await getVideosList(servers[2].url) |
7bc29171 | 209 | expect(res.body.data).to.be.an('array') |
cc6373e6 C |
210 | // 1 video is unlisted |
211 | expect(res.body.data).to.have.lengthOf(12) | |
7bc29171 | 212 | |
cc6373e6 C |
213 | // Check unlisted video |
214 | const resVideo = await getVideo(servers[2].url, unlistedVideo.uuid) | |
7bc29171 C |
215 | expect(resVideo.body).not.to.be.undefined |
216 | ||
cc6373e6 | 217 | await completeVideoCheck(servers[2].url, resVideo.body, unlistedCheckAttributes) |
7bc29171 C |
218 | }) |
219 | ||
cc6373e6 | 220 | it('Should send comments on a video to server 3, and automatically fetch the video', async function () { |
7bc29171 | 221 | this.timeout(25000) |
2ccaeeb3 | 222 | |
cc6373e6 | 223 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, missedVideo2.uuid, commentIdServer1, 'comment 1-3') |
7bc29171 | 224 | |
3cd0734f | 225 | await waitJobs(servers) |
7bc29171 | 226 | |
cc6373e6 | 227 | const resVideo = await getVideo(servers[2].url, missedVideo2.uuid) |
7bc29171 C |
228 | expect(resVideo.body).not.to.be.undefined |
229 | ||
7bc29171 | 230 | { |
cc6373e6 | 231 | let resComment = await getVideoCommentThreads(servers[2].url, missedVideo2.uuid, 0, 5) |
7bc29171 C |
232 | expect(resComment.body.data).to.be.an('array') |
233 | expect(resComment.body.data).to.have.lengthOf(1) | |
234 | ||
235 | threadIdServer2 = resComment.body.data[0].id | |
236 | ||
cc6373e6 | 237 | resComment = await getVideoThreadComments(servers[2].url, missedVideo2.uuid, threadIdServer2) |
7bc29171 C |
238 | |
239 | const tree: VideoCommentThreadTree = resComment.body | |
240 | expect(tree.comment.text).equal('thread 1') | |
241 | expect(tree.children).to.have.lengthOf(1) | |
242 | ||
243 | const firstChild = tree.children[0] | |
244 | expect(firstChild.comment.text).to.equal('comment 1-1') | |
245 | expect(firstChild.children).to.have.lengthOf(1) | |
246 | ||
247 | const childOfFirstChild = firstChild.children[0] | |
248 | expect(childOfFirstChild.comment.text).to.equal('comment 1-2') | |
249 | expect(childOfFirstChild.children).to.have.lengthOf(1) | |
250 | ||
251 | const childOfChildFirstChild = childOfFirstChild.children[0] | |
252 | expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') | |
253 | expect(childOfChildFirstChild.children).to.have.lengthOf(0) | |
254 | ||
255 | commentIdServer2 = childOfChildFirstChild.comment.id | |
256 | } | |
257 | }) | |
258 | ||
259 | it('Should correctly reply to the comment', async function () { | |
260 | this.timeout(15000) | |
261 | ||
cc6373e6 | 262 | await addVideoCommentReply(servers[2].url, servers[2].accessToken, missedVideo2.uuid, commentIdServer2, 'comment 1-4') |
7bc29171 | 263 | |
3cd0734f | 264 | await waitJobs(servers) |
7bc29171 C |
265 | |
266 | { | |
cc6373e6 | 267 | const resComment = await getVideoThreadComments(servers[0].url, missedVideo2.uuid, threadIdServer1) |
7bc29171 C |
268 | |
269 | const tree: VideoCommentThreadTree = resComment.body | |
270 | expect(tree.comment.text).equal('thread 1') | |
271 | expect(tree.children).to.have.lengthOf(1) | |
272 | ||
273 | const firstChild = tree.children[0] | |
274 | expect(firstChild.comment.text).to.equal('comment 1-1') | |
275 | expect(firstChild.children).to.have.lengthOf(1) | |
276 | ||
277 | const childOfFirstChild = firstChild.children[0] | |
278 | expect(childOfFirstChild.comment.text).to.equal('comment 1-2') | |
279 | expect(childOfFirstChild.children).to.have.lengthOf(1) | |
280 | ||
281 | const childOfChildFirstChild = childOfFirstChild.children[0] | |
282 | expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3') | |
283 | expect(childOfChildFirstChild.children).to.have.lengthOf(1) | |
284 | ||
285 | const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0] | |
286 | expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4') | |
287 | expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0) | |
288 | } | |
2ccaeeb3 C |
289 | }) |
290 | ||
291 | after(async function () { | |
292 | killallServers(servers) | |
2ccaeeb3 C |
293 | }) |
294 | }) |