]>
Commit | Line | Data |
---|---|---|
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 | createVideoPlaylist, | |
10 | doubleFollow, | |
11 | flushAndRunMultipleServers, | |
12 | makeActivityPubGetRequest, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | setDefaultVideoChannel, | |
16 | uploadVideoAndGetId | |
17 | } from '../../../../shared/extra-utils' | |
18 | ||
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test activitypub', function () { | |
22 | let servers: ServerInfo[] = [] | |
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 | } | |
63 | ||
64 | before(async function () { | |
65 | this.timeout(30000) | |
66 | ||
67 | servers = await flushAndRunMultipleServers(2) | |
68 | ||
69 | await setAccessTokensToServers(servers) | |
70 | await setDefaultVideoChannel(servers) | |
71 | ||
72 | { | |
73 | video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) | |
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 | |
80 | } | |
81 | ||
82 | await doubleFollow(servers[0], servers[1]) | |
83 | }) | |
84 | ||
85 | it('Should return the account object', async function () { | |
86 | await testAccount('/accounts/root') | |
87 | await testAccount('/a/root') | |
88 | }) | |
89 | ||
90 | it('Should return the channel object', async function () { | |
91 | await testChannel('/video-channels/root_channel') | |
92 | await testChannel('/c/root_channel') | |
93 | }) | |
94 | ||
95 | it('Should return the video object', async function () { | |
96 | await testVideo('/videos/watch/' + video.id) | |
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 | }) | |
103 | ||
104 | it('Should return the playlist object', async function () { | |
105 | await testPlaylist('/video-playlists/' + playlist.id) | |
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) | |
114 | }) | |
115 | ||
116 | it('Should redirect to the origin video object', async function () { | |
117 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) | |
118 | ||
119 | expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) | |
120 | }) | |
121 | ||
122 | after(async function () { | |
123 | await cleanupTests(servers) | |
124 | }) | |
125 | }) |