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