1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { SQLCommand } from '@server/tests/shared'
10 setAccessTokensToServers,
12 } from '@shared/server-commands'
14 describe('Test ActivityPub fetcher', function () {
15 let servers: PeerTubeServer[]
16 let sqlCommandServer1: SQLCommand
18 // ---------------------------------------------------------------
20 before(async function () {
23 servers = await createMultipleServers(3)
25 // Get the access tokens
26 await setAccessTokensToServers(servers)
28 const user = { username: 'user1', password: 'password' }
29 for (const server of servers) {
30 await server.users.create({ username: user.username, password: user.password })
33 const userAccessToken = await servers[0].login.getAccessToken(user)
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' } })
39 sqlCommandServer1 = new SQLCommand(servers[0])
42 const to = servers[0].url + '/accounts/user1'
43 const value = servers[1].url + '/accounts/user1'
44 await sqlCommandServer1.setActorField(to, 'url', value)
48 const value = servers[2].url + '/videos/watch/' + uuid
49 await sqlCommandServer1.setVideoField(uuid, 'url', value)
53 it('Should add only the video with a valid actor URL', async function () {
56 await doubleFollow(servers[0], servers[1])
57 await waitJobs(servers)
60 const { total, data } = await servers[0].videos.list({ sort: 'createdAt' })
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')
69 const { total, data } = await servers[1].videos.list({ sort: 'createdAt' })
71 expect(total).to.equal(1)
72 expect(data[0].name).to.equal('video root')
76 after(async function () {
79 await sqlCommandServer1.cleanup()
80 await cleanupTests(servers)