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