1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { processViewersStats } from '@server/tests/shared'
5 import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
10 makeActivityPubGetRequest,
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14 } from '@shared/server-commands'
16 describe('Test activitypub', function () {
17 let servers: PeerTubeServer[] = []
18 let video: { id: number, uuid: string, shortUUID: string }
19 let playlist: { id: number, uuid: string, shortUUID: string }
21 async function testAccount (path: string) {
22 const res = await makeActivityPubGetRequest(servers[0].url, path)
23 const object = res.body
25 expect(object.type).to.equal('Person')
26 expect(object.id).to.equal(servers[0].url + '/accounts/root')
27 expect(object.name).to.equal('root')
28 expect(object.preferredUsername).to.equal('root')
31 async function testChannel (path: string) {
32 const res = await makeActivityPubGetRequest(servers[0].url, path)
33 const object = res.body
35 expect(object.type).to.equal('Group')
36 expect(object.id).to.equal(servers[0].url + '/video-channels/root_channel')
37 expect(object.name).to.equal('Main root channel')
38 expect(object.preferredUsername).to.equal('root_channel')
41 async function testVideo (path: string) {
42 const res = await makeActivityPubGetRequest(servers[0].url, path)
43 const object = res.body
45 expect(object.type).to.equal('Video')
46 expect(object.id).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
47 expect(object.name).to.equal('video')
50 async function testPlaylist (path: string) {
51 const res = await makeActivityPubGetRequest(servers[0].url, path)
52 const object = res.body
54 expect(object.type).to.equal('Playlist')
55 expect(object.id).to.equal(servers[0].url + '/video-playlists/' + playlist.uuid)
56 expect(object.name).to.equal('playlist')
59 before(async function () {
62 servers = await createMultipleServers(2)
64 await setAccessTokensToServers(servers)
65 await setDefaultVideoChannel(servers)
68 video = await servers[0].videos.quickUpload({ name: 'video' })
72 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
73 playlist = await servers[0].playlists.create({ attributes })
76 await doubleFollow(servers[0], servers[1])
79 it('Should return the account object', async function () {
80 await testAccount('/accounts/root')
81 await testAccount('/a/root')
84 it('Should return the channel object', async function () {
85 await testChannel('/video-channels/root_channel')
86 await testChannel('/c/root_channel')
89 it('Should return the video object', async function () {
90 await testVideo('/videos/watch/' + video.id)
91 await testVideo('/videos/watch/' + video.uuid)
92 await testVideo('/videos/watch/' + video.shortUUID)
93 await testVideo('/w/' + video.id)
94 await testVideo('/w/' + video.uuid)
95 await testVideo('/w/' + video.shortUUID)
98 it('Should return the playlist object', async function () {
99 await testPlaylist('/video-playlists/' + playlist.id)
100 await testPlaylist('/video-playlists/' + playlist.uuid)
101 await testPlaylist('/video-playlists/' + playlist.shortUUID)
102 await testPlaylist('/w/p/' + playlist.id)
103 await testPlaylist('/w/p/' + playlist.uuid)
104 await testPlaylist('/w/p/' + playlist.shortUUID)
105 await testPlaylist('/videos/watch/playlist/' + playlist.id)
106 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
107 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
110 it('Should redirect to the origin video object', async function () {
111 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
113 expect(res.header.location).to.equal(servers[0].url + '/videos/watch/' + video.uuid)
116 it('Should return the watch action', async function () {
119 await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
120 await processViewersStats(servers)
122 const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
124 const object: WatchActionObject = res.body
125 expect(object.type).to.equal('WatchAction')
126 expect(object.duration).to.equal('PT2S')
127 expect(object.actionStatus).to.equal('CompletedActionStatus')
128 expect(object.watchSections).to.have.lengthOf(1)
129 expect(object.watchSections[0].startTimestamp).to.equal(0)
130 expect(object.watchSections[0].endTimestamp).to.equal(2)
133 after(async function () {
134 await cleanupTests(servers)