]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/client.ts
Add new player string to custom translations
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / client.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { processViewersStats } from '@server/tests/shared'
6 import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
7 import {
8 cleanupTests,
9 createMultipleServers,
10 doubleFollow,
11 makeActivityPubGetRequest,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 setDefaultVideoChannel
15 } from '@shared/server-commands'
16
17 const expect = chai.expect
18
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 }
23
24 async function testAccount (path: string) {
25 const res = await makeActivityPubGetRequest(servers[0].url, path)
26 const object = res.body
27
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')
32 }
33
34 async function testChannel (path: string) {
35 const res = await makeActivityPubGetRequest(servers[0].url, path)
36 const object = res.body
37
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')
42 }
43
44 async function testVideo (path: string) {
45 const res = await makeActivityPubGetRequest(servers[0].url, path)
46 const object = res.body
47
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')
51 }
52
53 async function testPlaylist (path: string) {
54 const res = await makeActivityPubGetRequest(servers[0].url, path)
55 const object = res.body
56
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')
60 }
61
62 before(async function () {
63 this.timeout(30000)
64
65 servers = await createMultipleServers(2)
66
67 await setAccessTokensToServers(servers)
68 await setDefaultVideoChannel(servers)
69
70 {
71 video = await servers[0].videos.quickUpload({ name: 'video' })
72 }
73
74 {
75 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
76 playlist = await servers[0].playlists.create({ attributes })
77 }
78
79 await doubleFollow(servers[0], servers[1])
80 })
81
82 it('Should return the account object', async function () {
83 await testAccount('/accounts/root')
84 await testAccount('/a/root')
85 })
86
87 it('Should return the channel object', async function () {
88 await testChannel('/video-channels/root_channel')
89 await testChannel('/c/root_channel')
90 })
91
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)
99 })
100
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)
111 })
112
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)
115
116 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
117 })
118
119 it('Should return the watch action', async function () {
120 this.timeout(50000)
121
122 await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] })
123 await processViewersStats(servers)
124
125 const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200)
126
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)
134 })
135
136 after(async function () {
137 await cleanupTests(servers)
138 })
139 })