2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2017-11-30 12:00:40 +01:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-06-28 17:30:59 +02:00
|
|
|
import * as chai from 'chai'
|
|
|
|
import { VideoPlaylistPrivacy } from '@shared/models'
|
|
|
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
2018-11-30 15:06:06 +01:00
|
|
|
import {
|
2019-04-26 08:50:52 +02:00
|
|
|
cleanupTests,
|
2018-11-30 15:06:06 +01:00
|
|
|
doubleFollow,
|
|
|
|
flushAndRunMultipleServers,
|
|
|
|
makeActivityPubGetRequest,
|
|
|
|
ServerInfo,
|
2018-12-07 16:09:57 +01:00
|
|
|
setAccessTokensToServers,
|
2021-06-28 17:30:59 +02:00
|
|
|
setDefaultVideoChannel,
|
|
|
|
uploadVideoAndGetId
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../../shared/extra-utils'
|
2017-11-30 12:00:40 +01:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test activitypub', function () {
|
2018-11-30 15:06:06 +01:00
|
|
|
let servers: ServerInfo[] = []
|
2021-06-28 17:30:59 +02:00
|
|
|
let video: { id: number, uuid: string, shortUUID: string }
|
|
|
|
let playlist: { id: number, uuid: string, shortUUID: string }
|
|
|
|
|
|
|
|
async function testAccount (path: string) {
|
|
|
|
const res = await makeActivityPubGetRequest(servers[0].url, path)
|
|
|
|
const object = res.body
|
|
|
|
|
|
|
|
expect(object.type).to.equal('Person')
|
|
|
|
expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
|
|
|
|
expect(object.name).to.equal('root')
|
|
|
|
expect(object.preferredUsername).to.equal('root')
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testChannel (path: string) {
|
|
|
|
const res = await makeActivityPubGetRequest(servers[0].url, path)
|
|
|
|
const object = res.body
|
|
|
|
|
|
|
|
expect(object.type).to.equal('Group')
|
|
|
|
expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
|
|
|
|
expect(object.name).to.equal('Main root channel')
|
|
|
|
expect(object.preferredUsername).to.equal('root_channel')
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testVideo (path: string) {
|
|
|
|
const res = await makeActivityPubGetRequest(servers[0].url, path)
|
|
|
|
const object = res.body
|
|
|
|
|
|
|
|
expect(object.type).to.equal('Video')
|
|
|
|
expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
|
|
|
|
expect(object.name).to.equal('video')
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testPlaylist (path: string) {
|
|
|
|
const res = await makeActivityPubGetRequest(servers[0].url, path)
|
|
|
|
const object = res.body
|
|
|
|
|
|
|
|
expect(object.type).to.equal('Playlist')
|
|
|
|
expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
|
|
|
|
expect(object.name).to.equal('playlist')
|
|
|
|
}
|
2017-11-30 12:00:40 +01:00
|
|
|
|
|
|
|
before(async function () {
|
2018-01-18 18:10:45 +01:00
|
|
|
this.timeout(30000)
|
2017-11-30 12:00:40 +01:00
|
|
|
|
2018-11-30 15:06:06 +01:00
|
|
|
servers = await flushAndRunMultipleServers(2)
|
2017-11-30 12:00:40 +01:00
|
|
|
|
2018-11-30 15:06:06 +01:00
|
|
|
await setAccessTokensToServers(servers)
|
2021-06-28 17:30:59 +02:00
|
|
|
await setDefaultVideoChannel(servers)
|
2018-11-30 15:06:06 +01:00
|
|
|
|
|
|
|
{
|
2021-06-28 17:30:59 +02:00
|
|
|
video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-08 15:54:39 +02:00
|
|
|
const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
|
|
|
|
playlist = await servers[0].playlistsCommand.create({ attributes })
|
2018-11-30 15:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-11-30 12:00:40 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return the account object', async function () {
|
2021-06-28 17:30:59 +02:00
|
|
|
await testAccount('/accounts/root')
|
|
|
|
await testAccount('/a/root')
|
|
|
|
})
|
2017-11-30 12:00:40 +01:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
it('Should return the channel object', async function () {
|
|
|
|
await testChannel('/video-channels/root_channel')
|
|
|
|
await testChannel('/c/root_channel')
|
2017-11-30 12:00:40 +01:00
|
|
|
})
|
|
|
|
|
2018-11-30 15:06:06 +01:00
|
|
|
it('Should return the video object', async function () {
|
2021-06-28 17:30:59 +02:00
|
|
|
await testVideo('/videos/watch/' + video.id)
|
|
|
|
await testVideo('/videos/watch/' + video.uuid)
|
|
|
|
await testVideo('/videos/watch/' + video.shortUUID)
|
|
|
|
await testVideo('/w/' + video.id)
|
|
|
|
await testVideo('/w/' + video.uuid)
|
|
|
|
await testVideo('/w/' + video.shortUUID)
|
|
|
|
})
|
2018-11-30 15:06:06 +01:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
it('Should return the playlist object', async function () {
|
|
|
|
await testPlaylist('/video-playlists/' + playlist.id)
|
|
|
|
await testPlaylist('/video-playlists/' + playlist.uuid)
|
|
|
|
await testPlaylist('/video-playlists/' + playlist.shortUUID)
|
|
|
|
await testPlaylist('/w/p/' + playlist.id)
|
|
|
|
await testPlaylist('/w/p/' + playlist.uuid)
|
|
|
|
await testPlaylist('/w/p/' + playlist.shortUUID)
|
|
|
|
await testPlaylist('/videos/watch/playlist/' + playlist.id)
|
|
|
|
await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
|
|
|
|
await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
|
2018-11-30 15:06:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should redirect to the origin video object', async function () {
|
2021-06-28 17:30:59 +02:00
|
|
|
const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
|
2018-11-30 15:06:06 +01:00
|
|
|
|
2021-06-28 17:30:59 +02:00
|
|
|
expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
|
2018-11-30 15:06:06 +01:00
|
|
|
})
|
|
|
|
|
2019-04-26 08:50:52 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2017-11-30 12:00:40 +01:00
|
|
|
})
|
|
|
|
})
|