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