]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/fetch.ts
Merge branch 'next' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / fetch.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6
7 const expect = chai.expect
8
9 describe('Test ActivityPub fetcher', function () {
10 let servers: PeerTubeServer[]
11
12 // ---------------------------------------------------------------
13
14 before(async function () {
15 this.timeout(60000)
16
17 servers = await createMultipleServers(3)
18
19 // Get the access tokens
20 await setAccessTokensToServers(servers)
21
22 const user = { username: 'user1', password: 'password' }
23 for (const server of servers) {
24 await server.users.create({ username: user.username, password: user.password })
25 }
26
27 const userAccessToken = await servers[0].login.getAccessToken(user)
28
29 await servers[0].videos.upload({ attributes: { name: 'video root' } })
30 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } })
31 await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } })
32
33 {
34 const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
35 const value = 'http://localhost:' + servers[1].port + '/accounts/user1'
36 await servers[0].sql.setActorField(to, 'url', value)
37 }
38
39 {
40 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
41 await servers[0].sql.setVideoField(uuid, 'url', value)
42 }
43 })
44
45 it('Should add only the video with a valid actor URL', async function () {
46 this.timeout(60000)
47
48 await doubleFollow(servers[0], servers[1])
49 await waitJobs(servers)
50
51 {
52 const { total, data } = await servers[0].videos.list({ sort: 'createdAt' })
53
54 expect(total).to.equal(3)
55 expect(data[0].name).to.equal('video root')
56 expect(data[1].name).to.equal('bad video root')
57 expect(data[2].name).to.equal('video user')
58 }
59
60 {
61 const { total, data } = await servers[1].videos.list({ sort: 'createdAt' })
62
63 expect(total).to.equal(1)
64 expect(data[0].name).to.equal('video root')
65 }
66 })
67
68 after(async function () {
69 this.timeout(20000)
70
71 await cleanupTests(servers)
72 })
73 })