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