]>
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' |
b2111066 C |
5 | import { processViewersStats } from '@server/tests/shared' |
6 | import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models' | |
1a8dd4da | 7 | import { |
48f07b4a | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
1a8dd4da | 11 | makeActivityPubGetRequest, |
254d3579 | 12 | PeerTubeServer, |
2a8c5d0a | 13 | setAccessTokensToServers, |
d23dd9fb | 14 | setDefaultVideoChannel |
bf54587a | 15 | } from '@shared/server-commands' |
6cbdbdef C |
16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test activitypub', function () { | |
254d3579 | 20 | let servers: PeerTubeServer[] = [] |
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 | |
254d3579 | 65 | servers = await createMultipleServers(2) |
6cbdbdef | 66 | |
1a8dd4da | 67 | await setAccessTokensToServers(servers) |
d4a8e7a6 | 68 | await setDefaultVideoChannel(servers) |
1a8dd4da C |
69 | |
70 | { | |
c0e8b12e | 71 | video = 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 | ||
b2111066 C |
119 | it('Should return the watch action', async function () { |
120 | this.timeout(50000) | |
121 | ||
122 | await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] }) | |
123 | await processViewersStats(servers) | |
124 | ||
125 | const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200) | |
126 | ||
127 | const object: WatchActionObject = res.body | |
128 | expect(object.type).to.equal('WatchAction') | |
129 | expect(object.duration).to.equal('PT2S') | |
130 | expect(object.actionStatus).to.equal('CompletedActionStatus') | |
131 | expect(object.watchSections).to.have.lengthOf(1) | |
132 | expect(object.watchSections[0].startTimestamp).to.equal(0) | |
133 | expect(object.watchSections[0].endTimestamp).to.equal(2) | |
134 | }) | |
135 | ||
48f07b4a C |
136 | after(async function () { |
137 | await cleanupTests(servers) | |
6cbdbdef C |
138 | }) |
139 | }) |