]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/fetch.ts
Merge branch 'develop' into pr/1217
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / fetch.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4
5 import {
6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
9 flushTests,
10 getVideosListSort,
11 killallServers,
12 ServerInfo,
13 setAccessTokensToServers,
14 setActorField,
15 setVideoField,
16 uploadVideo,
17 userLogin,
18 waitJobs
19 } from '../../../../shared/utils'
20 import * as chai from 'chai'
21 import { Video } from '../../../../shared/models/videos'
22
23 const expect = chai.expect
24
25 describe('Test ActivityPub fetcher', function () {
26 let servers: ServerInfo[]
27
28 // ---------------------------------------------------------------
29
30 before(async function () {
31 this.timeout(60000)
32
33 servers = await flushAndRunMultipleServers(3)
34
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
37
38 const user = { username: 'user1', password: 'password' }
39 for (const server of servers) {
40 await createUser(server.url, server.accessToken, user.username, user.password)
41 }
42
43 const userAccessToken = await userLogin(servers[0], user)
44
45 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' })
46 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' })
47 const badVideoUUID = res.body.video.uuid
48 await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
49
50 await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1')
51 await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID)
52 })
53
54 it('Should add only the video with a valid actor URL', async function () {
55 this.timeout(60000)
56
57 await doubleFollow(servers[0], servers[1])
58 await waitJobs(servers)
59
60 {
61 const res = await getVideosListSort(servers[0].url, 'createdAt')
62 expect(res.body.total).to.equal(3)
63
64 const data: Video[] = res.body.data
65 expect(data[0].name).to.equal('video root')
66 expect(data[1].name).to.equal('bad video root')
67 expect(data[2].name).to.equal('video user')
68 }
69
70 {
71 const res = await getVideosListSort(servers[1].url, 'createdAt')
72 expect(res.body.total).to.equal(1)
73
74 const data: Video[] = res.body.data
75 expect(data[0].name).to.equal('video root')
76 }
77 })
78
79 after(async function () {
80 killallServers(servers)
81
82 // Keep the logs if the test failed
83 if (this['ok']) {
84 await flushTests()
85 }
86 })
87 })