]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/activitypub/client.ts
Introduce channels command
[github/Chocobozzz/PeerTube.git] / server / tests / api / activitypub / client.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6cbdbdef 2
6cbdbdef 3import 'mocha'
d4a8e7a6
C
4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
1a8dd4da 7import {
48f07b4a 8 cleanupTests,
1a8dd4da
C
9 doubleFollow,
10 flushAndRunMultipleServers,
1a8dd4da 11 makeActivityPubGetRequest,
1a8dd4da 12 ServerInfo,
2a8c5d0a 13 setAccessTokensToServers,
d4a8e7a6
C
14 setDefaultVideoChannel,
15 uploadVideoAndGetId
94565d52 16} from '../../../../shared/extra-utils'
6cbdbdef
C
17
18const expect = chai.expect
19
20describe('Test activitypub', function () {
1a8dd4da 21 let servers: ServerInfo[] = []
d4a8e7a6
C
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 }
6cbdbdef
C
62
63 before(async function () {
e212f887 64 this.timeout(30000)
6cbdbdef 65
1a8dd4da 66 servers = await flushAndRunMultipleServers(2)
6cbdbdef 67
1a8dd4da 68 await setAccessTokensToServers(servers)
d4a8e7a6 69 await setDefaultVideoChannel(servers)
1a8dd4da
C
70
71 {
d4a8e7a6
C
72 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
73 }
74
75 {
e6346d59
C
76 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
77 playlist = await servers[0].playlistsCommand.create({ attributes })
1a8dd4da
C
78 }
79
80 await doubleFollow(servers[0], servers[1])
6cbdbdef
C
81 })
82
83 it('Should return the account object', async function () {
d4a8e7a6
C
84 await testAccount('/accounts/root')
85 await testAccount('/a/root')
86 })
6cbdbdef 87
d4a8e7a6
C
88 it('Should return the channel object', async function () {
89 await testChannel('/video-channels/root_channel')
90 await testChannel('/c/root_channel')
6cbdbdef
C
91 })
92
1a8dd4da 93 it('Should return the video object', async function () {
d4a8e7a6
C
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 })
1a8dd4da 101
d4a8e7a6
C
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)
1a8dd4da
C
112 })
113
114 it('Should redirect to the origin video object', async function () {
d4a8e7a6 115 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
1a8dd4da 116
d4a8e7a6 117 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
1a8dd4da
C
118 })
119
48f07b4a
C
120 after(async function () {
121 await cleanupTests(servers)
6cbdbdef
C
122 })
123})