aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users-multiple-servers.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/users/users-multiple-servers.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/users/users-multiple-servers.ts')
-rw-r--r--server/tests/api/users/users-multiple-servers.ts216
1 files changed, 0 insertions, 216 deletions
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
deleted file mode 100644
index 3823b74ef..000000000
--- a/server/tests/api/users/users-multiple-servers.ts
+++ /dev/null
@@ -1,216 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { expect } from 'chai'
4import {
5 checkActorFilesWereRemoved,
6 checkTmpIsEmpty,
7 checkVideoFilesWereRemoved,
8 saveVideoInServers,
9 testImage
10} from '@server/tests/shared'
11import { MyUser } from '@shared/models'
12import {
13 cleanupTests,
14 createMultipleServers,
15 doubleFollow,
16 PeerTubeServer,
17 setAccessTokensToServers,
18 setDefaultChannelAvatar,
19 waitJobs
20} from '@shared/server-commands'
21
22describe('Test users with multiple servers', function () {
23 let servers: PeerTubeServer[] = []
24
25 let user: MyUser
26 let userId: number
27
28 let videoUUID: string
29 let userAccessToken: string
30 let userAvatarFilenames: string[]
31
32 before(async function () {
33 this.timeout(120_000)
34
35 servers = await createMultipleServers(3)
36
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
39 await setDefaultChannelAvatar(servers)
40
41 // Server 1 and server 2 follow each other
42 await doubleFollow(servers[0], servers[1])
43 // Server 1 and server 3 follow each other
44 await doubleFollow(servers[0], servers[2])
45 // Server 2 and server 3 follow each other
46 await doubleFollow(servers[1], servers[2])
47
48 // The root user of server 1 is propagated to servers 2 and 3
49 await servers[0].videos.upload()
50
51 {
52 const username = 'user1'
53 const created = await servers[0].users.create({ username })
54 userId = created.id
55 userAccessToken = await servers[0].login.getAccessToken(username)
56 }
57
58 {
59 const { uuid } = await servers[0].videos.upload({ token: userAccessToken })
60 videoUUID = uuid
61
62 await waitJobs(servers)
63
64 await saveVideoInServers(servers, videoUUID)
65 }
66 })
67
68 it('Should be able to update my display name', async function () {
69 await servers[0].users.updateMe({ displayName: 'my super display name' })
70
71 user = await servers[0].users.getMyInfo()
72 expect(user.account.displayName).to.equal('my super display name')
73
74 await waitJobs(servers)
75 })
76
77 it('Should be able to update my description', async function () {
78 this.timeout(10_000)
79
80 await servers[0].users.updateMe({ description: 'my super description updated' })
81
82 user = await servers[0].users.getMyInfo()
83 expect(user.account.displayName).to.equal('my super display name')
84 expect(user.account.description).to.equal('my super description updated')
85
86 await waitJobs(servers)
87 })
88
89 it('Should be able to update my avatar', async function () {
90 this.timeout(10_000)
91
92 const fixture = 'avatar2.png'
93
94 await servers[0].users.updateMyAvatar({ fixture })
95
96 user = await servers[0].users.getMyInfo()
97 userAvatarFilenames = user.account.avatars.map(({ path }) => path)
98
99 for (const avatar of user.account.avatars) {
100 await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
101 }
102
103 await waitJobs(servers)
104 })
105
106 it('Should have updated my profile on other servers too', async function () {
107 let createdAt: string | Date
108
109 for (const server of servers) {
110 const body = await server.accounts.list({ sort: '-createdAt' })
111
112 const resList = body.data.find(a => a.name === 'root' && a.host === servers[0].host)
113 expect(resList).not.to.be.undefined
114
115 const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host })
116
117 if (!createdAt) createdAt = account.createdAt
118
119 expect(account.name).to.equal('root')
120 expect(account.host).to.equal(servers[0].host)
121 expect(account.displayName).to.equal('my super display name')
122 expect(account.description).to.equal('my super description updated')
123 expect(createdAt).to.equal(account.createdAt)
124
125 if (server.serverNumber === 1) {
126 expect(account.userId).to.be.a('number')
127 } else {
128 expect(account.userId).to.be.undefined
129 }
130
131 for (const avatar of account.avatars) {
132 await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
133 }
134 }
135 })
136
137 it('Should list account videos', async function () {
138 for (const server of servers) {
139 const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host })
140
141 expect(total).to.equal(1)
142 expect(data).to.be.an('array')
143 expect(data).to.have.lengthOf(1)
144 expect(data[0].uuid).to.equal(videoUUID)
145 }
146 })
147
148 it('Should search through account videos', async function () {
149 const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } })
150
151 await waitJobs(servers)
152
153 for (const server of servers) {
154 const { total, data } = await server.videos.listByAccount({ handle: 'user1@' + servers[0].host, search: 'Kami' })
155
156 expect(total).to.equal(1)
157 expect(data).to.be.an('array')
158 expect(data).to.have.lengthOf(1)
159 expect(data[0].uuid).to.equal(created.uuid)
160 }
161 })
162
163 it('Should remove the user', async function () {
164 this.timeout(10_000)
165
166 for (const server of servers) {
167 const body = await server.accounts.list({ sort: '-createdAt' })
168
169 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
170 expect(accountDeleted).not.to.be.undefined
171
172 const { data } = await server.channels.list()
173 const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === servers[0].host)
174 expect(videoChannelDeleted).not.to.be.undefined
175 }
176
177 await servers[0].users.remove({ userId })
178
179 await waitJobs(servers)
180
181 for (const server of servers) {
182 const body = await server.accounts.list({ sort: '-createdAt' })
183
184 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === servers[0].host)
185 expect(accountDeleted).to.be.undefined
186
187 const { data } = await server.channels.list()
188 const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === servers[0].host)
189 expect(videoChannelDeleted).to.be.undefined
190 }
191 })
192
193 it('Should not have actor files', async () => {
194 for (const server of servers) {
195 for (const userAvatarFilename of userAvatarFilenames) {
196 await checkActorFilesWereRemoved(userAvatarFilename, server)
197 }
198 }
199 })
200
201 it('Should not have video files', async () => {
202 for (const server of servers) {
203 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
204 }
205 })
206
207 it('Should have an empty tmp directory', async function () {
208 for (const server of servers) {
209 await checkTmpIsEmpty(server)
210 }
211 })
212
213 after(async function () {
214 await cleanupTests(servers)
215 })
216})