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