]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6cbdbdef | 2 | |
6cbdbdef | 3 | import 'mocha' |
d4a8e7a6 | 4 | import * as chai from 'chai' |
1a8dd4da | 5 | import { |
48f07b4a | 6 | cleanupTests, |
254d3579 | 7 | createMultipleServers, |
4c7e60bc | 8 | doubleFollow, |
1a8dd4da | 9 | makeActivityPubGetRequest, |
254d3579 | 10 | PeerTubeServer, |
2a8c5d0a | 11 | setAccessTokensToServers, |
d23dd9fb | 12 | setDefaultVideoChannel |
bf54587a | 13 | } from '@shared/server-commands' |
4c7e60bc | 14 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' |
6cbdbdef C |
15 | |
16 | const expect = chai.expect | |
17 | ||
18 | describe('Test activitypub', function () { | |
254d3579 | 19 | let servers: PeerTubeServer[] = [] |
d4a8e7a6 C |
20 | let video: { id: number, uuid: string, shortUUID: string } |
21 | let playlist: { id: number, uuid: string, shortUUID: string } | |
22 | ||
23 | async function testAccount (path: string) { | |
24 | const res = await makeActivityPubGetRequest(servers[0].url, path) | |
25 | const object = res.body | |
26 | ||
27 | expect(object.type).to.equal('Person') | |
28 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') | |
29 | expect(object.name).to.equal('root') | |
30 | expect(object.preferredUsername).to.equal('root') | |
31 | } | |
32 | ||
33 | async function testChannel (path: string) { | |
34 | const res = await makeActivityPubGetRequest(servers[0].url, path) | |
35 | const object = res.body | |
36 | ||
37 | expect(object.type).to.equal('Group') | |
38 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel') | |
39 | expect(object.name).to.equal('Main root channel') | |
40 | expect(object.preferredUsername).to.equal('root_channel') | |
41 | } | |
42 | ||
43 | async function testVideo (path: string) { | |
44 | const res = await makeActivityPubGetRequest(servers[0].url, path) | |
45 | const object = res.body | |
46 | ||
47 | expect(object.type).to.equal('Video') | |
48 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) | |
49 | expect(object.name).to.equal('video') | |
50 | } | |
51 | ||
52 | async function testPlaylist (path: string) { | |
53 | const res = await makeActivityPubGetRequest(servers[0].url, path) | |
54 | const object = res.body | |
55 | ||
56 | expect(object.type).to.equal('Playlist') | |
57 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid) | |
58 | expect(object.name).to.equal('playlist') | |
59 | } | |
6cbdbdef C |
60 | |
61 | before(async function () { | |
e212f887 | 62 | this.timeout(30000) |
6cbdbdef | 63 | |
254d3579 | 64 | servers = await createMultipleServers(2) |
6cbdbdef | 65 | |
1a8dd4da | 66 | await setAccessTokensToServers(servers) |
d4a8e7a6 | 67 | await setDefaultVideoChannel(servers) |
1a8dd4da C |
68 | |
69 | { | |
c0e8b12e | 70 | video = await servers[0].videos.quickUpload({ name: 'video' }) |
d4a8e7a6 C |
71 | } |
72 | ||
73 | { | |
89d241a7 C |
74 | const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id } |
75 | playlist = await servers[0].playlists.create({ attributes }) | |
1a8dd4da C |
76 | } |
77 | ||
78 | await doubleFollow(servers[0], servers[1]) | |
6cbdbdef C |
79 | }) |
80 | ||
81 | it('Should return the account object', async function () { | |
d4a8e7a6 C |
82 | await testAccount('/accounts/root') |
83 | await testAccount('/a/root') | |
84 | }) | |
6cbdbdef | 85 | |
d4a8e7a6 C |
86 | it('Should return the channel object', async function () { |
87 | await testChannel('/video-channels/root_channel') | |
88 | await testChannel('/c/root_channel') | |
6cbdbdef C |
89 | }) |
90 | ||
1a8dd4da | 91 | it('Should return the video object', async function () { |
d4a8e7a6 C |
92 | await testVideo('/videos/watch/' + video.id) |
93 | await testVideo('/videos/watch/' + video.uuid) | |
94 | await testVideo('/videos/watch/' + video.shortUUID) | |
95 | await testVideo('/w/' + video.id) | |
96 | await testVideo('/w/' + video.uuid) | |
97 | await testVideo('/w/' + video.shortUUID) | |
98 | }) | |
1a8dd4da | 99 | |
d4a8e7a6 C |
100 | it('Should return the playlist object', async function () { |
101 | await testPlaylist('/video-playlists/' + playlist.id) | |
102 | await testPlaylist('/video-playlists/' + playlist.uuid) | |
103 | await testPlaylist('/video-playlists/' + playlist.shortUUID) | |
104 | await testPlaylist('/w/p/' + playlist.id) | |
105 | await testPlaylist('/w/p/' + playlist.uuid) | |
106 | await testPlaylist('/w/p/' + playlist.shortUUID) | |
107 | await testPlaylist('/videos/watch/playlist/' + playlist.id) | |
108 | await testPlaylist('/videos/watch/playlist/' + playlist.uuid) | |
109 | await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID) | |
1a8dd4da C |
110 | }) |
111 | ||
112 | it('Should redirect to the origin video object', async function () { | |
d4a8e7a6 | 113 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) |
1a8dd4da | 114 | |
d4a8e7a6 | 115 | expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) |
1a8dd4da C |
116 | }) |
117 | ||
48f07b4a C |
118 | after(async function () { |
119 | await cleanupTests(servers) | |
6cbdbdef C |
120 | }) |
121 | }) |