1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 makeActivityPubGetRequest,
11 setAccessTokensToServers,
12 setDefaultVideoChannel
13 } from '@shared/extra-utils'
14 import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
16 const expect = chai.expect
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 }
23 async function testAccount (path: string) {
24 const res = await makeActivityPubGetRequest(servers[0].url, path)
25 const object = res.body
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')
33 async function testChannel (path: string) {
34 const res = await makeActivityPubGetRequest(servers[0].url, path)
35 const object = res.body
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')
43 async function testVideo (path: string) {
44 const res = await makeActivityPubGetRequest(servers[0].url, path)
45 const object = res.body
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')
52 async function testPlaylist (path: string) {
53 const res = await makeActivityPubGetRequest(servers[0].url, path)
54 const object = res.body
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')
61 before(async function () {
64 servers = await createMultipleServers(2)
66 await setAccessTokensToServers(servers)
67 await setDefaultVideoChannel(servers)
70 video = await servers[0].videos.quickUpload({ name: 'video' })
74 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
75 playlist = await servers[0].playlists.create({ attributes })
78 await doubleFollow(servers[0], servers[1])
81 it('Should return the account object', async function () {
82 await testAccount('/accounts/root')
83 await testAccount('/a/root')
86 it('Should return the channel object', async function () {
87 await testChannel('/video-channels/root_channel')
88 await testChannel('/c/root_channel')
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)
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)
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)
115 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
118 after(async function () {
119 await cleanupTests(servers)