aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/multiple-pods.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-24 19:41:30 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commit5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (patch)
treea73085d0d83affc2377b78a2c7c25bda08d26388 /server/tests/api/multiple-pods.ts
parent72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (diff)
downloadPeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.tar.gz
PeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.tar.zst
PeerTube-5f04dd2f743961e0a06c29531cc3ccc9e4928d56.zip
Add video channel tests
Diffstat (limited to 'server/tests/api/multiple-pods.ts')
-rw-r--r--server/tests/api/multiple-pods.ts134
1 files changed, 97 insertions, 37 deletions
diff --git a/server/tests/api/multiple-pods.ts b/server/tests/api/multiple-pods.ts
index e0ccb3058..fe4e4a036 100644
--- a/server/tests/api/multiple-pods.ts
+++ b/server/tests/api/multiple-pods.ts
@@ -19,8 +19,12 @@ import {
19 updateVideo, 19 updateVideo,
20 uploadVideo, 20 uploadVideo,
21 wait, 21 wait,
22 webtorrentAdd 22 webtorrentAdd,
23 addVideoChannel,
24 getVideoChannelsList,
25 getUserAccessToken
23} from '../utils' 26} from '../utils'
27import { createUser } from '../utils/users'
24 28
25const expect = chai.expect 29const expect = chai.expect
26 30
@@ -28,6 +32,7 @@ describe('Test multiple pods', function () {
28 let servers: ServerInfo[] = [] 32 let servers: ServerInfo[] = []
29 const toRemove = [] 33 const toRemove = []
30 let videoUUID = '' 34 let videoUUID = ''
35 let videoChannelId: number
31 36
32 before(async function () { 37 before(async function () {
33 this.timeout(120000) 38 this.timeout(120000)
@@ -37,6 +42,14 @@ describe('Test multiple pods', function () {
37 // Get the access tokens 42 // Get the access tokens
38 await setAccessTokensToServers(servers) 43 await setAccessTokensToServers(servers)
39 44
45 const videoChannel = {
46 name: 'my channel',
47 description: 'super channel'
48 }
49 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
50 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1)
51 videoChannelId = channelRes.body.data[0].id
52
40 // The second pod make friend with the third 53 // The second pod make friend with the third
41 await makeFriends(servers[1].url, servers[1].accessToken) 54 await makeFriends(servers[1].url, servers[1].accessToken)
42 55
@@ -69,6 +82,7 @@ describe('Test multiple pods', function () {
69 nsfw: true, 82 nsfw: true,
70 description: 'my super description for pod 1', 83 description: 'my super description for pod 1',
71 tags: [ 'tag1p1', 'tag2p1' ], 84 tags: [ 'tag1p1', 'tag2p1' ],
85 channelId: videoChannelId,
72 fixture: 'video_short1.webm' 86 fixture: 'video_short1.webm'
73 } 87 }
74 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 88 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
@@ -101,21 +115,30 @@ describe('Test multiple pods', function () {
101 expect(dateIsValid(video.updatedAt)).to.be.true 115 expect(dateIsValid(video.updatedAt)).to.be.true
102 expect(video.author).to.equal('root') 116 expect(video.author).to.equal('root')
103 117
104 expect(video.files).to.have.lengthOf(1) 118 const res2 = await getVideo(server.url, video.uuid)
119 const videoDetails = res2.body
120
121 expect(videoDetails.channel.name).to.equal('my channel')
122 expect(videoDetails.channel.description).to.equal('super channel')
123 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
124 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
125 expect(videoDetails.files).to.have.lengthOf(1)
105 126
106 const file = video.files[0] 127 const file = videoDetails.files[0]
107 const magnetUri = file.magnetUri 128 const magnetUri = file.magnetUri
108 expect(file.magnetUri).to.have.lengthOf.above(2) 129 expect(file.magnetUri).to.have.lengthOf.above(2)
109 expect(file.torrentUrl).to.equal(`http://${video.podHost}/static/torrents/${video.uuid}-${file.resolution}.torrent`) 130 expect(file.torrentUrl).to.equal(`http://${videoDetails.podHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
110 expect(file.fileUrl).to.equal(`http://${video.podHost}/static/webseed/${video.uuid}-${file.resolution}.webm`) 131 expect(file.fileUrl).to.equal(`http://${videoDetails.podHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
111 expect(file.resolution).to.equal(720) 132 expect(file.resolution).to.equal(720)
112 expect(file.resolutionLabel).to.equal('720p') 133 expect(file.resolutionLabel).to.equal('720p')
113 expect(file.size).to.equal(572456) 134 expect(file.size).to.equal(572456)
114 135
115 if (server.url !== 'http://localhost:9001') { 136 if (server.url !== 'http://localhost:9001') {
116 expect(video.isLocal).to.be.false 137 expect(video.isLocal).to.be.false
138 expect(videoDetails.channel.isLocal).to.be.false
117 } else { 139 } else {
118 expect(video.isLocal).to.be.true 140 expect(video.isLocal).to.be.true
141 expect(videoDetails.channel.isLocal).to.be.true
119 } 142 }
120 143
121 // All pods should have the same magnet Uri 144 // All pods should have the same magnet Uri
@@ -133,6 +156,13 @@ describe('Test multiple pods', function () {
133 it('Should upload the video on pod 2 and propagate on each pod', async function () { 156 it('Should upload the video on pod 2 and propagate on each pod', async function () {
134 this.timeout(120000) 157 this.timeout(120000)
135 158
159 const user = {
160 username: 'user1',
161 password: 'super_password'
162 }
163 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
164 const userAccessToken = await getUserAccessToken(servers[1], user)
165
136 const videoAttributes = { 166 const videoAttributes = {
137 name: 'my super name for pod 2', 167 name: 'my super name for pod 2',
138 category: 4, 168 category: 4,
@@ -143,7 +173,7 @@ describe('Test multiple pods', function () {
143 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], 173 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
144 fixture: 'video_short2.webm' 174 fixture: 'video_short2.webm'
145 } 175 }
146 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes) 176 await uploadVideo(servers[1].url, userAccessToken, videoAttributes)
147 177
148 // Transcoding, so wait more than 22000 178 // Transcoding, so wait more than 22000
149 await wait(60000) 179 await wait(60000)
@@ -172,20 +202,27 @@ describe('Test multiple pods', function () {
172 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) 202 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
173 expect(dateIsValid(video.createdAt)).to.be.true 203 expect(dateIsValid(video.createdAt)).to.be.true
174 expect(dateIsValid(video.updatedAt)).to.be.true 204 expect(dateIsValid(video.updatedAt)).to.be.true
175 expect(video.author).to.equal('root') 205 expect(video.author).to.equal('user1')
206
207 if (server.url !== 'http://localhost:9002') {
208 expect(video.isLocal).to.be.false
209 } else {
210 expect(video.isLocal).to.be.true
211 }
176 212
177 expect(video.files).to.have.lengthOf(4) 213 const res2 = await getVideo(server.url, video.uuid)
214 const videoDetails = res2.body
215
216 expect(videoDetails.channel.name).to.equal('Default user1 channel')
217 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
218 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true
219
220 expect(videoDetails.files).to.have.lengthOf(4)
178 221
179 // Check common attributes 222 // Check common attributes
180 for (const file of video.files) { 223 for (const file of videoDetails.files) {
181 expect(file.magnetUri).to.have.lengthOf.above(2) 224 expect(file.magnetUri).to.have.lengthOf.above(2)
182 225
183 if (server.url !== 'http://localhost:9002') {
184 expect(video.isLocal).to.be.false
185 } else {
186 expect(video.isLocal).to.be.true
187 }
188
189 // All pods should have the same magnet Uri 226 // All pods should have the same magnet Uri
190 if (baseMagnet[file.resolution] === undefined) { 227 if (baseMagnet[file.resolution] === undefined) {
191 baseMagnet[file.resolution] = file.magnet 228 baseMagnet[file.resolution] = file.magnet
@@ -194,27 +231,27 @@ describe('Test multiple pods', function () {
194 } 231 }
195 } 232 }
196 233
197 const file240p = video.files.find(f => f.resolution === 240) 234 const file240p = videoDetails.files.find(f => f.resolution === 240)
198 expect(file240p).not.to.be.undefined 235 expect(file240p).not.to.be.undefined
199 expect(file240p.resolutionLabel).to.equal('240p') 236 expect(file240p.resolutionLabel).to.equal('240p')
200 expect(file240p.size).to.be.above(180000).and.below(200000) 237 expect(file240p.size).to.be.above(180000).and.below(200000)
201 238
202 const file360p = video.files.find(f => f.resolution === 360) 239 const file360p = videoDetails.files.find(f => f.resolution === 360)
203 expect(file360p).not.to.be.undefined 240 expect(file360p).not.to.be.undefined
204 expect(file360p.resolutionLabel).to.equal('360p') 241 expect(file360p.resolutionLabel).to.equal('360p')
205 expect(file360p.size).to.be.above(270000).and.below(290000) 242 expect(file360p.size).to.be.above(270000).and.below(290000)
206 243
207 const file480p = video.files.find(f => f.resolution === 480) 244 const file480p = videoDetails.files.find(f => f.resolution === 480)
208 expect(file480p).not.to.be.undefined 245 expect(file480p).not.to.be.undefined
209 expect(file480p.resolutionLabel).to.equal('480p') 246 expect(file480p.resolutionLabel).to.equal('480p')
210 expect(file480p.size).to.be.above(380000).and.below(400000) 247 expect(file480p.size).to.be.above(380000).and.below(400000)
211 248
212 const file720p = video.files.find(f => f.resolution === 720) 249 const file720p = videoDetails.files.find(f => f.resolution === 720)
213 expect(file720p).not.to.be.undefined 250 expect(file720p).not.to.be.undefined
214 expect(file720p.resolutionLabel).to.equal('720p') 251 expect(file720p.resolutionLabel).to.equal('720p')
215 expect(file720p.size).to.be.above(700000).and.below(7200000) 252 expect(file720p.size).to.be.above(700000).and.below(7200000)
216 253
217 const test = await testVideoImage(server.url, 'video_short2.webm', video.thumbnailPath) 254 const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath)
218 expect(test).to.equal(true) 255 expect(test).to.equal(true)
219 } 256 }
220 }) 257 })
@@ -284,9 +321,11 @@ describe('Test multiple pods', function () {
284 expect(dateIsValid(video1.createdAt)).to.be.true 321 expect(dateIsValid(video1.createdAt)).to.be.true
285 expect(dateIsValid(video1.updatedAt)).to.be.true 322 expect(dateIsValid(video1.updatedAt)).to.be.true
286 323
287 expect(video1.files).to.have.lengthOf(1) 324 const res2 = await getVideo(server.url, video1.id)
325 const video1Details = res2.body
326 expect(video1Details.files).to.have.lengthOf(1)
288 327
289 const file1 = video1.files[0] 328 const file1 = video1Details.files[0]
290 expect(file1.magnetUri).to.have.lengthOf.above(2) 329 expect(file1.magnetUri).to.have.lengthOf.above(2)
291 expect(file1.resolution).to.equal(720) 330 expect(file1.resolution).to.equal(720)
292 expect(file1.resolutionLabel).to.equal('720p') 331 expect(file1.resolutionLabel).to.equal('720p')
@@ -308,9 +347,12 @@ describe('Test multiple pods', function () {
308 expect(dateIsValid(video2.createdAt)).to.be.true 347 expect(dateIsValid(video2.createdAt)).to.be.true
309 expect(dateIsValid(video2.updatedAt)).to.be.true 348 expect(dateIsValid(video2.updatedAt)).to.be.true
310 349
311 expect(video2.files).to.have.lengthOf(1) 350 const res3 = await getVideo(server.url, video2.id)
351 const video2Details = res3.body
312 352
313 const file2 = video2.files[0] 353 expect(video2Details.files).to.have.lengthOf(1)
354
355 const file2 = video2Details.files[0]
314 const magnetUri2 = file2.magnetUri 356 const magnetUri2 = file2.magnetUri
315 expect(file2.magnetUri).to.have.lengthOf.above(2) 357 expect(file2.magnetUri).to.have.lengthOf.above(2)
316 expect(file2.resolution).to.equal(720) 358 expect(file2.resolution).to.equal(720)
@@ -352,7 +394,10 @@ describe('Test multiple pods', function () {
352 toRemove.push(res.body.data[2]) 394 toRemove.push(res.body.data[2])
353 toRemove.push(res.body.data[3]) 395 toRemove.push(res.body.data[3])
354 396
355 const torrent = await webtorrentAdd(video.files[0].magnetUri) 397 const res2 = await getVideo(servers[2].url, video.id)
398 const videoDetails = res2.body
399
400 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
356 expect(torrent.files).to.be.an('array') 401 expect(torrent.files).to.be.an('array')
357 expect(torrent.files.length).to.equal(1) 402 expect(torrent.files.length).to.equal(1)
358 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 403 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -365,8 +410,10 @@ describe('Test multiple pods', function () {
365 const res = await getVideosList(servers[0].url) 410 const res = await getVideosList(servers[0].url)
366 411
367 const video = res.body.data[1] 412 const video = res.body.data[1]
413 const res2 = await getVideo(servers[0].url, video.id)
414 const videoDetails = res2.body
368 415
369 const torrent = await webtorrentAdd(video.files[0].magnetUri) 416 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
370 expect(torrent.files).to.be.an('array') 417 expect(torrent.files).to.be.an('array')
371 expect(torrent.files.length).to.equal(1) 418 expect(torrent.files.length).to.equal(1)
372 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 419 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -379,8 +426,10 @@ describe('Test multiple pods', function () {
379 const res = await getVideosList(servers[1].url) 426 const res = await getVideosList(servers[1].url)
380 427
381 const video = res.body.data[2] 428 const video = res.body.data[2]
429 const res2 = await getVideo(servers[1].url, video.id)
430 const videoDetails = res2.body
382 431
383 const torrent = await webtorrentAdd(video.files[0].magnetUri) 432 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
384 expect(torrent.files).to.be.an('array') 433 expect(torrent.files).to.be.an('array')
385 expect(torrent.files.length).to.equal(1) 434 expect(torrent.files.length).to.equal(1)
386 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 435 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -393,8 +442,10 @@ describe('Test multiple pods', function () {
393 const res = await getVideosList(servers[0].url) 442 const res = await getVideosList(servers[0].url)
394 443
395 const video = res.body.data[3] 444 const video = res.body.data[3]
445 const res2 = await getVideo(servers[0].url, video.id)
446 const videoDetails = res2.body
396 447
397 const torrent = await webtorrentAdd(video.files[0].magnetUri) 448 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
398 expect(torrent.files).to.be.an('array') 449 expect(torrent.files).to.be.an('array')
399 expect(torrent.files.length).to.equal(1) 450 expect(torrent.files.length).to.equal(1)
400 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 451 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
@@ -407,7 +458,10 @@ describe('Test multiple pods', function () {
407 const res = await getVideosList(servers[0].url) 458 const res = await getVideosList(servers[0].url)
408 459
409 const video = res.body.data.find(v => v.name === 'my super name for pod 2') 460 const video = res.body.data.find(v => v.name === 'my super name for pod 2')
410 const file = video.files.find(f => f.resolution === 360) 461 const res2 = await getVideo(servers[0].url, video.id)
462 const videoDetails = res2.body
463
464 const file = videoDetails.files.find(f => f.resolution === 360)
411 expect(file).not.to.be.undefined 465 expect(file).not.to.be.undefined
412 466
413 const torrent = await webtorrentAdd(file.magnetUri) 467 const torrent = await webtorrentAdd(file.magnetUri)
@@ -425,14 +479,14 @@ describe('Test multiple pods', function () {
425 479
426 before(async function () { 480 before(async function () {
427 const res1 = await getVideosList(servers[0].url) 481 const res1 = await getVideosList(servers[0].url)
428 remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.id) 482 remoteVideosPod1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
429 483
430 const res2 = await getVideosList(servers[1].url) 484 const res2 = await getVideosList(servers[1].url)
431 remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.id) 485 remoteVideosPod2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
432 486
433 const res3 = await getVideosList(servers[2].url) 487 const res3 = await getVideosList(servers[2].url)
434 localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.id) 488 localVideosPod3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
435 remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.id) 489 remoteVideosPod3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
436 }) 490 })
437 491
438 it('Should view multiple videos on owned servers', async function () { 492 it('Should view multiple videos on owned servers', async function () {
@@ -452,8 +506,11 @@ describe('Test multiple pods', function () {
452 const res = await getVideosList(server.url) 506 const res = await getVideosList(server.url)
453 507
454 const videos = res.body.data 508 const videos = res.body.data
455 expect(videos.find(video => video.views === 3)).to.be.an('object') 509 const video0 = videos.find(v => v.uuid === localVideosPod3[0])
456 expect(videos.find(video => video.views === 1)).to.be.an('object') 510 const video1 = videos.find(v => v.uuid === localVideosPod3[1])
511
512 expect(video0.views).to.equal(4)
513 expect(video1.views).to.equal(2)
457 } 514 }
458 }) 515 })
459 516
@@ -573,7 +630,10 @@ describe('Test multiple pods', function () {
573 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ]) 630 expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ])
574 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true 631 expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
575 632
576 const file = videoUpdated.files[0] 633 const res2 = await getVideo(server.url, videoUpdated.uuid)
634 const videoUpdatedDetails = res2.body
635
636 const file = videoUpdatedDetails .files[0]
577 expect(file.magnetUri).to.have.lengthOf.above(2) 637 expect(file.magnetUri).to.have.lengthOf.above(2)
578 expect(file.resolution).to.equal(720) 638 expect(file.resolution).to.equal(720)
579 expect(file.resolutionLabel).to.equal('720p') 639 expect(file.resolutionLabel).to.equal('720p')
@@ -584,7 +644,7 @@ describe('Test multiple pods', function () {
584 644
585 // Avoid "duplicate torrent" errors 645 // Avoid "duplicate torrent" errors
586 const refreshWebTorrent = true 646 const refreshWebTorrent = true
587 const torrent = await webtorrentAdd(videoUpdated.files[0].magnetUri, refreshWebTorrent) 647 const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent)
588 expect(torrent.files).to.be.an('array') 648 expect(torrent.files).to.be.an('array')
589 expect(torrent.files.length).to.equal(1) 649 expect(torrent.files.length).to.equal(1)
590 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 650 expect(torrent.files[0].path).to.exist.and.to.not.equal('')