]>
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' |
d23dd9fb | 5 | import { HttpStatusCode } from '@shared/core-utils' |
1a8dd4da | 6 | import { |
48f07b4a | 7 | cleanupTests, |
1a8dd4da C |
8 | doubleFollow, |
9 | flushAndRunMultipleServers, | |
1a8dd4da | 10 | makeActivityPubGetRequest, |
1a8dd4da | 11 | ServerInfo, |
2a8c5d0a | 12 | setAccessTokensToServers, |
d23dd9fb C |
13 | setDefaultVideoChannel |
14 | } from '@shared/extra-utils' | |
15 | import { VideoPlaylistPrivacy } from '@shared/models' | |
6cbdbdef C |
16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test activitypub', function () { | |
1a8dd4da | 20 | let servers: ServerInfo[] = [] |
d4a8e7a6 C |
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 | } | |
6cbdbdef C |
61 | |
62 | before(async function () { | |
e212f887 | 63 | this.timeout(30000) |
6cbdbdef | 64 | |
1a8dd4da | 65 | servers = await flushAndRunMultipleServers(2) |
6cbdbdef | 66 | |
1a8dd4da | 67 | await setAccessTokensToServers(servers) |
d4a8e7a6 | 68 | await setDefaultVideoChannel(servers) |
1a8dd4da C |
69 | |
70 | { | |
89d241a7 | 71 | video = await await servers[0].videos.quickUpload({ name: 'video' }) |
d4a8e7a6 C |
72 | } |
73 | ||
74 | { | |
89d241a7 C |
75 | const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id } |
76 | playlist = await servers[0].playlists.create({ attributes }) | |
1a8dd4da C |
77 | } |
78 | ||
79 | await doubleFollow(servers[0], servers[1]) | |
6cbdbdef C |
80 | }) |
81 | ||
82 | it('Should return the account object', async function () { | |
d4a8e7a6 C |
83 | await testAccount('/accounts/root') |
84 | await testAccount('/a/root') | |
85 | }) | |
6cbdbdef | 86 | |
d4a8e7a6 C |
87 | it('Should return the channel object', async function () { |
88 | await testChannel('/video-channels/root_channel') | |
89 | await testChannel('/c/root_channel') | |
6cbdbdef C |
90 | }) |
91 | ||
1a8dd4da | 92 | it('Should return the video object', async function () { |
d4a8e7a6 C |
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 | }) | |
1a8dd4da | 100 | |
d4a8e7a6 C |
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) | |
1a8dd4da C |
111 | }) |
112 | ||
113 | it('Should redirect to the origin video object', async function () { | |
d4a8e7a6 | 114 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) |
1a8dd4da | 115 | |
d4a8e7a6 | 116 | expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) |
1a8dd4da C |
117 | }) |
118 | ||
48f07b4a C |
119 | after(async function () { |
120 | await cleanupTests(servers) | |
6cbdbdef C |
121 | }) |
122 | }) |