1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { processViewersStats } from '@server/tests/shared'
6 import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
11 makeActivityPubGetRequest,
13 setAccessTokensToServers,
14 setDefaultVideoChannel
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test activitypub', function () {
20 let servers: PeerTubeServer[] = []
21 let video: { id: number, uuid: string, shortUUID: string }
22 let playlist: { id: number, uuid: string, shortUUID: string }
24 async function testAccount (path: string) {
25 const res = await makeActivityPubGetRequest(servers[0].url, path)
26 const object = res.body
28 expect(object.type).to.equal('Person')
29 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
30 expect(object.name).to.equal('root')
31 expect(object.preferredUsername).to.equal('root')
34 async function testChannel (path: string) {
35 const res = await makeActivityPubGetRequest(servers[0].url, path)
36 const object = res.body
38 expect(object.type).to.equal('Group')
39 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
40 expect(object.name).to.equal('Main root channel')
41 expect(object.preferredUsername).to.equal('root_channel')
44 async function testVideo (path: string) {
45 const res = await makeActivityPubGetRequest(servers[0].url, path)
46 const object = res.body
48 expect(object.type).to.equal('Video')
49 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
50 expect(object.name).to.equal('video')
53 async function testPlaylist (path: string) {
54 const res = await makeActivityPubGetRequest(servers[0].url, path)
55 const object = res.body
57 expect(object.type).to.equal('Playlist')
58 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
59 expect(object.name).to.equal('playlist')
62 before(async function () {
65 servers = await createMultipleServers(2)
67 await setAccessTokensToServers(servers)
68 await setDefaultVideoChannel(servers)
71 video = await servers[0].videos.quickUpload({ name: 'video' })
75 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
76 playlist = await servers[0].playlists.create({ attributes })
79 await doubleFollow(servers[0], servers[1])
82 it('Should return the account object', async function () {
83 await testAccount('/accounts/root')
84 await testAccount('/a/root')
87 it('Should return the channel object', async function () {
88 await testChannel('/video-channels/root_channel')
89 await testChannel('/c/root_channel')
92 it('Should return the video object', async function () {
93 await testVideo('/videos/watch/' + video.id)
94 await testVideo('/videos/watch/' + video.uuid)
95 await testVideo('/videos/watch/' + video.shortUUID)
96 await testVideo('/w/' + video.id)
97 await testVideo('/w/' + video.uuid)
98 await testVideo('/w/' + video.shortUUID)
101 it('Should return the playlist object', async function () {
102 await testPlaylist('/video-playlists/' + playlist.id)
103 await testPlaylist('/video-playlists/' + playlist.uuid)
104 await testPlaylist('/video-playlists/' + playlist.shortUUID)
105 await testPlaylist('/w/p/' + playlist.id)
106 await testPlaylist('/w/p/' + playlist.uuid)
107 await testPlaylist('/w/p/' + playlist.shortUUID)
108 await testPlaylist('/videos/watch/playlist/' + playlist.id)
109 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
110 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
113 it('Should redirect to the origin video object', async function () {
114 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
116 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
119 it('Should return the watch action', async function () {
122 await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
123 await processViewersStats(servers)
125 const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
127 const object: WatchActionObject = res.body
128 expect(object.type).to.equal('WatchAction')
129 expect(object.duration).to.equal('PT2S')
130 expect(object.actionStatus).to.equal('CompletedActionStatus')
131 expect(object.watchSections).to.have.lengthOf(1)
132 expect(object.watchSections[0].startTimestamp).to.equal(0)
133 expect(object.watchSections[0].endTimestamp).to.equal(2)
136 after(async function () {
137 await cleanupTests(servers)