diff options
Diffstat (limited to 'server/tests/api/users/users-multiple-servers.ts')
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 148 |
1 files changed, 57 insertions, 91 deletions
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index f60c66e4b..d0ca82b07 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts | |||
@@ -1,34 +1,30 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { Account } from '../../../../shared/models/actors' | 4 | import * as chai from 'chai' |
6 | import { | 5 | import { |
6 | checkActorFilesWereRemoved, | ||
7 | checkTmpIsEmpty, | 7 | checkTmpIsEmpty, |
8 | checkVideoFilesWereRemoved, | 8 | checkVideoFilesWereRemoved, |
9 | cleanupTests, | 9 | cleanupTests, |
10 | createUser, | 10 | createMultipleServers, |
11 | doubleFollow, | 11 | doubleFollow, |
12 | flushAndRunMultipleServers, | 12 | PeerTubeServer, |
13 | getAccountVideos, | 13 | saveVideoInServers, |
14 | getVideoChannelsList, | 14 | setAccessTokensToServers, |
15 | removeUser, | 15 | testImage, |
16 | updateMyUser, | 16 | waitJobs |
17 | userLogin | 17 | } from '@shared/extra-utils' |
18 | } from '../../../../shared/extra-utils' | 18 | import { MyUser } from '@shared/models' |
19 | import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' | ||
20 | import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' | ||
21 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
22 | import { User } from '../../../../shared/models/users' | ||
23 | import { VideoChannel } from '../../../../shared/models/videos' | ||
24 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
25 | 19 | ||
26 | const expect = chai.expect | 20 | const expect = chai.expect |
27 | 21 | ||
28 | describe('Test users with multiple servers', function () { | 22 | describe('Test users with multiple servers', function () { |
29 | let servers: ServerInfo[] = [] | 23 | let servers: PeerTubeServer[] = [] |
30 | let user: User | 24 | |
25 | let user: MyUser | ||
31 | let userId: number | 26 | let userId: number |
27 | |||
32 | let videoUUID: string | 28 | let videoUUID: string |
33 | let userAccessToken: string | 29 | let userAccessToken: string |
34 | let userAvatarFilename: string | 30 | let userAvatarFilename: string |
@@ -36,7 +32,7 @@ describe('Test users with multiple servers', function () { | |||
36 | before(async function () { | 32 | before(async function () { |
37 | this.timeout(120_000) | 33 | this.timeout(120_000) |
38 | 34 | ||
39 | servers = await flushAndRunMultipleServers(3) | 35 | servers = await createMultipleServers(3) |
40 | 36 | ||
41 | // Get the access tokens | 37 | // Get the access tokens |
42 | await setAccessTokensToServers(servers) | 38 | await setAccessTokensToServers(servers) |
@@ -49,43 +45,31 @@ describe('Test users with multiple servers', function () { | |||
49 | await doubleFollow(servers[1], servers[2]) | 45 | await doubleFollow(servers[1], servers[2]) |
50 | 46 | ||
51 | // The root user of server 1 is propagated to servers 2 and 3 | 47 | // The root user of server 1 is propagated to servers 2 and 3 |
52 | await uploadVideo(servers[0].url, servers[0].accessToken, {}) | 48 | await servers[0].videos.upload() |
53 | 49 | ||
54 | { | 50 | { |
55 | const user = { | 51 | const username = 'user1' |
56 | username: 'user1', | 52 | const created = await servers[0].users.create({ username }) |
57 | password: 'password' | 53 | userId = created.id |
58 | } | 54 | userAccessToken = await servers[0].login.getAccessToken(username) |
59 | const res = await createUser({ | ||
60 | url: servers[0].url, | ||
61 | accessToken: servers[0].accessToken, | ||
62 | username: user.username, | ||
63 | password: user.password | ||
64 | }) | ||
65 | userId = res.body.user.id | ||
66 | userAccessToken = await userLogin(servers[0], user) | ||
67 | } | 55 | } |
68 | 56 | ||
69 | { | 57 | { |
70 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) | 58 | const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) |
71 | videoUUID = resVideo.body.video.uuid | 59 | videoUUID = uuid |
72 | } | ||
73 | 60 | ||
74 | await waitJobs(servers) | 61 | await waitJobs(servers) |
62 | |||
63 | await saveVideoInServers(servers, videoUUID) | ||
64 | } | ||
75 | }) | 65 | }) |
76 | 66 | ||
77 | it('Should be able to update my display name', async function () { | 67 | it('Should be able to update my display name', async function () { |
78 | this.timeout(10000) | 68 | this.timeout(10000) |
79 | 69 | ||
80 | await updateMyUser({ | 70 | await servers[0].users.updateMe({ displayName: 'my super display name' }) |
81 | url: servers[0].url, | ||
82 | accessToken: servers[0].accessToken, | ||
83 | displayName: 'my super display name' | ||
84 | }) | ||
85 | |||
86 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
87 | user = res.body | ||
88 | 71 | ||
72 | user = await servers[0].users.getMyInfo() | ||
89 | expect(user.account.displayName).to.equal('my super display name') | 73 | expect(user.account.displayName).to.equal('my super display name') |
90 | 74 | ||
91 | await waitJobs(servers) | 75 | await waitJobs(servers) |
@@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () { | |||
94 | it('Should be able to update my description', async function () { | 78 | it('Should be able to update my description', async function () { |
95 | this.timeout(10_000) | 79 | this.timeout(10_000) |
96 | 80 | ||
97 | await updateMyUser({ | 81 | await servers[0].users.updateMe({ description: 'my super description updated' }) |
98 | url: servers[0].url, | ||
99 | accessToken: servers[0].accessToken, | ||
100 | description: 'my super description updated' | ||
101 | }) | ||
102 | 82 | ||
103 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | 83 | user = await servers[0].users.getMyInfo() |
104 | user = res.body | ||
105 | expect(user.account.displayName).to.equal('my super display name') | 84 | expect(user.account.displayName).to.equal('my super display name') |
106 | expect(user.account.description).to.equal('my super description updated') | 85 | expect(user.account.description).to.equal('my super description updated') |
107 | 86 | ||
@@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () { | |||
113 | 92 | ||
114 | const fixture = 'avatar2.png' | 93 | const fixture = 'avatar2.png' |
115 | 94 | ||
116 | await updateMyAvatar({ | 95 | await servers[0].users.updateMyAvatar({ fixture }) |
117 | url: servers[0].url, | ||
118 | accessToken: servers[0].accessToken, | ||
119 | fixture | ||
120 | }) | ||
121 | |||
122 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | ||
123 | user = res.body | ||
124 | 96 | ||
97 | user = await servers[0].users.getMyInfo() | ||
125 | userAvatarFilename = user.account.avatar.path | 98 | userAvatarFilename = user.account.avatar.path |
126 | 99 | ||
127 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') | 100 | await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') |
@@ -133,13 +106,12 @@ describe('Test users with multiple servers', function () { | |||
133 | let createdAt: string | Date | 106 | let createdAt: string | Date |
134 | 107 | ||
135 | for (const server of servers) { | 108 | for (const server of servers) { |
136 | const resAccounts = await getAccountsList(server.url, '-createdAt') | 109 | const body = await server.accounts.list({ sort: '-createdAt' }) |
137 | 110 | ||
138 | const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account | 111 | const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) |
139 | expect(resList).not.to.be.undefined | 112 | expect(resList).not.to.be.undefined |
140 | 113 | ||
141 | const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) | 114 | const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) |
142 | const account = resAccount.body as Account | ||
143 | 115 | ||
144 | if (!createdAt) createdAt = account.createdAt | 116 | if (!createdAt) createdAt = account.createdAt |
145 | 117 | ||
@@ -161,31 +133,29 @@ describe('Test users with multiple servers', function () { | |||
161 | 133 | ||
162 | it('Should list account videos', async function () { | 134 | it('Should list account videos', async function () { |
163 | for (const server of servers) { | 135 | for (const server of servers) { |
164 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) | 136 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port }) |
165 | 137 | ||
166 | expect(res.body.total).to.equal(1) | 138 | expect(total).to.equal(1) |
167 | expect(res.body.data).to.be.an('array') | 139 | expect(data).to.be.an('array') |
168 | expect(res.body.data).to.have.lengthOf(1) | 140 | expect(data).to.have.lengthOf(1) |
169 | expect(res.body.data[0].uuid).to.equal(videoUUID) | 141 | expect(data[0].uuid).to.equal(videoUUID) |
170 | } | 142 | } |
171 | }) | 143 | }) |
172 | 144 | ||
173 | it('Should search through account videos', async function () { | 145 | it('Should search through account videos', async function () { |
174 | this.timeout(10_000) | 146 | this.timeout(10_000) |
175 | 147 | ||
176 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) | 148 | const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) |
177 | 149 | ||
178 | await waitJobs(servers) | 150 | await waitJobs(servers) |
179 | 151 | ||
180 | for (const server of servers) { | 152 | for (const server of servers) { |
181 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { | 153 | const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' }) |
182 | search: 'Kami' | 154 | |
183 | }) | 155 | expect(total).to.equal(1) |
184 | 156 | expect(data).to.be.an('array') | |
185 | expect(res.body.total).to.equal(1) | 157 | expect(data).to.have.lengthOf(1) |
186 | expect(res.body.data).to.be.an('array') | 158 | expect(data[0].uuid).to.equal(created.uuid) |
187 | expect(res.body.data).to.have.lengthOf(1) | ||
188 | expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) | ||
189 | } | 159 | } |
190 | }) | 160 | }) |
191 | 161 | ||
@@ -193,32 +163,28 @@ describe('Test users with multiple servers', function () { | |||
193 | this.timeout(10_000) | 163 | this.timeout(10_000) |
194 | 164 | ||
195 | for (const server of servers) { | 165 | for (const server of servers) { |
196 | const resAccounts = await getAccountsList(server.url, '-createdAt') | 166 | const body = await server.accounts.list({ sort: '-createdAt' }) |
197 | 167 | ||
198 | const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account | 168 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
199 | expect(accountDeleted).not.to.be.undefined | 169 | expect(accountDeleted).not.to.be.undefined |
200 | 170 | ||
201 | const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) | 171 | const { data } = await server.channels.list() |
202 | const videoChannelDeleted = resVideoChannels.body.data.find(a => { | 172 | const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
203 | return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port | ||
204 | }) as VideoChannel | ||
205 | expect(videoChannelDeleted).not.to.be.undefined | 173 | expect(videoChannelDeleted).not.to.be.undefined |
206 | } | 174 | } |
207 | 175 | ||
208 | await removeUser(servers[0].url, userId, servers[0].accessToken) | 176 | await servers[0].users.remove({ userId }) |
209 | 177 | ||
210 | await waitJobs(servers) | 178 | await waitJobs(servers) |
211 | 179 | ||
212 | for (const server of servers) { | 180 | for (const server of servers) { |
213 | const resAccounts = await getAccountsList(server.url, '-createdAt') | 181 | const body = await server.accounts.list({ sort: '-createdAt' }) |
214 | 182 | ||
215 | const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account | 183 | const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) |
216 | expect(accountDeleted).to.be.undefined | 184 | expect(accountDeleted).to.be.undefined |
217 | 185 | ||
218 | const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) | 186 | const { data } = await server.channels.list() |
219 | const videoChannelDeleted = resVideoChannels.body.data.find(a => { | 187 | const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) |
220 | return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port | ||
221 | }) as VideoChannel | ||
222 | expect(videoChannelDeleted).to.be.undefined | 188 | expect(videoChannelDeleted).to.be.undefined |
223 | } | 189 | } |
224 | }) | 190 | }) |
@@ -231,7 +197,7 @@ describe('Test users with multiple servers', function () { | |||
231 | 197 | ||
232 | it('Should not have video files', async () => { | 198 | it('Should not have video files', async () => { |
233 | for (const server of servers) { | 199 | for (const server of servers) { |
234 | await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) | 200 | await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails }) |
235 | } | 201 | } |
236 | }) | 202 | }) |
237 | 203 | ||