]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/client.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / client.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 createMultipleServers,
8 doubleFollow,
9 makeActivityPubGetRequest,
10 PeerTubeServer,
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/extra-utils'
14 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
15
16 const expect = chai.expect
17
18 describe('Test activitypub', function () {
19 let servers: PeerTubeServer[] = []
20 let video: { id: number, uuid: string, shortUUID: string }
21 let playlist: { id: number, uuid: string, shortUUID: string }
22
23 async function testAccount (path: string) {
24 const res = await makeActivityPubGetRequest(servers[0].url, path)
25 const object = res.body
26
27 expect(object.type).to.equal('Person')
28 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
29 expect(object.name).to.equal('root')
30 expect(object.preferredUsername).to.equal('root')
31 }
32
33 async function testChannel (path: string) {
34 const res = await makeActivityPubGetRequest(servers[0].url, path)
35 const object = res.body
36
37 expect(object.type).to.equal('Group')
38 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
39 expect(object.name).to.equal('Main root channel')
40 expect(object.preferredUsername).to.equal('root_channel')
41 }
42
43 async function testVideo (path: string) {
44 const res = await makeActivityPubGetRequest(servers[0].url, path)
45 const object = res.body
46
47 expect(object.type).to.equal('Video')
48 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
49 expect(object.name).to.equal('video')
50 }
51
52 async function testPlaylist (path: string) {
53 const res = await makeActivityPubGetRequest(servers[0].url, path)
54 const object = res.body
55
56 expect(object.type).to.equal('Playlist')
57 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
58 expect(object.name).to.equal('playlist')
59 }
60
61 before(async function () {
62 this.timeout(30000)
63
64 servers = await createMultipleServers(2)
65
66 await setAccessTokensToServers(servers)
67 await setDefaultVideoChannel(servers)
68
69 {
70 video = await servers[0].videos.quickUpload({ name: 'video' })
71 }
72
73 {
74 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
75 playlist = await servers[0].playlists.create({ attributes })
76 }
77
78 await doubleFollow(servers[0], servers[1])
79 })
80
81 it('Should return the account object', async function () {
82 await testAccount('/accounts/root')
83 await testAccount('/a/root')
84 })
85
86 it('Should return the channel object', async function () {
87 await testChannel('/video-channels/root_channel')
88 await testChannel('/c/root_channel')
89 })
90
91 it('Should return the video object', async function () {
92 await testVideo('/videos/watch/' + video.id)
93 await testVideo('/videos/watch/' + video.uuid)
94 await testVideo('/videos/watch/' + video.shortUUID)
95 await testVideo('/w/' + video.id)
96 await testVideo('/w/' + video.uuid)
97 await testVideo('/w/' + video.shortUUID)
98 })
99
100 it('Should return the playlist object', async function () {
101 await testPlaylist('/video-playlists/' + playlist.id)
102 await testPlaylist('/video-playlists/' + playlist.uuid)
103 await testPlaylist('/video-playlists/' + playlist.shortUUID)
104 await testPlaylist('/w/p/' + playlist.id)
105 await testPlaylist('/w/p/' + playlist.uuid)
106 await testPlaylist('/w/p/' + playlist.shortUUID)
107 await testPlaylist('/videos/watch/playlist/' + playlist.id)
108 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
109 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
110 })
111
112 it('Should redirect to the origin video object', async function () {
113 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
114
115 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
116 })
117
118 after(async function () {
119 await cleanupTests(servers)
120 })
121 })