aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r--server/tests/api/activitypub/client.ts98
1 files changed, 79 insertions, 19 deletions
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index b6c538e19..be94e219c 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -1,23 +1,65 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { 7import {
6 cleanupTests, 8 cleanupTests,
9 createVideoPlaylist,
7 doubleFollow, 10 doubleFollow,
8 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
9 makeActivityPubGetRequest, 12 makeActivityPubGetRequest,
10 ServerInfo, 13 ServerInfo,
11 setAccessTokensToServers, 14 setAccessTokensToServers,
12 uploadVideo 15 setDefaultVideoChannel,
16 uploadVideoAndGetId
13} from '../../../../shared/extra-utils' 17} from '../../../../shared/extra-utils'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 18
16const expect = chai.expect 19const expect = chai.expect
17 20
18describe('Test activitypub', function () { 21describe('Test activitypub', function () {
19 let servers: ServerInfo[] = [] 22 let servers: ServerInfo[] = []
20 let videoUUID: string 23 let video: { id: number, uuid: string, shortUUID: string }
24 let playlist: { id: number, uuid: string, shortUUID: string }
25
26 async function testAccount (path: string) {
27 const res = await makeActivityPubGetRequest(servers[0].url, path)
28 const object = res.body
29
30 expect(object.type).to.equal('Person')
31 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root')
32 expect(object.name).to.equal('root')
33 expect(object.preferredUsername).to.equal('root')
34 }
35
36 async function testChannel (path: string) {
37 const res = await makeActivityPubGetRequest(servers[0].url, path)
38 const object = res.body
39
40 expect(object.type).to.equal('Group')
41 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel')
42 expect(object.name).to.equal('Main root channel')
43 expect(object.preferredUsername).to.equal('root_channel')
44 }
45
46 async function testVideo (path: string) {
47 const res = await makeActivityPubGetRequest(servers[0].url, path)
48 const object = res.body
49
50 expect(object.type).to.equal('Video')
51 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
52 expect(object.name).to.equal('video')
53 }
54
55 async function testPlaylist (path: string) {
56 const res = await makeActivityPubGetRequest(servers[0].url, path)
57 const object = res.body
58
59 expect(object.type).to.equal('Playlist')
60 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid)
61 expect(object.name).to.equal('playlist')
62 }
21 63
22 before(async function () { 64 before(async function () {
23 this.timeout(30000) 65 this.timeout(30000)
@@ -25,38 +67,56 @@ describe('Test activitypub', function () {
25 servers = await flushAndRunMultipleServers(2) 67 servers = await flushAndRunMultipleServers(2)
26 68
27 await setAccessTokensToServers(servers) 69 await setAccessTokensToServers(servers)
70 await setDefaultVideoChannel(servers)
28 71
29 { 72 {
30 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 73 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
31 videoUUID = res.body.video.uuid 74 }
75
76 {
77 const playlistAttrs = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
78 const resCreate = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
79 playlist = resCreate.body.videoPlaylist
32 } 80 }
33 81
34 await doubleFollow(servers[0], servers[1]) 82 await doubleFollow(servers[0], servers[1])
35 }) 83 })
36 84
37 it('Should return the account object', async function () { 85 it('Should return the account object', async function () {
38 const res = await makeActivityPubGetRequest(servers[0].url, '/accounts/root') 86 await testAccount('/accounts/root')
39 const object = res.body 87 await testAccount('/a/root')
88 })
40 89
41 expect(object.type).to.equal('Person') 90 it('Should return the channel object', async function () {
42 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') 91 await testChannel('/video-channels/root_channel')
43 expect(object.name).to.equal('root') 92 await testChannel('/c/root_channel')
44 expect(object.preferredUsername).to.equal('root')
45 }) 93 })
46 94
47 it('Should return the video object', async function () { 95 it('Should return the video object', async function () {
48 const res = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID) 96 await testVideo('/videos/watch/' + video.id)
49 const object = res.body 97 await testVideo('/videos/watch/' + video.uuid)
98 await testVideo('/videos/watch/' + video.shortUUID)
99 await testVideo('/w/' + video.id)
100 await testVideo('/w/' + video.uuid)
101 await testVideo('/w/' + video.shortUUID)
102 })
50 103
51 expect(object.type).to.equal('Video') 104 it('Should return the playlist object', async function () {
52 expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) 105 await testPlaylist('/video-playlists/' + playlist.id)
53 expect(object.name).to.equal('video') 106 await testPlaylist('/video-playlists/' + playlist.uuid)
107 await testPlaylist('/video-playlists/' + playlist.shortUUID)
108 await testPlaylist('/w/p/' + playlist.id)
109 await testPlaylist('/w/p/' + playlist.uuid)
110 await testPlaylist('/w/p/' + playlist.shortUUID)
111 await testPlaylist('/videos/watch/playlist/' + playlist.id)
112 await testPlaylist('/videos/watch/playlist/' + playlist.uuid)
113 await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID)
54 }) 114 })
55 115
56 it('Should redirect to the origin video object', async function () { 116 it('Should redirect to the origin video object', async function () {
57 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, HttpStatusCode.FOUND_302) 117 const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302)
58 118
59 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) 119 expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid)
60 }) 120 })
61 121
62 after(async function () { 122 after(async function () {