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