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