]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { | |
5 | checkActorFilesWereRemoved, | |
6 | checkTmpIsEmpty, | |
7 | checkVideoFilesWereRemoved, | |
8 | saveVideoInServers, | |
9 | testImage | |
10 | } from '@server/tests/shared' | |
11 | import { MyUser } from '@shared/models' | |
12 | import { | |
13 | cleanupTests, | |
14 | createMultipleServers, | |
15 | doubleFollow, | |
16 | PeerTubeServer, | |
17 | setAccessTokensToServers, | |
18 | setDefaultChannelAvatar, | |
19 | waitJobs | |
20 | } from '@shared/server-commands' | |
21 | ||
22 | describe('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 | this.timeout(10000) | |
70 | ||
71 | await servers[0].users.updateMe({ displayName: 'my super display name' }) | |
72 | ||
73 | user = await servers[0].users.getMyInfo() | |
74 | expect(user.account.displayName).to.equal('my super display name') | |
75 | ||
76 | await waitJobs(servers) | |
77 | }) | |
78 | ||
79 | it('Should be able to update my description', async function () { | |
80 | this.timeout(10_000) | |
81 | ||
82 | await servers[0].users.updateMe({ description: 'my super description updated' }) | |
83 | ||
84 | user = await servers[0].users.getMyInfo() | |
85 | expect(user.account.displayName).to.equal('my super display name') | |
86 | expect(user.account.description).to.equal('my super description updated') | |
87 | ||
88 | await waitJobs(servers) | |
89 | }) | |
90 | ||
91 | it('Should be able to update my avatar', async function () { | |
92 | this.timeout(10_000) | |
93 | ||
94 | const fixture = 'avatar2.png' | |
95 | ||
96 | await servers[0].users.updateMyAvatar({ fixture }) | |
97 | ||
98 | user = await servers[0].users.getMyInfo() | |
99 | userAvatarFilenames = user.account.avatars.map(({ path }) => path) | |
100 | ||
101 | for (const avatar of user.account.avatars) { | |
102 | await testImage(servers[0].url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png') | |
103 | } | |
104 | ||
105 | await waitJobs(servers) | |
106 | }) | |
107 | ||
108 | it('Should have updated my profile on other servers too', async function () { | |
109 | let createdAt: string | Date | |
110 | ||
111 | for (const server of servers) { | |
112 | const body = await server.accounts.list({ sort: '-createdAt' }) | |
113 | ||
114 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) | |
115 | expect(resList).not.to.be.undefined | |
116 | ||
117 | const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) | |
118 | ||
119 | if (!createdAt) createdAt = account.createdAt | |
120 | ||
121 | expect(account.name).to.equal('root') | |
122 | expect(account.host).to.equal('localhost:' + servers[0].port) | |
123 | expect(account.displayName).to.equal('my super display name') | |
124 | expect(account.description).to.equal('my super description updated') | |
125 | expect(createdAt).to.equal(account.createdAt) | |
126 | ||
127 | if (server.serverNumber === 1) { | |
128 | expect(account.userId).to.be.a('number') | |
129 | } else { | |
130 | expect(account.userId).to.be.undefined | |
131 | } | |
132 | ||
133 | for (const avatar of account.avatars) { | |
134 | await testImage(server.url, `avatar2-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png') | |
135 | } | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should list account videos', async function () { | |
140 | for (const server of servers) { | |
141 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port }) | |
142 | ||
143 | expect(total).to.equal(1) | |
144 | expect(data).to.be.an('array') | |
145 | expect(data).to.have.lengthOf(1) | |
146 | expect(data[0].uuid).to.equal(videoUUID) | |
147 | } | |
148 | }) | |
149 | ||
150 | it('Should search through account videos', async function () { | |
151 | this.timeout(10_000) | |
152 | ||
153 | const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) | |
154 | ||
155 | await waitJobs(servers) | |
156 | ||
157 | for (const server of servers) { | |
158 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' }) | |
159 | ||
160 | expect(total).to.equal(1) | |
161 | expect(data).to.be.an('array') | |
162 | expect(data).to.have.lengthOf(1) | |
163 | expect(data[0].uuid).to.equal(created.uuid) | |
164 | } | |
165 | }) | |
166 | ||
167 | it('Should remove the user', async function () { | |
168 | this.timeout(10_000) | |
169 | ||
170 | for (const server of servers) { | |
171 | const body = await server.accounts.list({ sort: '-createdAt' }) | |
172 | ||
173 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) | |
174 | expect(accountDeleted).not.to.be.undefined | |
175 | ||
176 | const { data } = await server.channels.list() | |
177 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | |
178 | expect(videoChannelDeleted).not.to.be.undefined | |
179 | } | |
180 | ||
181 | await servers[0].users.remove({ userId }) | |
182 | ||
183 | await waitJobs(servers) | |
184 | ||
185 | for (const server of servers) { | |
186 | const body = await server.accounts.list({ sort: '-createdAt' }) | |
187 | ||
188 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) | |
189 | expect(accountDeleted).to.be.undefined | |
190 | ||
191 | const { data } = await server.channels.list() | |
192 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) | |
193 | expect(videoChannelDeleted).to.be.undefined | |
194 | } | |
195 | }) | |
196 | ||
197 | it('Should not have actor files', async () => { | |
198 | for (const server of servers) { | |
199 | for (const userAvatarFilename of userAvatarFilenames) { | |
200 | await checkActorFilesWereRemoved(userAvatarFilename, server.internalServerNumber) | |
201 | } | |
202 | } | |
203 | }) | |
204 | ||
205 | it('Should not have video files', async () => { | |
206 | for (const server of servers) { | |
207 | await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails }) | |
208 | } | |
209 | }) | |
210 | ||
211 | it('Should have an empty tmp directory', async function () { | |
212 | for (const server of servers) { | |
213 | await checkTmpIsEmpty(server) | |
214 | } | |
215 | }) | |
216 | ||
217 | after(async function () { | |
218 | await cleanupTests(servers) | |
219 | }) | |
220 | }) |