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