]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6cbdbdef | 2 | |
6cbdbdef | 3 | import 'mocha' |
d4a8e7a6 C |
4 | import * as chai from 'chai' |
5 | import { VideoPlaylistPrivacy } from '@shared/models' | |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
1a8dd4da | 7 | import { |
48f07b4a | 8 | cleanupTests, |
d4a8e7a6 | 9 | createVideoPlaylist, |
1a8dd4da C |
10 | doubleFollow, |
11 | flushAndRunMultipleServers, | |
1a8dd4da | 12 | makeActivityPubGetRequest, |
1a8dd4da | 13 | ServerInfo, |
2a8c5d0a | 14 | setAccessTokensToServers, |
d4a8e7a6 C |
15 | setDefaultVideoChannel, |
16 | uploadVideoAndGetId | |
94565d52 | 17 | } from '../../../../shared/extra-utils' |
6cbdbdef C |
18 | |
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test activitypub', function () { | |
1a8dd4da | 22 | let servers: ServerInfo[] = [] |
d4a8e7a6 C |
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 | } | |
6cbdbdef C |
63 | |
64 | before(async function () { | |
e212f887 | 65 | this.timeout(30000) |
6cbdbdef | 66 | |
1a8dd4da | 67 | servers = await flushAndRunMultipleServers(2) |
6cbdbdef | 68 | |
1a8dd4da | 69 | await setAccessTokensToServers(servers) |
d4a8e7a6 | 70 | await setDefaultVideoChannel(servers) |
1a8dd4da C |
71 | |
72 | { | |
d4a8e7a6 C |
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 | |
1a8dd4da C |
80 | } |
81 | ||
82 | await doubleFollow(servers[0], servers[1]) | |
6cbdbdef C |
83 | }) |
84 | ||
85 | it('Should return the account object', async function () { | |
d4a8e7a6 C |
86 | await testAccount('/accounts/root') |
87 | await testAccount('/a/root') | |
88 | }) | |
6cbdbdef | 89 | |
d4a8e7a6 C |
90 | it('Should return the channel object', async function () { |
91 | await testChannel('/video-channels/root_channel') | |
92 | await testChannel('/c/root_channel') | |
6cbdbdef C |
93 | }) |
94 | ||
1a8dd4da | 95 | it('Should return the video object', async function () { |
d4a8e7a6 C |
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 | }) | |
1a8dd4da | 103 | |
d4a8e7a6 C |
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) | |
1a8dd4da C |
114 | }) |
115 | ||
116 | it('Should redirect to the origin video object', async function () { | |
d4a8e7a6 | 117 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) |
1a8dd4da | 118 | |
d4a8e7a6 | 119 | expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) |
1a8dd4da C |
120 | }) |
121 | ||
48f07b4a C |
122 | after(async function () { |
123 | await cleanupTests(servers) | |
6cbdbdef C |
124 | }) |
125 | }) |