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