diff options
Diffstat (limited to 'server/tests/api/activitypub/client.ts')
-rw-r--r-- | server/tests/api/activitypub/client.ts | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts deleted file mode 100644 index 572a358a0..000000000 --- a/server/tests/api/activitypub/client.ts +++ /dev/null | |||
@@ -1,136 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { processViewersStats } from '@server/tests/shared' | ||
5 | import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | makeActivityPubGetRequest, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers, | ||
13 | setDefaultVideoChannel | ||
14 | } from '@shared/server-commands' | ||
15 | |||
16 | describe('Test activitypub', function () { | ||
17 | let servers: PeerTubeServer[] = [] | ||
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(servers[0].url + '/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(servers[0].url + '/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(servers[0].url + '/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(servers[0].url + '/video-playlists/' + playlist.uuid) | ||
56 | expect(object.name).to.equal('playlist') | ||
57 | } | ||
58 | |||
59 | before(async function () { | ||
60 | this.timeout(30000) | ||
61 | |||
62 | servers = await createMultipleServers(2) | ||
63 | |||
64 | await setAccessTokensToServers(servers) | ||
65 | await setDefaultVideoChannel(servers) | ||
66 | |||
67 | { | ||
68 | video = await servers[0].videos.quickUpload({ name: 'video' }) | ||
69 | } | ||
70 | |||
71 | { | ||
72 | const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id } | ||
73 | playlist = await servers[0].playlists.create({ attributes }) | ||
74 | } | ||
75 | |||
76 | await doubleFollow(servers[0], servers[1]) | ||
77 | }) | ||
78 | |||
79 | it('Should return the account object', async function () { | ||
80 | await testAccount('/accounts/root') | ||
81 | await testAccount('/a/root') | ||
82 | }) | ||
83 | |||
84 | it('Should return the channel object', async function () { | ||
85 | await testChannel('/video-channels/root_channel') | ||
86 | await testChannel('/c/root_channel') | ||
87 | }) | ||
88 | |||
89 | it('Should return the video object', async function () { | ||
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 | }) | ||
97 | |||
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) | ||
108 | }) | ||
109 | |||
110 | it('Should redirect to the origin video object', async function () { | ||
111 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) | ||
112 | |||
113 | expect(res.header.location).to.equal(servers[0].url + '/videos/watch/' + video.uuid) | ||
114 | }) | ||
115 | |||
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 | |||
133 | after(async function () { | ||
134 | await cleanupTests(servers) | ||
135 | }) | ||
136 | }) | ||