aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub/client.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/activitypub/client.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/activitypub/client.ts')
-rw-r--r--server/tests/api/activitypub/client.ts136
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
3import { expect } from 'chai'
4import { processViewersStats } from '@server/tests/shared'
5import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 makeActivityPubGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel
14} from '@shared/server-commands'
15
16describe('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})