1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoPlaylistPrivacy } from '@shared/models'
6 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10 flushAndRunMultipleServers,
11 makeActivityPubGetRequest,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
16 } from '../../../../shared/extra-utils'
18 const expect = chai.expect
20 describe('Test activitypub', function () {
21 let servers: ServerInfo[] = []
22 let video: { id: number, uuid: string, shortUUID: string }
23 let playlist: { id: number, uuid: string, shortUUID: string }
25 async function testAccount (path: string) {
26 const res = await makeActivityPubGetRequest(servers[0].url, path)
27 const object = res.body
29 expect(object.type).to.equal('Person')
30 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
31 expect(object.name).to.equal('root')
32 expect(object.preferredUsername).to.equal('root')
35 async function testChannel (path: string) {
36 const res = await makeActivityPubGetRequest(servers[0].url, path)
37 const object = res.body
39 expect(object.type).to.equal('Group')
40 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
41 expect(object.name).to.equal('Main root channel')
42 expect(object.preferredUsername).to.equal('root_channel')
45 async function testVideo (path: string) {
46 const res = await makeActivityPubGetRequest(servers[0].url, path)
47 const object = res.body
49 expect(object.type).to.equal('Video')
50 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
51 expect(object.name).to.equal('video')
54 async function testPlaylist (path: string) {
55 const res = await makeActivityPubGetRequest(servers[0].url, path)
56 const object = res.body
58 expect(object.type).to.equal('Playlist')
59 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
60 expect(object.name).to.equal('playlist')
63 before(async function () {
66 servers = await flushAndRunMultipleServers(2)
68 await setAccessTokensToServers(servers)
69 await setDefaultVideoChannel(servers)
72 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
76 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
77 playlist = await servers[0].playlistsCommand.create({ attributes })
80 await doubleFollow(servers[0], servers[1])
83 it('Should return the account object', async function () {
84 await testAccount('/accounts/root')
85 await testAccount('/a/root')
88 it('Should return the channel object', async function () {
89 await testChannel('/video-channels/root_channel')
90 await testChannel('/c/root_channel')
93 it('Should return the video object', async function () {
94 await testVideo('/videos/watch/' + video.id)
95 await testVideo('/videos/watch/' + video.uuid)
96 await testVideo('/videos/watch/' + video.shortUUID)
97 await testVideo('/w/' + video.id)
98 await testVideo('/w/' + video.uuid)
99 await testVideo('/w/' + video.shortUUID)
102 it('Should return the playlist object', async function () {
103 await testPlaylist('/video-playlists/' + playlist.id)
104 await testPlaylist('/video-playlists/' + playlist.uuid)
105 await testPlaylist('/video-playlists/' + playlist.shortUUID)
106 await testPlaylist('/w/p/' + playlist.id)
107 await testPlaylist('/w/p/' + playlist.uuid)
108 await testPlaylist('/w/p/' + playlist.shortUUID)
109 await testPlaylist('/videos/watch/playlist/' + playlist.id)
110 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
111 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
114 it('Should redirect to the origin video object', async function () {
115 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
117 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
120 after(async function () {
121 await cleanupTests(servers)