aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub/refresher.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/refresher.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/refresher.ts')
-rw-r--r--server/tests/api/activitypub/refresher.ts157
1 files changed, 0 insertions, 157 deletions
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
deleted file mode 100644
index 4ea7929ec..000000000
--- a/server/tests/api/activitypub/refresher.ts
+++ /dev/null
@@ -1,157 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { SQLCommand } from '@server/tests/shared'
4import { wait } from '@shared/core-utils'
5import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 waitJobs
15} from '@shared/server-commands'
16
17describe('Test AP refresher', function () {
18 let servers: PeerTubeServer[] = []
19 let sqlCommandServer2: SQLCommand
20 let videoUUID1: string
21 let videoUUID2: string
22 let videoUUID3: string
23 let playlistUUID1: string
24 let playlistUUID2: string
25
26 before(async function () {
27 this.timeout(60000)
28
29 servers = await createMultipleServers(2)
30
31 // Get the access tokens
32 await setAccessTokensToServers(servers)
33 await setDefaultVideoChannel(servers)
34
35 for (const server of servers) {
36 await server.config.disableTranscoding()
37 }
38
39 {
40 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
41 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
42 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
43 }
44
45 {
46 const token1 = await servers[1].users.generateUserAndToken('user1')
47 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
48
49 const token2 = await servers[1].users.generateUserAndToken('user2')
50 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
51 }
52
53 {
54 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
55 const created = await servers[1].playlists.create({ attributes })
56 playlistUUID1 = created.uuid
57 }
58
59 {
60 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
61 const created = await servers[1].playlists.create({ attributes })
62 playlistUUID2 = created.uuid
63 }
64
65 await doubleFollow(servers[0], servers[1])
66
67 sqlCommandServer2 = new SQLCommand(servers[1])
68 })
69
70 describe('Videos refresher', function () {
71
72 it('Should remove a deleted remote video', async function () {
73 this.timeout(60000)
74
75 await wait(10000)
76
77 // Change UUID so the remote server returns a 404
78 await sqlCommandServer2.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
79
80 await servers[0].videos.get({ id: videoUUID1 })
81 await servers[0].videos.get({ id: videoUUID2 })
82
83 await waitJobs(servers)
84
85 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
86 await servers[0].videos.get({ id: videoUUID2 })
87 })
88
89 it('Should not update a remote video if the remote instance is down', async function () {
90 this.timeout(70000)
91
92 await killallServers([ servers[1] ])
93
94 await sqlCommandServer2.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
95
96 // Video will need a refresh
97 await wait(10000)
98
99 await servers[0].videos.get({ id: videoUUID3 })
100 // The refresh should fail
101 await waitJobs([ servers[0] ])
102
103 await servers[1].run()
104
105 await servers[0].videos.get({ id: videoUUID3 })
106 })
107 })
108
109 describe('Actors refresher', function () {
110
111 it('Should remove a deleted actor', async function () {
112 this.timeout(60000)
113
114 const command = servers[0].accounts
115
116 await wait(10000)
117
118 // Change actor name so the remote server returns a 404
119 const to = servers[1].url + '/accounts/user2'
120 await sqlCommandServer2.setActorField(to, 'preferredUsername', 'toto')
121
122 await command.get({ accountName: 'user1@' + servers[1].host })
123 await command.get({ accountName: 'user2@' + servers[1].host })
124
125 await waitJobs(servers)
126
127 await command.get({ accountName: 'user1@' + servers[1].host, expectedStatus: HttpStatusCode.OK_200 })
128 await command.get({ accountName: 'user2@' + servers[1].host, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
129 })
130 })
131
132 describe('Playlist refresher', function () {
133
134 it('Should remove a deleted playlist', async function () {
135 this.timeout(60000)
136
137 await wait(10000)
138
139 // Change UUID so the remote server returns a 404
140 await sqlCommandServer2.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
141
142 await servers[0].playlists.get({ playlistId: playlistUUID1 })
143 await servers[0].playlists.get({ playlistId: playlistUUID2 })
144
145 await waitJobs(servers)
146
147 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
148 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
149 })
150 })
151
152 after(async function () {
153 await sqlCommandServer2.cleanup()
154
155 await cleanupTests(servers)
156 })
157})