]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/activitypub/client.ts
Introduce channels command
[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 { VideoPlaylistPrivacy } from '@shared/models'
6 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7 import {
8 cleanupTests,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 makeActivityPubGetRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
15 uploadVideoAndGetId
16 } from '../../../../shared/extra-utils'
17
18 const expect = chai.expect
19
20 describe('Test activitypub', function () {
21 let servers: ServerInfo[] = []
22 let video: { id: number, uuid: string, shortUUID: string }
23 let playlist: { id: number, uuid: string, shortUUID: string }
24
25 async function testAccount (path: string) {
26 const res = await makeActivityPubGetRequest(servers[0].url, path)
27 const object = res.body
28
29 expect(object.type).to.equal('Person')
30 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
31 expect(object.name).to.equal('root')
32 expect(object.preferredUsername).to.equal('root')
33 }
34
35 async function testChannel (path: string) {
36 const res = await makeActivityPubGetRequest(servers[0].url, path)
37 const object = res.body
38
39 expect(object.type).to.equal('Group')
40 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
41 expect(object.name).to.equal('Main root channel')
42 expect(object.preferredUsername).to.equal('root_channel')
43 }
44
45 async function testVideo (path: string) {
46 const res = await makeActivityPubGetRequest(servers[0].url, path)
47 const object = res.body
48
49 expect(object.type).to.equal('Video')
50 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
51 expect(object.name).to.equal('video')
52 }
53
54 async function testPlaylist (path: string) {
55 const res = await makeActivityPubGetRequest(servers[0].url, path)
56 const object = res.body
57
58 expect(object.type).to.equal('Playlist')
59 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
60 expect(object.name).to.equal('playlist')
61 }
62
63 before(async function () {
64 this.timeout(30000)
65
66 servers = await flushAndRunMultipleServers(2)
67
68 await setAccessTokensToServers(servers)
69 await setDefaultVideoChannel(servers)
70
71 {
72 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
73 }
74
75 {
76 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
77 playlist = await servers[0].playlistsCommand.create({ attributes })
78 }
79
80 await doubleFollow(servers[0], servers[1])
81 })
82
83 it('Should return the account object', async function () {
84 await testAccount('/accounts/root')
85 await testAccount('/a/root')
86 })
87
88 it('Should return the channel object', async function () {
89 await testChannel('/video-channels/root_channel')
90 await testChannel('/c/root_channel')
91 })
92
93 it('Should return the video object', async function () {
94 await testVideo('/videos/watch/' + video.id)
95 await testVideo('/videos/watch/' + video.uuid)
96 await testVideo('/videos/watch/' + video.shortUUID)
97 await testVideo('/w/' + video.id)
98 await testVideo('/w/' + video.uuid)
99 await testVideo('/w/' + video.shortUUID)
100 })
101
102 it('Should return the playlist object', async function () {
103 await testPlaylist('/video-playlists/' + playlist.id)
104 await testPlaylist('/video-playlists/' + playlist.uuid)
105 await testPlaylist('/video-playlists/' + playlist.shortUUID)
106 await testPlaylist('/w/p/' + playlist.id)
107 await testPlaylist('/w/p/' + playlist.uuid)
108 await testPlaylist('/w/p/' + playlist.shortUUID)
109 await testPlaylist('/videos/watch/playlist/' + playlist.id)
110 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
111 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
112 })
113
114 it('Should redirect to the origin video object', async function () {
115 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
116
117 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
118 })
119
120 after(async function () {
121 await cleanupTests(servers)
122 })
123 })