2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2017-11-30 05:00:40 -06:00
|
|
|
|
2022-08-17 08:44:32 -05:00
|
|
|
import { expect } from 'chai'
|
2022-03-24 07:36:47 -05:00
|
|
|
import { processViewersStats } from '@server/tests/shared'
|
|
|
|
import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
|
2018-11-30 08:06:06 -06:00
|
|
|
import {
|
2019-04-26 01:50:52 -05:00
|
|
|
cleanupTests,
|
2021-07-16 02:47:51 -05:00
|
|
|
createMultipleServers,
|
2021-07-16 07:27:30 -05:00
|
|
|
doubleFollow,
|
2018-11-30 08:06:06 -06:00
|
|
|
makeActivityPubGetRequest,
|
2021-07-16 02:47:51 -05:00
|
|
|
PeerTubeServer,
|
2018-12-07 09:09:57 -06:00
|
|
|
setAccessTokensToServers,
|
2021-07-15 03:02:54 -05:00
|
|
|
setDefaultVideoChannel
|
2021-12-17 02:29:23 -06:00
|
|
|
} from '@shared/server-commands'
|
2017-11-30 05:00:40 -06:00
|
|
|
|
|
|
|
describe('Test activitypub', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
let servers: PeerTubeServer[] = []
|
2021-06-28 10:30:59 -05: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')
|
2022-12-09 04:14:47 -06:00
|
|
|
expect(object.id).to.equal(servers[0].url + '/accounts/root')
|
2021-06-28 10:30:59 -05:00
|
|
|
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')
|
2022-12-09 04:14:47 -06:00
|
|
|
expect(object.id).to.equal(servers[0].url + '/video-channels/root_channel')
|
2021-06-28 10:30:59 -05:00
|
|
|
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')
|
2022-12-09 04:14:47 -06:00
|
|
|
expect(object.id).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
|
2021-06-28 10:30:59 -05:00
|
|
|
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')
|
2022-12-09 04:14:47 -06:00
|
|
|
expect(object.id).to.equal(servers[0].url + '/video-playlists/' + playlist.uuid)
|
2021-06-28 10:30:59 -05:00
|
|
|
expect(object.name).to.equal('playlist')
|
|
|
|
}
|
2017-11-30 05:00:40 -06:00
|
|
|
|
|
|
|
before(async function () {
|
2018-01-18 11:10:45 -06:00
|
|
|
this.timeout(30000)
|
2017-11-30 05:00:40 -06:00
|
|
|
|
2021-07-16 02:47:51 -05:00
|
|
|
servers = await createMultipleServers(2)
|
2017-11-30 05:00:40 -06:00
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
await setAccessTokensToServers(servers)
|
2021-06-28 10:30:59 -05:00
|
|
|
await setDefaultVideoChannel(servers)
|
2018-11-30 08:06:06 -06:00
|
|
|
|
|
|
|
{
|
2021-07-16 03:42:24 -05:00
|
|
|
video = await servers[0].videos.quickUpload({ name: 'video' })
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 02:04:35 -05:00
|
|
|
const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
|
|
|
|
playlist = await servers[0].playlists.create({ attributes })
|
2018-11-30 08:06:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-11-30 05:00:40 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should return the account object', async function () {
|
2021-06-28 10:30:59 -05:00
|
|
|
await testAccount('/accounts/root')
|
|
|
|
await testAccount('/a/root')
|
|
|
|
})
|
2017-11-30 05:00:40 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should return the channel object', async function () {
|
|
|
|
await testChannel('/video-channels/root_channel')
|
|
|
|
await testChannel('/c/root_channel')
|
2017-11-30 05:00:40 -06:00
|
|
|
})
|
|
|
|
|
2018-11-30 08:06:06 -06:00
|
|
|
it('Should return the video object', async function () {
|
2021-06-28 10:30:59 -05: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 08:06:06 -06:00
|
|
|
|
2021-06-28 10:30:59 -05: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 08:06:06 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should redirect to the origin video object', async function () {
|
2021-06-28 10:30:59 -05:00
|
|
|
const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
|
2018-11-30 08:06:06 -06:00
|
|
|
|
2022-12-09 04:14:47 -06:00
|
|
|
expect(res.header.location).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
|
2018-11-30 08:06:06 -06:00
|
|
|
})
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
it('Should return the watch action', async function () {
|
|
|
|
this.timeout(50000)
|
|
|
|
|
|
|
|
await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
|
|
|
|
await processViewersStats(servers)
|
|
|
|
|
|
|
|
const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
|
|
|
|
|
|
|
|
const object: WatchActionObject = res.body
|
|
|
|
expect(object.type).to.equal('WatchAction')
|
|
|
|
expect(object.duration).to.equal('PT2S')
|
|
|
|
expect(object.actionStatus).to.equal('CompletedActionStatus')
|
|
|
|
expect(object.watchSections).to.have.lengthOf(1)
|
|
|
|
expect(object.watchSections[0].startTimestamp).to.equal(0)
|
|
|
|
expect(object.watchSections[0].endTimestamp).to.equal(2)
|
|
|
|
})
|
|
|
|
|
2019-04-26 01:50:52 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2017-11-30 05:00:40 -06:00
|
|
|
})
|
|
|
|
})
|