]>
Commit | Line | Data |
---|---|---|
0f91ae62 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
c5d31dba | 5 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' |
0f91ae62 C |
6 | |
7 | import { | |
db799da3 | 8 | flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, |
0f91ae62 | 9 | wait |
c5d31dba C |
10 | } from '../../utils/index' |
11 | import { dateIsValid, webtorrentAdd } from '../../utils/miscs/miscs' | |
12 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' | |
13 | import { getUserAccessToken } from '../../utils/users/login' | |
14 | import { createUser } from '../../utils/users/users' | |
15 | import { | |
16 | addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads, | |
17 | getVideoThreadComments | |
18 | } from '../../utils/videos/video-comments' | |
19 | import { getVideo, rateVideo, testVideoImage } from '../../utils/videos/videos' | |
0f91ae62 C |
20 | |
21 | const expect = chai.expect | |
22 | ||
23 | describe('Test follows', function () { | |
24 | let servers: ServerInfo[] = [] | |
0f91ae62 C |
25 | |
26 | before(async function () { | |
c46edbc2 | 27 | this.timeout(20000) |
0f91ae62 C |
28 | |
29 | servers = await flushAndRunMultipleServers(3) | |
30 | ||
31 | // Get the access tokens | |
32 | await setAccessTokensToServers(servers) | |
33 | }) | |
34 | ||
35 | it('Should not have followers', async function () { | |
36 | for (const server of servers) { | |
37 | const res = await getFollowersListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
38 | const follows = res.body.data | |
39 | ||
40 | expect(res.body.total).to.equal(0) | |
41 | expect(follows).to.be.an('array') | |
42 | expect(follows.length).to.equal(0) | |
43 | } | |
44 | }) | |
45 | ||
46 | it('Should not have following', async function () { | |
47 | for (const server of servers) { | |
48 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
49 | const follows = res.body.data | |
50 | ||
51 | expect(res.body.total).to.equal(0) | |
52 | expect(follows).to.be.an('array') | |
53 | expect(follows.length).to.equal(0) | |
54 | } | |
55 | }) | |
56 | ||
57 | it('Should have server 1 following server 2 and 3', async function () { | |
58 | this.timeout(10000) | |
59 | ||
60 | await follow(servers[0].url, [ servers[1].url, servers[2].url ], servers[0].accessToken) | |
61 | ||
62 | await wait(7000) | |
63 | }) | |
64 | ||
65 | it('Should have 2 followings on server 1', async function () { | |
66 | let res = await getFollowingListPaginationAndSort(servers[0].url, 0, 1, 'createdAt') | |
67 | let follows = res.body.data | |
68 | ||
69 | expect(res.body.total).to.equal(2) | |
70 | expect(follows).to.be.an('array') | |
71 | expect(follows.length).to.equal(1) | |
72 | ||
73 | res = await getFollowingListPaginationAndSort(servers[0].url, 1, 1, 'createdAt') | |
74 | follows = follows.concat(res.body.data) | |
75 | ||
76 | const server2Follow = follows.find(f => f.following.host === 'localhost:9002') | |
77 | const server3Follow = follows.find(f => f.following.host === 'localhost:9003') | |
78 | ||
79 | expect(server2Follow).to.not.be.undefined | |
80 | expect(server3Follow).to.not.be.undefined | |
81 | expect(server2Follow.state).to.equal('accepted') | |
82 | expect(server3Follow.state).to.equal('accepted') | |
0f91ae62 C |
83 | }) |
84 | ||
85 | it('Should have 0 followings on server 1 and 2', async function () { | |
86 | for (const server of [ servers[1], servers[2] ]) { | |
87 | const res = await getFollowingListPaginationAndSort(server.url, 0, 5, 'createdAt') | |
88 | const follows = res.body.data | |
89 | ||
90 | expect(res.body.total).to.equal(0) | |
91 | expect(follows).to.be.an('array') | |
92 | expect(follows.length).to.equal(0) | |
93 | } | |
94 | }) | |
95 | ||
96 | it('Should have 1 followers on server 2 and 3', async function () { | |
97 | for (const server of [ servers[1], servers[2] ]) { | |
98 | let res = await getFollowersListPaginationAndSort(server.url, 0, 1, 'createdAt') | |
99 | ||
100 | let follows = res.body.data | |
101 | expect(res.body.total).to.equal(1) | |
102 | expect(follows).to.be.an('array') | |
103 | expect(follows.length).to.equal(1) | |
104 | expect(follows[0].follower.host).to.equal('localhost:9001') | |
105 | } | |
106 | }) | |
107 | ||
108 | it('Should have 0 followers on server 1', async function () { | |
109 | const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') | |
110 | const follows = res.body.data | |
111 | ||
112 | expect(res.body.total).to.equal(0) | |
113 | expect(follows).to.be.an('array') | |
114 | expect(follows.length).to.equal(0) | |
115 | }) | |
116 | ||
117 | it('Should unfollow server 3 on server 1', async function () { | |
118 | this.timeout(5000) | |
119 | ||
50d6de9c | 120 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) |
0f91ae62 C |
121 | |
122 | await wait(3000) | |
123 | }) | |
124 | ||
125 | it('Should not follow server 3 on server 1 anymore', async function () { | |
126 | const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 2, 'createdAt') | |
127 | let follows = res.body.data | |
128 | ||
129 | expect(res.body.total).to.equal(1) | |
130 | expect(follows).to.be.an('array') | |
131 | expect(follows.length).to.equal(1) | |
132 | ||
133 | expect(follows[0].following.host).to.equal('localhost:9002') | |
134 | }) | |
135 | ||
136 | it('Should not have server 1 as follower on server 3 anymore', async function () { | |
137 | const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 1, 'createdAt') | |
138 | ||
139 | let follows = res.body.data | |
140 | expect(res.body.total).to.equal(0) | |
141 | expect(follows).to.be.an('array') | |
142 | expect(follows.length).to.equal(0) | |
143 | }) | |
144 | ||
145 | it('Should upload a video on server 2 ans 3 and propagate only the video of server 2', async function () { | |
146 | this.timeout(10000) | |
147 | ||
148 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'server2' }) | |
149 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3' }) | |
150 | ||
151 | await wait(5000) | |
152 | ||
153 | let res = await getVideosList(servers[0].url) | |
154 | expect(res.body.total).to.equal(1) | |
155 | expect(res.body.data[0].name).to.equal('server2') | |
156 | ||
157 | res = await getVideosList(servers[1].url) | |
158 | expect(res.body.total).to.equal(1) | |
159 | expect(res.body.data[0].name).to.equal('server2') | |
160 | ||
161 | res = await getVideosList(servers[2].url) | |
162 | expect(res.body.total).to.equal(1) | |
163 | expect(res.body.data[0].name).to.equal('server3') | |
164 | }) | |
165 | ||
c46edbc2 C |
166 | it('Should propagate previous uploaded videos on a new following', async function () { |
167 | this.timeout(20000) | |
168 | ||
d8553faa C |
169 | const video4Attributes = { |
170 | name: 'server3-4', | |
171 | category: 2, | |
172 | nsfw: true, | |
173 | licence: 6, | |
174 | tags: [ 'tag1', 'tag2', 'tag3' ] | |
175 | } | |
176 | ||
c46edbc2 C |
177 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-2' }) |
178 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-3' }) | |
d8553faa | 179 | await uploadVideo(servers[2].url, servers[2].accessToken, video4Attributes) |
c46edbc2 C |
180 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-5' }) |
181 | await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) | |
182 | ||
d8553faa C |
183 | { |
184 | const user = { username: 'captain', password: 'password' } | |
185 | await createUser(servers[2].url, servers[2].accessToken, user.username, user.password) | |
186 | const userAccessToken = await getUserAccessToken(servers[2], user) | |
187 | ||
db799da3 C |
188 | const resVideos = await getVideosList(servers[ 2 ].url) |
189 | const video4 = resVideos.body.data.find(v => v.name === 'server3-4') | |
d8553faa | 190 | |
db799da3 C |
191 | { |
192 | await rateVideo(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, 'like') | |
193 | await rateVideo(servers[ 2 ].url, userAccessToken, video4.id, 'dislike') | |
194 | } | |
195 | ||
196 | { | |
197 | const text = 'my super first comment' | |
198 | const res = await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, text) | |
199 | const threadId = res.body.comment.id | |
200 | ||
201 | const text1 = 'my super answer to thread 1' | |
202 | const childCommentRes = await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text1) | |
203 | const childCommentId = childCommentRes.body.comment.id | |
204 | ||
205 | const text2 = 'my super answer to answer of thread 1' | |
206 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, childCommentId, text2) | |
207 | ||
208 | const text3 = 'my second answer to thread 1' | |
209 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, video4.id, threadId, text3) | |
210 | } | |
d8553faa C |
211 | } |
212 | ||
c46edbc2 C |
213 | await wait(5000) |
214 | ||
215 | // Server 1 follows server 3 | |
216 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | |
217 | ||
218 | await wait(7000) | |
219 | ||
220 | let res = await getVideosList(servers[0].url) | |
221 | expect(res.body.total).to.equal(7) | |
222 | ||
223 | const video2 = res.body.data.find(v => v.name === 'server3-2') | |
224 | const video4 = res.body.data.find(v => v.name === 'server3-4') | |
225 | const video6 = res.body.data.find(v => v.name === 'server3-6') | |
226 | ||
227 | expect(video2).to.not.be.undefined | |
228 | expect(video4).to.not.be.undefined | |
229 | expect(video6).to.not.be.undefined | |
d8553faa C |
230 | |
231 | const res2 = await getVideo(servers[0].url, video4.id) | |
232 | const videoDetails = res2.body | |
233 | ||
234 | expect(videoDetails.name).to.equal('server3-4') | |
235 | expect(videoDetails.category).to.equal(2) | |
236 | expect(videoDetails.categoryLabel).to.equal('Films') | |
237 | expect(videoDetails.licence).to.equal(6) | |
238 | expect(videoDetails.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
239 | expect(videoDetails.language).to.equal(3) | |
240 | expect(videoDetails.languageLabel).to.equal('Mandarin') | |
241 | expect(videoDetails.nsfw).to.be.ok | |
242 | expect(videoDetails.description).to.equal('my super description') | |
243 | expect(videoDetails.serverHost).to.equal('localhost:9003') | |
b1fa3eba | 244 | expect(videoDetails.accountName).to.equal('root') |
d8553faa C |
245 | expect(videoDetails.likes).to.equal(1) |
246 | expect(videoDetails.dislikes).to.equal(1) | |
247 | expect(videoDetails.isLocal).to.be.false | |
248 | expect(videoDetails.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | |
249 | expect(dateIsValid(videoDetails.createdAt)).to.be.true | |
250 | expect(dateIsValid(videoDetails.updatedAt)).to.be.true | |
251 | expect(videoDetails.files).to.have.lengthOf(1) | |
252 | ||
253 | const file = videoDetails.files[0] | |
254 | const magnetUri = file.magnetUri | |
255 | expect(file.magnetUri).to.have.lengthOf.above(2) | |
256 | expect(file.torrentUrl).to.equal(`${servers[2].url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | |
257 | expect(file.fileUrl).to.equal(`${servers[2].url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | |
258 | expect(file.resolution).to.equal(720) | |
259 | expect(file.resolutionLabel).to.equal('720p') | |
260 | expect(file.size).to.equal(218910) | |
261 | ||
262 | const test = await testVideoImage(servers[2].url, 'video_short.webm', videoDetails.thumbnailPath) | |
263 | expect(test).to.equal(true) | |
264 | ||
265 | const torrent = await webtorrentAdd(magnetUri) | |
266 | expect(torrent.files).to.be.an('array') | |
267 | expect(torrent.files.length).to.equal(1) | |
268 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
db799da3 C |
269 | |
270 | { | |
271 | const res1 = await getVideoCommentThreads(servers[0].url, video4.id, 0, 5) | |
272 | ||
273 | expect(res1.body.total).to.equal(1) | |
274 | expect(res1.body.data).to.be.an('array') | |
275 | expect(res1.body.data).to.have.lengthOf(1) | |
276 | ||
277 | const comment: VideoComment = res1.body.data[0] | |
278 | expect(comment.inReplyToCommentId).to.be.null | |
279 | expect(comment.text).equal('my super first comment') | |
280 | expect(comment.videoId).to.equal(video4.id) | |
281 | expect(comment.id).to.equal(comment.threadId) | |
282 | expect(comment.account.name).to.equal('root') | |
283 | expect(comment.account.host).to.equal('localhost:9003') | |
284 | expect(comment.totalReplies).to.equal(3) | |
285 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
286 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
287 | ||
288 | const threadId = comment.threadId | |
289 | ||
290 | const res2 = await getVideoThreadComments(servers[0].url, video4.id, threadId) | |
291 | ||
292 | const tree: VideoCommentThreadTree = res2.body | |
293 | expect(tree.comment.text).equal('my super first comment') | |
294 | expect(tree.children).to.have.lengthOf(2) | |
295 | ||
296 | const firstChild = tree.children[0] | |
297 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
298 | expect(firstChild.children).to.have.lengthOf(1) | |
299 | ||
300 | const childOfFirstChild = firstChild.children[0] | |
301 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
302 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
303 | ||
304 | const secondChild = tree.children[1] | |
305 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
306 | expect(secondChild.children).to.have.lengthOf(0) | |
307 | } | |
c46edbc2 C |
308 | }) |
309 | ||
0f91ae62 C |
310 | after(async function () { |
311 | killallServers(servers) | |
312 | ||
313 | // Keep the logs if the test failed | |
314 | if (this['ok']) { | |
315 | await flushTests() | |
316 | } | |
317 | }) | |
318 | }) |