]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/client.ts
5845045a362676063e990199626b07713fdaab27
[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 { HttpStatusCode } from '@shared/core-utils'
6 import {
7 cleanupTests,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 makeActivityPubGetRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14 } from '@shared/extra-utils'
15 import { VideoPlaylistPrivacy } from '@shared/models'
16
17 const expect = chai.expect
18
19 describe('Test activitypub', function () {
20 let servers: ServerInfo[] = []
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 flushAndRunMultipleServers(2)
66
67 await setAccessTokensToServers(servers)
68 await setDefaultVideoChannel(servers)
69
70 {
71 video = await 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 after(async function () {
120 await cleanupTests(servers)
121 })
122 })