diff options
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 230 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 132 | ||||
-rw-r--r-- | server/tests/api/users/users-verification.ts | 107 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 657 |
4 files changed, 436 insertions, 690 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 60676a37b..77b99886d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -1,42 +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' |
4 | import * as chai from 'chai' | ||
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | createUser, | 7 | createMultipleServers, |
8 | doubleFollow, | 8 | doubleFollow, |
9 | flushAndRunMultipleServers, | 9 | PeerTubeServer, |
10 | follow, | 10 | setAccessTokensToServers, |
11 | getVideosList, | 11 | SubscriptionsCommand, |
12 | unfollow, | 12 | waitJobs |
13 | updateVideo, | 13 | } from '@shared/extra-utils' |
14 | userLogin | ||
15 | } from '../../../../shared/extra-utils' | ||
16 | import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' | ||
17 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
18 | import { Video, VideoChannel } from '../../../../shared/models/videos' | ||
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
20 | import { | ||
21 | addUserSubscription, | ||
22 | areSubscriptionsExist, | ||
23 | getUserSubscription, | ||
24 | listUserSubscriptions, | ||
25 | listUserSubscriptionVideos, | ||
26 | removeUserSubscription | ||
27 | } from '../../../../shared/extra-utils/users/user-subscriptions' | ||
28 | 14 | ||
29 | const expect = chai.expect | 15 | const expect = chai.expect |
30 | 16 | ||
31 | describe('Test users subscriptions', function () { | 17 | describe('Test users subscriptions', function () { |
32 | let servers: ServerInfo[] = [] | 18 | let servers: PeerTubeServer[] = [] |
33 | const users: { accessToken: string }[] = [] | 19 | const users: { accessToken: string }[] = [] |
34 | let video3UUID: string | 20 | let video3UUID: string |
35 | 21 | ||
22 | let command: SubscriptionsCommand | ||
23 | |||
36 | before(async function () { | 24 | before(async function () { |
37 | this.timeout(120000) | 25 | this.timeout(120000) |
38 | 26 | ||
39 | servers = await flushAndRunMultipleServers(3) | 27 | servers = await createMultipleServers(3) |
40 | 28 | ||
41 | // Get the access tokens | 29 | // Get the access tokens |
42 | await setAccessTokensToServers(servers) | 30 | await setAccessTokensToServers(servers) |
@@ -47,47 +35,50 @@ describe('Test users subscriptions', function () { | |||
47 | { | 35 | { |
48 | for (const server of servers) { | 36 | for (const server of servers) { |
49 | const user = { username: 'user' + server.serverNumber, password: 'password' } | 37 | const user = { username: 'user' + server.serverNumber, password: 'password' } |
50 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 38 | await server.users.create({ username: user.username, password: user.password }) |
51 | 39 | ||
52 | const accessToken = await userLogin(server, user) | 40 | const accessToken = await server.login.getAccessToken(user) |
53 | users.push({ accessToken }) | 41 | users.push({ accessToken }) |
54 | 42 | ||
55 | const videoName1 = 'video 1-' + server.serverNumber | 43 | const videoName1 = 'video 1-' + server.serverNumber |
56 | await uploadVideo(server.url, accessToken, { name: videoName1 }) | 44 | await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) |
57 | 45 | ||
58 | const videoName2 = 'video 2-' + server.serverNumber | 46 | const videoName2 = 'video 2-' + server.serverNumber |
59 | await uploadVideo(server.url, accessToken, { name: videoName2 }) | 47 | await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) |
60 | } | 48 | } |
61 | } | 49 | } |
62 | 50 | ||
63 | await waitJobs(servers) | 51 | await waitJobs(servers) |
52 | |||
53 | command = servers[0].subscriptions | ||
64 | }) | 54 | }) |
65 | 55 | ||
66 | it('Should display videos of server 2 on server 1', async function () { | 56 | it('Should display videos of server 2 on server 1', async function () { |
67 | const res = await getVideosList(servers[0].url) | 57 | const { total } = await servers[0].videos.list() |
68 | 58 | ||
69 | expect(res.body.total).to.equal(4) | 59 | expect(total).to.equal(4) |
70 | }) | 60 | }) |
71 | 61 | ||
72 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { | 62 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { |
73 | this.timeout(60000) | 63 | this.timeout(60000) |
74 | 64 | ||
75 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 65 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) |
76 | await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 66 | await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) |
77 | 67 | ||
78 | await waitJobs(servers) | 68 | await waitJobs(servers) |
79 | 69 | ||
80 | const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) | 70 | const attributes = { name: 'video server 3 added after follow' } |
81 | video3UUID = res.body.video.uuid | 71 | const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes }) |
72 | video3UUID = uuid | ||
82 | 73 | ||
83 | await waitJobs(servers) | 74 | await waitJobs(servers) |
84 | }) | 75 | }) |
85 | 76 | ||
86 | it('Should not display videos of server 3 on server 1', async function () { | 77 | it('Should not display videos of server 3 on server 1', async function () { |
87 | const res = await getVideosList(servers[0].url) | 78 | const { total, data } = await servers[0].videos.list() |
79 | expect(total).to.equal(4) | ||
88 | 80 | ||
89 | expect(res.body.total).to.equal(4) | 81 | for (const video of data) { |
90 | for (const video of res.body.data) { | ||
91 | expect(video.name).to.not.contain('1-3') | 82 | expect(video.name).to.not.contain('1-3') |
92 | expect(video.name).to.not.contain('2-3') | 83 | expect(video.name).to.not.contain('2-3') |
93 | expect(video.name).to.not.contain('video server 3 added after follow') | 84 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -96,17 +87,17 @@ describe('Test users subscriptions', function () { | |||
96 | 87 | ||
97 | it('Should list subscriptions', async function () { | 88 | it('Should list subscriptions', async function () { |
98 | { | 89 | { |
99 | const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) | 90 | const body = await command.list() |
100 | expect(res.body.total).to.equal(0) | 91 | expect(body.total).to.equal(0) |
101 | expect(res.body.data).to.be.an('array') | 92 | expect(body.data).to.be.an('array') |
102 | expect(res.body.data).to.have.lengthOf(0) | 93 | expect(body.data).to.have.lengthOf(0) |
103 | } | 94 | } |
104 | 95 | ||
105 | { | 96 | { |
106 | const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) | 97 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) |
107 | expect(res.body.total).to.equal(2) | 98 | expect(body.total).to.equal(2) |
108 | 99 | ||
109 | const subscriptions: VideoChannel[] = res.body.data | 100 | const subscriptions = body.data |
110 | expect(subscriptions).to.be.an('array') | 101 | expect(subscriptions).to.be.an('array') |
111 | expect(subscriptions).to.have.lengthOf(2) | 102 | expect(subscriptions).to.have.lengthOf(2) |
112 | 103 | ||
@@ -117,8 +108,7 @@ describe('Test users subscriptions', function () { | |||
117 | 108 | ||
118 | it('Should get subscription', async function () { | 109 | it('Should get subscription', async function () { |
119 | { | 110 | { |
120 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 111 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) |
121 | const videoChannel: VideoChannel = res.body | ||
122 | 112 | ||
123 | expect(videoChannel.name).to.equal('user3_channel') | 113 | expect(videoChannel.name).to.equal('user3_channel') |
124 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) | 114 | expect(videoChannel.host).to.equal('localhost:' + servers[2].port) |
@@ -128,8 +118,7 @@ describe('Test users subscriptions', function () { | |||
128 | } | 118 | } |
129 | 119 | ||
130 | { | 120 | { |
131 | const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 121 | const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) |
132 | const videoChannel: VideoChannel = res.body | ||
133 | 122 | ||
134 | expect(videoChannel.name).to.equal('root_channel') | 123 | expect(videoChannel.name).to.equal('root_channel') |
135 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) | 124 | expect(videoChannel.host).to.equal('localhost:' + servers[0].port) |
@@ -147,8 +136,7 @@ describe('Test users subscriptions', function () { | |||
147 | 'user3_channel@localhost:' + servers[0].port | 136 | 'user3_channel@localhost:' + servers[0].port |
148 | ] | 137 | ] |
149 | 138 | ||
150 | const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) | 139 | const body = await command.exist({ token: users[0].accessToken, uris }) |
151 | const body = res.body | ||
152 | 140 | ||
153 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true | 141 | expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true |
154 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false | 142 | expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false |
@@ -158,45 +146,31 @@ describe('Test users subscriptions', function () { | |||
158 | 146 | ||
159 | it('Should search among subscriptions', async function () { | 147 | it('Should search among subscriptions', async function () { |
160 | { | 148 | { |
161 | const res = await listUserSubscriptions({ | 149 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' }) |
162 | url: servers[0].url, | 150 | expect(body.total).to.equal(1) |
163 | token: users[0].accessToken, | 151 | expect(body.data).to.have.lengthOf(1) |
164 | sort: '-createdAt', | ||
165 | search: 'user3_channel' | ||
166 | }) | ||
167 | expect(res.body.total).to.equal(1) | ||
168 | |||
169 | const subscriptions = res.body.data | ||
170 | expect(subscriptions).to.have.lengthOf(1) | ||
171 | } | 152 | } |
172 | 153 | ||
173 | { | 154 | { |
174 | const res = await listUserSubscriptions({ | 155 | const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' }) |
175 | url: servers[0].url, | 156 | expect(body.total).to.equal(0) |
176 | token: users[0].accessToken, | 157 | expect(body.data).to.have.lengthOf(0) |
177 | sort: '-createdAt', | ||
178 | search: 'toto' | ||
179 | }) | ||
180 | expect(res.body.total).to.equal(0) | ||
181 | |||
182 | const subscriptions = res.body.data | ||
183 | expect(subscriptions).to.have.lengthOf(0) | ||
184 | } | 158 | } |
185 | }) | 159 | }) |
186 | 160 | ||
187 | it('Should list subscription videos', async function () { | 161 | it('Should list subscription videos', async function () { |
188 | { | 162 | { |
189 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 163 | const body = await command.listVideos() |
190 | expect(res.body.total).to.equal(0) | 164 | expect(body.total).to.equal(0) |
191 | expect(res.body.data).to.be.an('array') | 165 | expect(body.data).to.be.an('array') |
192 | expect(res.body.data).to.have.lengthOf(0) | 166 | expect(body.data).to.have.lengthOf(0) |
193 | } | 167 | } |
194 | 168 | ||
195 | { | 169 | { |
196 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 170 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
197 | expect(res.body.total).to.equal(3) | 171 | expect(body.total).to.equal(3) |
198 | 172 | ||
199 | const videos: Video[] = res.body.data | 173 | const videos = body.data |
200 | expect(videos).to.be.an('array') | 174 | expect(videos).to.be.an('array') |
201 | expect(videos).to.have.lengthOf(3) | 175 | expect(videos).to.have.lengthOf(3) |
202 | 176 | ||
@@ -210,22 +184,22 @@ describe('Test users subscriptions', function () { | |||
210 | this.timeout(60000) | 184 | this.timeout(60000) |
211 | 185 | ||
212 | const videoName = 'video server 1 added after follow' | 186 | const videoName = 'video server 1 added after follow' |
213 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) | 187 | await servers[0].videos.upload({ attributes: { name: videoName } }) |
214 | 188 | ||
215 | await waitJobs(servers) | 189 | await waitJobs(servers) |
216 | 190 | ||
217 | { | 191 | { |
218 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 192 | const body = await command.listVideos() |
219 | expect(res.body.total).to.equal(0) | 193 | expect(body.total).to.equal(0) |
220 | expect(res.body.data).to.be.an('array') | 194 | expect(body.data).to.be.an('array') |
221 | expect(res.body.data).to.have.lengthOf(0) | 195 | expect(body.data).to.have.lengthOf(0) |
222 | } | 196 | } |
223 | 197 | ||
224 | { | 198 | { |
225 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 199 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
226 | expect(res.body.total).to.equal(4) | 200 | expect(body.total).to.equal(4) |
227 | 201 | ||
228 | const videos: Video[] = res.body.data | 202 | const videos = body.data |
229 | expect(videos).to.be.an('array') | 203 | expect(videos).to.be.an('array') |
230 | expect(videos).to.have.lengthOf(4) | 204 | expect(videos).to.have.lengthOf(4) |
231 | 205 | ||
@@ -236,10 +210,10 @@ describe('Test users subscriptions', function () { | |||
236 | } | 210 | } |
237 | 211 | ||
238 | { | 212 | { |
239 | const res = await getVideosList(servers[0].url) | 213 | const { data, total } = await servers[0].videos.list() |
214 | expect(total).to.equal(5) | ||
240 | 215 | ||
241 | expect(res.body.total).to.equal(5) | 216 | for (const video of data) { |
242 | for (const video of res.body.data) { | ||
243 | expect(video.name).to.not.contain('1-3') | 217 | expect(video.name).to.not.contain('1-3') |
244 | expect(video.name).to.not.contain('2-3') | 218 | expect(video.name).to.not.contain('2-3') |
245 | expect(video.name).to.not.contain('video server 3 added after follow') | 219 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -250,17 +224,16 @@ describe('Test users subscriptions', function () { | |||
250 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { | 224 | it('Should have server 1 follow server 3 and display server 3 videos', async function () { |
251 | this.timeout(60000) | 225 | this.timeout(60000) |
252 | 226 | ||
253 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | 227 | await servers[0].follows.follow({ hosts: [ servers[2].url ] }) |
254 | 228 | ||
255 | await waitJobs(servers) | 229 | await waitJobs(servers) |
256 | 230 | ||
257 | const res = await getVideosList(servers[0].url) | 231 | const { data, total } = await servers[0].videos.list() |
258 | 232 | expect(total).to.equal(8) | |
259 | expect(res.body.total).to.equal(8) | ||
260 | 233 | ||
261 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] | 234 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] |
262 | for (const name of names) { | 235 | for (const name of names) { |
263 | const video = res.body.data.find(v => v.name.indexOf(name) === -1) | 236 | const video = data.find(v => v.name.includes(name)) |
264 | expect(video).to.not.be.undefined | 237 | expect(video).to.not.be.undefined |
265 | } | 238 | } |
266 | }) | 239 | }) |
@@ -268,14 +241,14 @@ describe('Test users subscriptions', function () { | |||
268 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { | 241 | it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { |
269 | this.timeout(60000) | 242 | this.timeout(60000) |
270 | 243 | ||
271 | await unfollow(servers[0].url, servers[0].accessToken, servers[2]) | 244 | await servers[0].follows.unfollow({ target: servers[2] }) |
272 | 245 | ||
273 | await waitJobs(servers) | 246 | await waitJobs(servers) |
274 | 247 | ||
275 | const res = await getVideosList(servers[0].url) | 248 | const { total, data } = await servers[0].videos.list() |
249 | expect(total).to.equal(5) | ||
276 | 250 | ||
277 | expect(res.body.total).to.equal(5) | 251 | for (const video of data) { |
278 | for (const video of res.body.data) { | ||
279 | expect(video.name).to.not.contain('1-3') | 252 | expect(video.name).to.not.contain('1-3') |
280 | expect(video.name).to.not.contain('2-3') | 253 | expect(video.name).to.not.contain('2-3') |
281 | expect(video.name).to.not.contain('video server 3 added after follow') | 254 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -284,17 +257,17 @@ describe('Test users subscriptions', function () { | |||
284 | 257 | ||
285 | it('Should still list subscription videos', async function () { | 258 | it('Should still list subscription videos', async function () { |
286 | { | 259 | { |
287 | const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) | 260 | const body = await command.listVideos() |
288 | expect(res.body.total).to.equal(0) | 261 | expect(body.total).to.equal(0) |
289 | expect(res.body.data).to.be.an('array') | 262 | expect(body.data).to.be.an('array') |
290 | expect(res.body.data).to.have.lengthOf(0) | 263 | expect(body.data).to.have.lengthOf(0) |
291 | } | 264 | } |
292 | 265 | ||
293 | { | 266 | { |
294 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 267 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
295 | expect(res.body.total).to.equal(4) | 268 | expect(body.total).to.equal(4) |
296 | 269 | ||
297 | const videos: Video[] = res.body.data | 270 | const videos = body.data |
298 | expect(videos).to.be.an('array') | 271 | expect(videos).to.be.an('array') |
299 | expect(videos).to.have.lengthOf(4) | 272 | expect(videos).to.have.lengthOf(4) |
300 | 273 | ||
@@ -308,58 +281,55 @@ describe('Test users subscriptions', function () { | |||
308 | it('Should update a video of server 3 and see the updated video on server 1', async function () { | 281 | it('Should update a video of server 3 and see the updated video on server 1', async function () { |
309 | this.timeout(30000) | 282 | this.timeout(30000) |
310 | 283 | ||
311 | await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) | 284 | await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) |
312 | 285 | ||
313 | await waitJobs(servers) | 286 | await waitJobs(servers) |
314 | 287 | ||
315 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 288 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
316 | const videos: Video[] = res.body.data | 289 | expect(body.data[2].name).to.equal('video server 3 added after follow updated') |
317 | expect(videos[2].name).to.equal('video server 3 added after follow updated') | ||
318 | }) | 290 | }) |
319 | 291 | ||
320 | it('Should remove user of server 3 subscription', async function () { | 292 | it('Should remove user of server 3 subscription', async function () { |
321 | this.timeout(30000) | 293 | this.timeout(30000) |
322 | 294 | ||
323 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 295 | await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) |
324 | 296 | ||
325 | await waitJobs(servers) | 297 | await waitJobs(servers) |
326 | }) | 298 | }) |
327 | 299 | ||
328 | it('Should not display its videos anymore', async function () { | 300 | it('Should not display its videos anymore', async function () { |
329 | { | 301 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
330 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 302 | expect(body.total).to.equal(1) |
331 | expect(res.body.total).to.equal(1) | ||
332 | 303 | ||
333 | const videos: Video[] = res.body.data | 304 | const videos = body.data |
334 | expect(videos).to.be.an('array') | 305 | expect(videos).to.be.an('array') |
335 | expect(videos).to.have.lengthOf(1) | 306 | expect(videos).to.have.lengthOf(1) |
336 | 307 | ||
337 | expect(videos[0].name).to.equal('video server 1 added after follow') | 308 | expect(videos[0].name).to.equal('video server 1 added after follow') |
338 | } | ||
339 | }) | 309 | }) |
340 | 310 | ||
341 | it('Should remove the root subscription and not display the videos anymore', async function () { | 311 | it('Should remove the root subscription and not display the videos anymore', async function () { |
342 | this.timeout(30000) | 312 | this.timeout(30000) |
343 | 313 | ||
344 | await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) | 314 | await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) |
345 | 315 | ||
346 | await waitJobs(servers) | 316 | await waitJobs(servers) |
347 | 317 | ||
348 | { | 318 | { |
349 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 319 | const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) |
350 | expect(res.body.total).to.equal(0) | 320 | expect(body.total).to.equal(0) |
351 | 321 | ||
352 | const videos: Video[] = res.body.data | 322 | const videos = body.data |
353 | expect(videos).to.be.an('array') | 323 | expect(videos).to.be.an('array') |
354 | expect(videos).to.have.lengthOf(0) | 324 | expect(videos).to.have.lengthOf(0) |
355 | } | 325 | } |
356 | }) | 326 | }) |
357 | 327 | ||
358 | it('Should correctly display public videos on server 1', async function () { | 328 | it('Should correctly display public videos on server 1', async function () { |
359 | const res = await getVideosList(servers[0].url) | 329 | const { total, data } = await servers[0].videos.list() |
330 | expect(total).to.equal(5) | ||
360 | 331 | ||
361 | expect(res.body.total).to.equal(5) | 332 | for (const video of data) { |
362 | for (const video of res.body.data) { | ||
363 | expect(video.name).to.not.contain('1-3') | 333 | expect(video.name).to.not.contain('1-3') |
364 | expect(video.name).to.not.contain('2-3') | 334 | expect(video.name).to.not.contain('2-3') |
365 | expect(video.name).to.not.contain('video server 3 added after follow updated') | 335 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
@@ -369,15 +339,15 @@ describe('Test users subscriptions', function () { | |||
369 | it('Should follow user of server 3 again', async function () { | 339 | it('Should follow user of server 3 again', async function () { |
370 | this.timeout(60000) | 340 | this.timeout(60000) |
371 | 341 | ||
372 | await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) | 342 | await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) |
373 | 343 | ||
374 | await waitJobs(servers) | 344 | await waitJobs(servers) |
375 | 345 | ||
376 | { | 346 | { |
377 | const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') | 347 | const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) |
378 | expect(res.body.total).to.equal(3) | 348 | expect(body.total).to.equal(3) |
379 | 349 | ||
380 | const videos: Video[] = res.body.data | 350 | const videos = body.data |
381 | expect(videos).to.be.an('array') | 351 | expect(videos).to.be.an('array') |
382 | expect(videos).to.have.lengthOf(3) | 352 | expect(videos).to.have.lengthOf(3) |
383 | 353 | ||
@@ -387,10 +357,10 @@ describe('Test users subscriptions', function () { | |||
387 | } | 357 | } |
388 | 358 | ||
389 | { | 359 | { |
390 | const res = await getVideosList(servers[0].url) | 360 | const { total, data } = await servers[0].videos.list() |
361 | expect(total).to.equal(5) | ||
391 | 362 | ||
392 | expect(res.body.total).to.equal(5) | 363 | for (const video of data) { |
393 | for (const video of res.body.data) { | ||
394 | expect(video.name).to.not.contain('1-3') | 364 | expect(video.name).to.not.contain('1-3') |
395 | expect(video.name).to.not.contain('2-3') | 365 | expect(video.name).to.not.contain('2-3') |
396 | expect(video.name).to.not.contain('video server 3 added after follow updated') | 366 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
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 | ||
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index e0f2f2112..f54463359 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts | |||
@@ -1,30 +1,14 @@ | |||
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 { | 4 | import * as chai from 'chai' |
6 | cleanupTests, | 5 | import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' |
7 | flushAndRunServer, | 6 | import { HttpStatusCode } from '@shared/models' |
8 | getMyUserInformation, | ||
9 | getUserInformation, | ||
10 | login, | ||
11 | registerUser, | ||
12 | ServerInfo, | ||
13 | updateCustomSubConfig, | ||
14 | updateMyUser, | ||
15 | userLogin, | ||
16 | verifyEmail | ||
17 | } from '../../../../shared/extra-utils' | ||
18 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
19 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | ||
20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
21 | import { User } from '../../../../shared/models/users' | ||
22 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
23 | 7 | ||
24 | const expect = chai.expect | 8 | const expect = chai.expect |
25 | 9 | ||
26 | describe('Test users account verification', function () { | 10 | describe('Test users account verification', function () { |
27 | let server: ServerInfo | 11 | let server: PeerTubeServer |
28 | let userId: number | 12 | let userId: number |
29 | let userAccessToken: string | 13 | let userAccessToken: string |
30 | let verificationString: string | 14 | let verificationString: string |
@@ -50,7 +34,7 @@ describe('Test users account verification', function () { | |||
50 | port | 34 | port |
51 | } | 35 | } |
52 | } | 36 | } |
53 | server = await flushAndRunServer(1, overrideConfig) | 37 | server = await createSingleServer(1, overrideConfig) |
54 | 38 | ||
55 | await setAccessTokensToServers([ server ]) | 39 | await setAccessTokensToServers([ server ]) |
56 | }) | 40 | }) |
@@ -58,15 +42,17 @@ describe('Test users account verification', function () { | |||
58 | it('Should register user and send verification email if verification required', async function () { | 42 | it('Should register user and send verification email if verification required', async function () { |
59 | this.timeout(30000) | 43 | this.timeout(30000) |
60 | 44 | ||
61 | await updateCustomSubConfig(server.url, server.accessToken, { | 45 | await server.config.updateCustomSubConfig({ |
62 | signup: { | 46 | newConfig: { |
63 | enabled: true, | 47 | signup: { |
64 | requiresEmailVerification: true, | 48 | enabled: true, |
65 | limit: 10 | 49 | requiresEmailVerification: true, |
50 | limit: 10 | ||
51 | } | ||
66 | } | 52 | } |
67 | }) | 53 | }) |
68 | 54 | ||
69 | await registerUser(server.url, user1.username, user1.password) | 55 | await server.users.register(user1) |
70 | 56 | ||
71 | await waitJobs(server) | 57 | await waitJobs(server) |
72 | expectedEmailsLength++ | 58 | expectedEmailsLength++ |
@@ -85,23 +71,23 @@ describe('Test users account verification', function () { | |||
85 | 71 | ||
86 | userId = parseInt(userIdMatches[1], 10) | 72 | userId = parseInt(userIdMatches[1], 10) |
87 | 73 | ||
88 | const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) | 74 | const body = await server.users.get({ userId }) |
89 | expect(resUserInfo.body.emailVerified).to.be.false | 75 | expect(body.emailVerified).to.be.false |
90 | }) | 76 | }) |
91 | 77 | ||
92 | it('Should not allow login for user with unverified email', async function () { | 78 | it('Should not allow login for user with unverified email', async function () { |
93 | const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) | 79 | const { detail } = await server.login.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
94 | expect(resLogin.body.detail).to.contain('User email is not verified.') | 80 | expect(detail).to.contain('User email is not verified.') |
95 | }) | 81 | }) |
96 | 82 | ||
97 | it('Should verify the user via email and allow login', async function () { | 83 | it('Should verify the user via email and allow login', async function () { |
98 | await verifyEmail(server.url, userId, verificationString) | 84 | await server.users.verifyEmail({ userId, verificationString }) |
99 | 85 | ||
100 | const res = await login(server.url, server.client, user1) | 86 | const body = await server.login.login({ user: user1 }) |
101 | userAccessToken = res.body.access_token | 87 | userAccessToken = body.access_token |
102 | 88 | ||
103 | const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) | 89 | const user = await server.users.get({ userId }) |
104 | expect(resUserVerified.body.emailVerified).to.be.true | 90 | expect(user.emailVerified).to.be.true |
105 | }) | 91 | }) |
106 | 92 | ||
107 | it('Should be able to change the user email', async function () { | 93 | it('Should be able to change the user email', async function () { |
@@ -110,9 +96,8 @@ describe('Test users account verification', function () { | |||
110 | let updateVerificationString: string | 96 | let updateVerificationString: string |
111 | 97 | ||
112 | { | 98 | { |
113 | await updateMyUser({ | 99 | await server.users.updateMe({ |
114 | url: server.url, | 100 | token: userAccessToken, |
115 | accessToken: userAccessToken, | ||
116 | email: 'updated@example.com', | 101 | email: 'updated@example.com', |
117 | currentPassword: user1.password | 102 | currentPassword: user1.password |
118 | }) | 103 | }) |
@@ -128,19 +113,15 @@ describe('Test users account verification', function () { | |||
128 | } | 113 | } |
129 | 114 | ||
130 | { | 115 | { |
131 | const res = await getMyUserInformation(server.url, userAccessToken) | 116 | const me = await server.users.getMyInfo({ token: userAccessToken }) |
132 | const me: User = res.body | ||
133 | |||
134 | expect(me.email).to.equal('user_1@example.com') | 117 | expect(me.email).to.equal('user_1@example.com') |
135 | expect(me.pendingEmail).to.equal('updated@example.com') | 118 | expect(me.pendingEmail).to.equal('updated@example.com') |
136 | } | 119 | } |
137 | 120 | ||
138 | { | 121 | { |
139 | await verifyEmail(server.url, userId, updateVerificationString, true) | 122 | await server.users.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) |
140 | |||
141 | const res = await getMyUserInformation(server.url, userAccessToken) | ||
142 | const me: User = res.body | ||
143 | 123 | ||
124 | const me = await server.users.getMyInfo({ token: userAccessToken }) | ||
144 | expect(me.email).to.equal('updated@example.com') | 125 | expect(me.email).to.equal('updated@example.com') |
145 | expect(me.pendingEmail).to.be.null | 126 | expect(me.pendingEmail).to.be.null |
146 | } | 127 | } |
@@ -148,35 +129,39 @@ describe('Test users account verification', function () { | |||
148 | 129 | ||
149 | it('Should register user not requiring email verification if setting not enabled', async function () { | 130 | it('Should register user not requiring email verification if setting not enabled', async function () { |
150 | this.timeout(5000) | 131 | this.timeout(5000) |
151 | await updateCustomSubConfig(server.url, server.accessToken, { | 132 | await server.config.updateCustomSubConfig({ |
152 | signup: { | 133 | newConfig: { |
153 | enabled: true, | 134 | signup: { |
154 | requiresEmailVerification: false, | 135 | enabled: true, |
155 | limit: 10 | 136 | requiresEmailVerification: false, |
137 | limit: 10 | ||
138 | } | ||
156 | } | 139 | } |
157 | }) | 140 | }) |
158 | 141 | ||
159 | await registerUser(server.url, user2.username, user2.password) | 142 | await server.users.register(user2) |
160 | 143 | ||
161 | await waitJobs(server) | 144 | await waitJobs(server) |
162 | expect(emails).to.have.lengthOf(expectedEmailsLength) | 145 | expect(emails).to.have.lengthOf(expectedEmailsLength) |
163 | 146 | ||
164 | const accessToken = await userLogin(server, user2) | 147 | const accessToken = await server.login.getAccessToken(user2) |
165 | 148 | ||
166 | const resMyUserInfo = await getMyUserInformation(server.url, accessToken) | 149 | const user = await server.users.getMyInfo({ token: accessToken }) |
167 | expect(resMyUserInfo.body.emailVerified).to.be.null | 150 | expect(user.emailVerified).to.be.null |
168 | }) | 151 | }) |
169 | 152 | ||
170 | it('Should allow login for user with unverified email when setting later enabled', async function () { | 153 | it('Should allow login for user with unverified email when setting later enabled', async function () { |
171 | await updateCustomSubConfig(server.url, server.accessToken, { | 154 | await server.config.updateCustomSubConfig({ |
172 | signup: { | 155 | newConfig: { |
173 | enabled: true, | 156 | signup: { |
174 | requiresEmailVerification: true, | 157 | enabled: true, |
175 | limit: 10 | 158 | requiresEmailVerification: true, |
159 | limit: 10 | ||
160 | } | ||
176 | } | 161 | } |
177 | }) | 162 | }) |
178 | 163 | ||
179 | await userLogin(server, user2) | 164 | await server.login.getAccessToken(user2) |
180 | }) | 165 | }) |
181 | 166 | ||
182 | after(async function () { | 167 | after(async function () { |
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 87ba775f6..1419ae820 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -2,63 +2,24 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' | ||
6 | import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' | ||
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { | 5 | import { |
9 | addVideoCommentThread, | ||
10 | blockUser, | ||
11 | cleanupTests, | 6 | cleanupTests, |
12 | closeAllSequelize, | 7 | createSingleServer, |
13 | createUser, | ||
14 | deleteMe, | ||
15 | flushAndRunServer, | ||
16 | getAccountRatings, | ||
17 | getAdminAbusesList, | ||
18 | getBlacklistedVideosList, | ||
19 | getCustomConfig, | ||
20 | getMyUserInformation, | ||
21 | getMyUserVideoQuotaUsed, | ||
22 | getMyUserVideoRating, | ||
23 | getUserInformation, | ||
24 | getUsersList, | ||
25 | getUsersListPaginationAndSort, | ||
26 | getVideoChannel, | ||
27 | getVideosList, | ||
28 | installPlugin, | ||
29 | killallServers, | 8 | killallServers, |
30 | login, | ||
31 | makePutBodyRequest, | 9 | makePutBodyRequest, |
32 | rateVideo, | 10 | PeerTubeServer, |
33 | registerUserWithChannel, | 11 | setAccessTokensToServers, |
34 | removeUser, | ||
35 | removeVideo, | ||
36 | reportAbuse, | ||
37 | reRunServer, | ||
38 | ServerInfo, | ||
39 | setTokenField, | ||
40 | testImage, | 12 | testImage, |
41 | unblockUser, | ||
42 | updateAbuse, | ||
43 | updateCustomSubConfig, | ||
44 | updateMyAvatar, | ||
45 | updateMyUser, | ||
46 | updateUser, | ||
47 | uploadVideo, | ||
48 | userLogin, | ||
49 | waitJobs | 13 | waitJobs |
50 | } from '../../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
51 | import { follow } from '../../../../shared/extra-utils/server/follows' | 15 | import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' |
52 | import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
53 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | ||
54 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
55 | 16 | ||
56 | const expect = chai.expect | 17 | const expect = chai.expect |
57 | 18 | ||
58 | describe('Test users', function () { | 19 | describe('Test users', function () { |
59 | let server: ServerInfo | 20 | let server: PeerTubeServer |
60 | let accessToken: string | 21 | let token: string |
61 | let accessTokenUser: string | 22 | let userToken: string |
62 | let videoId: number | 23 | let videoId: number |
63 | let userId: number | 24 | let userId: number |
64 | const user = { | 25 | const user = { |
@@ -69,7 +30,7 @@ describe('Test users', function () { | |||
69 | before(async function () { | 30 | before(async function () { |
70 | this.timeout(30000) | 31 | this.timeout(30000) |
71 | 32 | ||
72 | server = await flushAndRunServer(1, { | 33 | server = await createSingleServer(1, { |
73 | rates_limit: { | 34 | rates_limit: { |
74 | login: { | 35 | login: { |
75 | max: 30 | 36 | max: 30 |
@@ -79,7 +40,7 @@ describe('Test users', function () { | |||
79 | 40 | ||
80 | await setAccessTokensToServers([ server ]) | 41 | await setAccessTokensToServers([ server ]) |
81 | 42 | ||
82 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | 43 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) |
83 | }) | 44 | }) |
84 | 45 | ||
85 | describe('OAuth client', function () { | 46 | describe('OAuth client', function () { |
@@ -90,158 +51,156 @@ describe('Test users', function () { | |||
90 | it('Should remove the last client') | 51 | it('Should remove the last client') |
91 | 52 | ||
92 | it('Should not login with an invalid client id', async function () { | 53 | it('Should not login with an invalid client id', async function () { |
93 | const client = { id: 'client', secret: server.client.secret } | 54 | const client = { id: 'client', secret: server.store.client.secret } |
94 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 55 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
95 | 56 | ||
96 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 57 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
97 | expect(res.body.error).to.contain('client is invalid') | 58 | expect(body.error).to.contain('client is invalid') |
98 | expect(res.body.type.startsWith('https://')).to.be.true | 59 | expect(body.type.startsWith('https://')).to.be.true |
99 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 60 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
100 | }) | 61 | }) |
101 | 62 | ||
102 | it('Should not login with an invalid client secret', async function () { | 63 | it('Should not login with an invalid client secret', async function () { |
103 | const client = { id: server.client.id, secret: 'coucou' } | 64 | const client = { id: server.store.client.id, secret: 'coucou' } |
104 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 65 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
105 | 66 | ||
106 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 67 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
107 | expect(res.body.error).to.contain('client is invalid') | 68 | expect(body.error).to.contain('client is invalid') |
108 | expect(res.body.type.startsWith('https://')).to.be.true | 69 | expect(body.type.startsWith('https://')).to.be.true |
109 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 70 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
110 | }) | 71 | }) |
111 | }) | 72 | }) |
112 | 73 | ||
113 | describe('Login', function () { | 74 | describe('Login', function () { |
114 | 75 | ||
115 | it('Should not login with an invalid username', async function () { | 76 | it('Should not login with an invalid username', async function () { |
116 | const user = { username: 'captain crochet', password: server.user.password } | 77 | const user = { username: 'captain crochet', password: server.store.user.password } |
117 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 78 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
118 | 79 | ||
119 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 80 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
120 | expect(res.body.error).to.contain('credentials are invalid') | 81 | expect(body.error).to.contain('credentials are invalid') |
121 | expect(res.body.type.startsWith('https://')).to.be.true | 82 | expect(body.type.startsWith('https://')).to.be.true |
122 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 83 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
123 | }) | 84 | }) |
124 | 85 | ||
125 | it('Should not login with an invalid password', async function () { | 86 | it('Should not login with an invalid password', async function () { |
126 | const user = { username: server.user.username, password: 'mew_three' } | 87 | const user = { username: server.store.user.username, password: 'mew_three' } |
127 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 88 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
128 | 89 | ||
129 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 90 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
130 | expect(res.body.error).to.contain('credentials are invalid') | 91 | expect(body.error).to.contain('credentials are invalid') |
131 | expect(res.body.type.startsWith('https://')).to.be.true | 92 | expect(body.type.startsWith('https://')).to.be.true |
132 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 93 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
133 | }) | 94 | }) |
134 | 95 | ||
135 | it('Should not be able to upload a video', async function () { | 96 | it('Should not be able to upload a video', async function () { |
136 | accessToken = 'my_super_token' | 97 | token = 'my_super_token' |
137 | 98 | ||
138 | const videoAttributes = {} | 99 | await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
139 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) | ||
140 | }) | 100 | }) |
141 | 101 | ||
142 | it('Should not be able to follow', async function () { | 102 | it('Should not be able to follow', async function () { |
143 | accessToken = 'my_super_token' | 103 | token = 'my_super_token' |
144 | await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) | 104 | |
105 | await server.follows.follow({ | ||
106 | hosts: [ 'http://example.com' ], | ||
107 | token, | ||
108 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
109 | }) | ||
145 | }) | 110 | }) |
146 | 111 | ||
147 | it('Should not be able to unfollow') | 112 | it('Should not be able to unfollow') |
148 | 113 | ||
149 | it('Should be able to login', async function () { | 114 | it('Should be able to login', async function () { |
150 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) | 115 | const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 }) |
151 | 116 | ||
152 | accessToken = res.body.access_token | 117 | token = body.access_token |
153 | }) | 118 | }) |
154 | 119 | ||
155 | it('Should be able to login with an insensitive username', async function () { | 120 | it('Should be able to login with an insensitive username', async function () { |
156 | const user = { username: 'RoOt', password: server.user.password } | 121 | const user = { username: 'RoOt', password: server.store.user.password } |
157 | await login(server.url, server.client, user, HttpStatusCode.OK_200) | 122 | await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 }) |
158 | 123 | ||
159 | const user2 = { username: 'rOoT', password: server.user.password } | 124 | const user2 = { username: 'rOoT', password: server.store.user.password } |
160 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) | 125 | await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) |
161 | 126 | ||
162 | const user3 = { username: 'ROOt', password: server.user.password } | 127 | const user3 = { username: 'ROOt', password: server.store.user.password } |
163 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) | 128 | await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) |
164 | }) | 129 | }) |
165 | }) | 130 | }) |
166 | 131 | ||
167 | describe('Upload', function () { | 132 | describe('Upload', function () { |
168 | 133 | ||
169 | it('Should upload the video with the correct token', async function () { | 134 | it('Should upload the video with the correct token', async function () { |
170 | const videoAttributes = {} | 135 | await server.videos.upload({ token }) |
171 | await uploadVideo(server.url, accessToken, videoAttributes) | 136 | const { data } = await server.videos.list() |
172 | const res = await getVideosList(server.url) | 137 | const video = data[0] |
173 | const video = res.body.data[0] | ||
174 | 138 | ||
175 | expect(video.account.name).to.equal('root') | 139 | expect(video.account.name).to.equal('root') |
176 | videoId = video.id | 140 | videoId = video.id |
177 | }) | 141 | }) |
178 | 142 | ||
179 | it('Should upload the video again with the correct token', async function () { | 143 | it('Should upload the video again with the correct token', async function () { |
180 | const videoAttributes = {} | 144 | await server.videos.upload({ token }) |
181 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
182 | }) | 145 | }) |
183 | }) | 146 | }) |
184 | 147 | ||
185 | describe('Ratings', function () { | 148 | describe('Ratings', function () { |
186 | 149 | ||
187 | it('Should retrieve a video rating', async function () { | 150 | it('Should retrieve a video rating', async function () { |
188 | await rateVideo(server.url, accessToken, videoId, 'like') | 151 | await server.videos.rate({ id: videoId, rating: 'like' }) |
189 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | 152 | const rating = await server.users.getMyRating({ token, videoId }) |
190 | const rating = res.body | ||
191 | 153 | ||
192 | expect(rating.videoId).to.equal(videoId) | 154 | expect(rating.videoId).to.equal(videoId) |
193 | expect(rating.rating).to.equal('like') | 155 | expect(rating.rating).to.equal('like') |
194 | }) | 156 | }) |
195 | 157 | ||
196 | it('Should retrieve ratings list', async function () { | 158 | it('Should retrieve ratings list', async function () { |
197 | await rateVideo(server.url, accessToken, videoId, 'like') | 159 | await server.videos.rate({ id: videoId, rating: 'like' }) |
198 | 160 | ||
199 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) | 161 | const body = await server.accounts.listRatings({ accountName: server.store.user.username }) |
200 | const ratings = res.body | ||
201 | 162 | ||
202 | expect(ratings.total).to.equal(1) | 163 | expect(body.total).to.equal(1) |
203 | expect(ratings.data[0].video.id).to.equal(videoId) | 164 | expect(body.data[0].video.id).to.equal(videoId) |
204 | expect(ratings.data[0].rating).to.equal('like') | 165 | expect(body.data[0].rating).to.equal('like') |
205 | }) | 166 | }) |
206 | 167 | ||
207 | it('Should retrieve ratings list by rating type', async function () { | 168 | it('Should retrieve ratings list by rating type', async function () { |
208 | { | 169 | { |
209 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | 170 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' }) |
210 | const ratings = res.body | 171 | expect(body.data.length).to.equal(1) |
211 | expect(ratings.data.length).to.equal(1) | ||
212 | } | 172 | } |
213 | 173 | ||
214 | { | 174 | { |
215 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | 175 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' }) |
216 | const ratings = res.body | 176 | expect(body.data.length).to.equal(0) |
217 | expect(ratings.data.length).to.equal(0) | ||
218 | } | 177 | } |
219 | }) | 178 | }) |
220 | }) | 179 | }) |
221 | 180 | ||
222 | describe('Remove video', function () { | 181 | describe('Remove video', function () { |
223 | it('Should not be able to remove the video with an incorrect token', async function () { | 182 | it('Should not be able to remove the video with an incorrect token', async function () { |
224 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) | 183 | await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
225 | }) | 184 | }) |
226 | 185 | ||
227 | it('Should not be able to remove the video with the token of another account') | 186 | it('Should not be able to remove the video with the token of another account') |
228 | 187 | ||
229 | it('Should be able to remove the video with the correct token', async function () { | 188 | it('Should be able to remove the video with the correct token', async function () { |
230 | await removeVideo(server.url, accessToken, videoId) | 189 | await server.videos.remove({ token, id: videoId }) |
231 | }) | 190 | }) |
232 | }) | 191 | }) |
233 | 192 | ||
234 | describe('Logout', function () { | 193 | describe('Logout', function () { |
235 | it('Should logout (revoke token)', async function () { | 194 | it('Should logout (revoke token)', async function () { |
236 | await logout(server.url, server.accessToken) | 195 | await server.login.logout({ token: server.accessToken }) |
237 | }) | 196 | }) |
238 | 197 | ||
239 | it('Should not be able to get the user information', async function () { | 198 | it('Should not be able to get the user information', async function () { |
240 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) | 199 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
241 | }) | 200 | }) |
242 | 201 | ||
243 | it('Should not be able to upload a video', async function () { | 202 | it('Should not be able to upload a video', async function () { |
244 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) | 203 | await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
245 | }) | 204 | }) |
246 | 205 | ||
247 | it('Should not be able to rate a video', async function () { | 206 | it('Should not be able to rate a video', async function () { |
@@ -255,79 +214,70 @@ describe('Test users', function () { | |||
255 | path: path + videoId, | 214 | path: path + videoId, |
256 | token: 'wrong token', | 215 | token: 'wrong token', |
257 | fields: data, | 216 | fields: data, |
258 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | 217 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
259 | } | 218 | } |
260 | await makePutBodyRequest(options) | 219 | await makePutBodyRequest(options) |
261 | }) | 220 | }) |
262 | 221 | ||
263 | it('Should be able to login again', async function () { | 222 | it('Should be able to login again', async function () { |
264 | const res = await login(server.url, server.client, server.user) | 223 | const body = await server.login.login() |
265 | server.accessToken = res.body.access_token | 224 | server.accessToken = body.access_token |
266 | server.refreshToken = res.body.refresh_token | 225 | server.refreshToken = body.refresh_token |
267 | }) | 226 | }) |
268 | 227 | ||
269 | it('Should be able to get my user information again', async function () { | 228 | it('Should be able to get my user information again', async function () { |
270 | await getMyUserInformation(server.url, server.accessToken) | 229 | await server.users.getMyInfo() |
271 | }) | 230 | }) |
272 | 231 | ||
273 | it('Should have an expired access token', async function () { | 232 | it('Should have an expired access token', async function () { |
274 | this.timeout(15000) | 233 | this.timeout(15000) |
275 | 234 | ||
276 | await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) | 235 | await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) |
277 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) | 236 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) |
278 | 237 | ||
279 | killallServers([ server ]) | 238 | await killallServers([ server ]) |
280 | await reRunServer(server) | 239 | await server.run() |
281 | 240 | ||
282 | await getMyUserInformation(server.url, server.accessToken, 401) | 241 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
283 | }) | 242 | }) |
284 | 243 | ||
285 | it('Should not be able to refresh an access token with an expired refresh token', async function () { | 244 | it('Should not be able to refresh an access token with an expired refresh token', async function () { |
286 | await refreshToken(server, server.refreshToken, 400) | 245 | await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
287 | }) | 246 | }) |
288 | 247 | ||
289 | it('Should refresh the token', async function () { | 248 | it('Should refresh the token', async function () { |
290 | this.timeout(15000) | 249 | this.timeout(15000) |
291 | 250 | ||
292 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() | 251 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() |
293 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate) | 252 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) |
294 | 253 | ||
295 | killallServers([ server ]) | 254 | await killallServers([ server ]) |
296 | await reRunServer(server) | 255 | await server.run() |
297 | 256 | ||
298 | const res = await refreshToken(server, server.refreshToken) | 257 | const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) |
299 | server.accessToken = res.body.access_token | 258 | server.accessToken = res.body.access_token |
300 | server.refreshToken = res.body.refresh_token | 259 | server.refreshToken = res.body.refresh_token |
301 | }) | 260 | }) |
302 | 261 | ||
303 | it('Should be able to get my user information again', async function () { | 262 | it('Should be able to get my user information again', async function () { |
304 | await getMyUserInformation(server.url, server.accessToken) | 263 | await server.users.getMyInfo() |
305 | }) | 264 | }) |
306 | }) | 265 | }) |
307 | 266 | ||
308 | describe('Creating a user', function () { | 267 | describe('Creating a user', function () { |
309 | 268 | ||
310 | it('Should be able to create a new user', async function () { | 269 | it('Should be able to create a new user', async function () { |
311 | await createUser({ | 270 | await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) |
312 | url: server.url, | ||
313 | accessToken: accessToken, | ||
314 | username: user.username, | ||
315 | password: user.password, | ||
316 | videoQuota: 2 * 1024 * 1024, | ||
317 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST | ||
318 | }) | ||
319 | }) | 271 | }) |
320 | 272 | ||
321 | it('Should be able to login with this user', async function () { | 273 | it('Should be able to login with this user', async function () { |
322 | accessTokenUser = await userLogin(server, user) | 274 | userToken = await server.login.getAccessToken(user) |
323 | }) | 275 | }) |
324 | 276 | ||
325 | it('Should be able to get user information', async function () { | 277 | it('Should be able to get user information', async function () { |
326 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | 278 | const userMe = await server.users.getMyInfo({ token: userToken }) |
327 | const userMe: MyUser = res1.body | ||
328 | 279 | ||
329 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) | 280 | const userGet = await server.users.get({ userId: userMe.id, withStats: true }) |
330 | const userGet: User = res2.body | ||
331 | 281 | ||
332 | for (const user of [ userMe, userGet ]) { | 282 | for (const user of [ userMe, userGet ]) { |
333 | expect(user.username).to.equal('user_1') | 283 | expect(user.username).to.equal('user_1') |
@@ -363,34 +313,28 @@ describe('Test users', function () { | |||
363 | it('Should be able to upload a video with this user', async function () { | 313 | it('Should be able to upload a video with this user', async function () { |
364 | this.timeout(10000) | 314 | this.timeout(10000) |
365 | 315 | ||
366 | const videoAttributes = { | 316 | const attributes = { |
367 | name: 'super user video', | 317 | name: 'super user video', |
368 | fixture: 'video_short.webm' | 318 | fixture: 'video_short.webm' |
369 | } | 319 | } |
370 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 320 | await server.videos.upload({ token: userToken, attributes }) |
371 | }) | 321 | }) |
372 | 322 | ||
373 | it('Should have video quota updated', async function () { | 323 | it('Should have video quota updated', async function () { |
374 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | 324 | const quota = await server.users.getMyQuotaUsed({ token: userToken }) |
375 | const data = res.body | 325 | expect(quota.videoQuotaUsed).to.equal(218910) |
376 | |||
377 | expect(data.videoQuotaUsed).to.equal(218910) | ||
378 | |||
379 | const resUsers = await getUsersList(server.url, server.accessToken) | ||
380 | 326 | ||
381 | const users: User[] = resUsers.body.data | 327 | const { data } = await server.users.list() |
382 | const tmpUser = users.find(u => u.username === user.username) | 328 | const tmpUser = data.find(u => u.username === user.username) |
383 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | 329 | expect(tmpUser.videoQuotaUsed).to.equal(218910) |
384 | }) | 330 | }) |
385 | 331 | ||
386 | it('Should be able to list my videos', async function () { | 332 | it('Should be able to list my videos', async function () { |
387 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | 333 | const { total, data } = await server.videos.listMyVideos({ token: userToken }) |
388 | expect(res.body.total).to.equal(1) | 334 | expect(total).to.equal(1) |
335 | expect(data).to.have.lengthOf(1) | ||
389 | 336 | ||
390 | const videos = res.body.data | 337 | const video: Video = data[0] |
391 | expect(videos).to.have.lengthOf(1) | ||
392 | |||
393 | const video: Video = videos[0] | ||
394 | expect(video.name).to.equal('super user video') | 338 | expect(video.name).to.equal('super user video') |
395 | expect(video.thumbnailPath).to.not.be.null | 339 | expect(video.thumbnailPath).to.not.be.null |
396 | expect(video.previewPath).to.not.be.null | 340 | expect(video.previewPath).to.not.be.null |
@@ -398,19 +342,15 @@ describe('Test users', function () { | |||
398 | 342 | ||
399 | it('Should be able to search in my videos', async function () { | 343 | it('Should be able to search in my videos', async function () { |
400 | { | 344 | { |
401 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') | 345 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) |
402 | expect(res.body.total).to.equal(1) | 346 | expect(total).to.equal(1) |
403 | 347 | expect(data).to.have.lengthOf(1) | |
404 | const videos = res.body.data | ||
405 | expect(videos).to.have.lengthOf(1) | ||
406 | } | 348 | } |
407 | 349 | ||
408 | { | 350 | { |
409 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') | 351 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) |
410 | expect(res.body.total).to.equal(0) | 352 | expect(total).to.equal(0) |
411 | 353 | expect(data).to.have.lengthOf(0) | |
412 | const videos = res.body.data | ||
413 | expect(videos).to.have.lengthOf(0) | ||
414 | } | 354 | } |
415 | }) | 355 | }) |
416 | 356 | ||
@@ -418,28 +358,25 @@ describe('Test users', function () { | |||
418 | this.timeout(60000) | 358 | this.timeout(60000) |
419 | 359 | ||
420 | { | 360 | { |
421 | const res = await getCustomConfig(server.url, server.accessToken) | 361 | const config = await server.config.getCustomConfig() |
422 | const config = res.body as CustomConfig | ||
423 | config.transcoding.webtorrent.enabled = false | 362 | config.transcoding.webtorrent.enabled = false |
424 | config.transcoding.hls.enabled = true | 363 | config.transcoding.hls.enabled = true |
425 | config.transcoding.enabled = true | 364 | config.transcoding.enabled = true |
426 | await updateCustomSubConfig(server.url, server.accessToken, config) | 365 | await server.config.updateCustomSubConfig({ newConfig: config }) |
427 | } | 366 | } |
428 | 367 | ||
429 | { | 368 | { |
430 | const videoAttributes = { | 369 | const attributes = { |
431 | name: 'super user video 2', | 370 | name: 'super user video 2', |
432 | fixture: 'video_short.webm' | 371 | fixture: 'video_short.webm' |
433 | } | 372 | } |
434 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 373 | await server.videos.upload({ token: userToken, attributes }) |
435 | 374 | ||
436 | await waitJobs([ server ]) | 375 | await waitJobs([ server ]) |
437 | } | 376 | } |
438 | 377 | ||
439 | { | 378 | { |
440 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | 379 | const data = await server.users.getMyQuotaUsed({ token: userToken }) |
441 | const data = res.body | ||
442 | |||
443 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | 380 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) |
444 | } | 381 | } |
445 | }) | 382 | }) |
@@ -448,21 +385,18 @@ describe('Test users', function () { | |||
448 | describe('Users listing', function () { | 385 | describe('Users listing', function () { |
449 | 386 | ||
450 | it('Should list all the users', async function () { | 387 | it('Should list all the users', async function () { |
451 | const res = await getUsersList(server.url, server.accessToken) | 388 | const { data, total } = await server.users.list() |
452 | const result = res.body | ||
453 | const total = result.total | ||
454 | const users = result.data | ||
455 | 389 | ||
456 | expect(total).to.equal(2) | 390 | expect(total).to.equal(2) |
457 | expect(users).to.be.an('array') | 391 | expect(data).to.be.an('array') |
458 | expect(users.length).to.equal(2) | 392 | expect(data.length).to.equal(2) |
459 | 393 | ||
460 | const user = users[0] | 394 | const user = data[0] |
461 | expect(user.username).to.equal('user_1') | 395 | expect(user.username).to.equal('user_1') |
462 | expect(user.email).to.equal('user_1@example.com') | 396 | expect(user.email).to.equal('user_1@example.com') |
463 | expect(user.nsfwPolicy).to.equal('display') | 397 | expect(user.nsfwPolicy).to.equal('display') |
464 | 398 | ||
465 | const rootUser = users[1] | 399 | const rootUser = data[1] |
466 | expect(rootUser.username).to.equal('root') | 400 | expect(rootUser.username).to.equal('root') |
467 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 401 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
468 | expect(user.nsfwPolicy).to.equal('display') | 402 | expect(user.nsfwPolicy).to.equal('display') |
@@ -474,16 +408,12 @@ describe('Test users', function () { | |||
474 | }) | 408 | }) |
475 | 409 | ||
476 | it('Should list only the first user by username asc', async function () { | 410 | it('Should list only the first user by username asc', async function () { |
477 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | 411 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' }) |
478 | |||
479 | const result = res.body | ||
480 | const total = result.total | ||
481 | const users = result.data | ||
482 | 412 | ||
483 | expect(total).to.equal(2) | 413 | expect(total).to.equal(2) |
484 | expect(users.length).to.equal(1) | 414 | expect(data.length).to.equal(1) |
485 | 415 | ||
486 | const user = users[0] | 416 | const user = data[0] |
487 | expect(user.username).to.equal('root') | 417 | expect(user.username).to.equal('root') |
488 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 418 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
489 | expect(user.roleLabel).to.equal('Administrator') | 419 | expect(user.roleLabel).to.equal('Administrator') |
@@ -491,111 +421,90 @@ describe('Test users', function () { | |||
491 | }) | 421 | }) |
492 | 422 | ||
493 | it('Should list only the first user by username desc', async function () { | 423 | it('Should list only the first user by username desc', async function () { |
494 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | 424 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' }) |
495 | const result = res.body | ||
496 | const total = result.total | ||
497 | const users = result.data | ||
498 | 425 | ||
499 | expect(total).to.equal(2) | 426 | expect(total).to.equal(2) |
500 | expect(users.length).to.equal(1) | 427 | expect(data.length).to.equal(1) |
501 | 428 | ||
502 | const user = users[0] | 429 | const user = data[0] |
503 | expect(user.username).to.equal('user_1') | 430 | expect(user.username).to.equal('user_1') |
504 | expect(user.email).to.equal('user_1@example.com') | 431 | expect(user.email).to.equal('user_1@example.com') |
505 | expect(user.nsfwPolicy).to.equal('display') | 432 | expect(user.nsfwPolicy).to.equal('display') |
506 | }) | 433 | }) |
507 | 434 | ||
508 | it('Should list only the second user by createdAt desc', async function () { | 435 | it('Should list only the second user by createdAt desc', async function () { |
509 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | 436 | const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' }) |
510 | const result = res.body | ||
511 | const total = result.total | ||
512 | const users = result.data | ||
513 | |||
514 | expect(total).to.equal(2) | 437 | expect(total).to.equal(2) |
515 | expect(users.length).to.equal(1) | ||
516 | 438 | ||
517 | const user = users[0] | 439 | expect(data.length).to.equal(1) |
440 | |||
441 | const user = data[0] | ||
518 | expect(user.username).to.equal('user_1') | 442 | expect(user.username).to.equal('user_1') |
519 | expect(user.email).to.equal('user_1@example.com') | 443 | expect(user.email).to.equal('user_1@example.com') |
520 | expect(user.nsfwPolicy).to.equal('display') | 444 | expect(user.nsfwPolicy).to.equal('display') |
521 | }) | 445 | }) |
522 | 446 | ||
523 | it('Should list all the users by createdAt asc', async function () { | 447 | it('Should list all the users by createdAt asc', async function () { |
524 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | 448 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' }) |
525 | const result = res.body | ||
526 | const total = result.total | ||
527 | const users = result.data | ||
528 | 449 | ||
529 | expect(total).to.equal(2) | 450 | expect(total).to.equal(2) |
530 | expect(users.length).to.equal(2) | 451 | expect(data.length).to.equal(2) |
531 | 452 | ||
532 | expect(users[0].username).to.equal('root') | 453 | expect(data[0].username).to.equal('root') |
533 | expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') | 454 | expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') |
534 | expect(users[0].nsfwPolicy).to.equal('display') | 455 | expect(data[0].nsfwPolicy).to.equal('display') |
535 | 456 | ||
536 | expect(users[1].username).to.equal('user_1') | 457 | expect(data[1].username).to.equal('user_1') |
537 | expect(users[1].email).to.equal('user_1@example.com') | 458 | expect(data[1].email).to.equal('user_1@example.com') |
538 | expect(users[1].nsfwPolicy).to.equal('display') | 459 | expect(data[1].nsfwPolicy).to.equal('display') |
539 | }) | 460 | }) |
540 | 461 | ||
541 | it('Should search user by username', async function () { | 462 | it('Should search user by username', async function () { |
542 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | 463 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) |
543 | const users = res.body.data as User[] | 464 | expect(total).to.equal(1) |
544 | 465 | expect(data.length).to.equal(1) | |
545 | expect(res.body.total).to.equal(1) | 466 | expect(data[0].username).to.equal('root') |
546 | expect(users.length).to.equal(1) | ||
547 | |||
548 | expect(users[0].username).to.equal('root') | ||
549 | }) | 467 | }) |
550 | 468 | ||
551 | it('Should search user by email', async function () { | 469 | it('Should search user by email', async function () { |
552 | { | 470 | { |
553 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | 471 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) |
554 | const users = res.body.data as User[] | 472 | expect(total).to.equal(1) |
555 | 473 | expect(data.length).to.equal(1) | |
556 | expect(res.body.total).to.equal(1) | 474 | expect(data[0].username).to.equal('user_1') |
557 | expect(users.length).to.equal(1) | 475 | expect(data[0].email).to.equal('user_1@example.com') |
558 | |||
559 | expect(users[0].username).to.equal('user_1') | ||
560 | expect(users[0].email).to.equal('user_1@example.com') | ||
561 | } | 476 | } |
562 | 477 | ||
563 | { | 478 | { |
564 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | 479 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) |
565 | const users = res.body.data as User[] | 480 | expect(total).to.equal(2) |
566 | 481 | expect(data.length).to.equal(2) | |
567 | expect(res.body.total).to.equal(2) | 482 | expect(data[0].username).to.equal('root') |
568 | expect(users.length).to.equal(2) | 483 | expect(data[1].username).to.equal('user_1') |
569 | |||
570 | expect(users[0].username).to.equal('root') | ||
571 | expect(users[1].username).to.equal('user_1') | ||
572 | } | 484 | } |
573 | }) | 485 | }) |
574 | }) | 486 | }) |
575 | 487 | ||
576 | describe('Update my account', function () { | 488 | describe('Update my account', function () { |
489 | |||
577 | it('Should update my password', async function () { | 490 | it('Should update my password', async function () { |
578 | await updateMyUser({ | 491 | await server.users.updateMe({ |
579 | url: server.url, | 492 | token: userToken, |
580 | accessToken: accessTokenUser, | ||
581 | currentPassword: 'super password', | 493 | currentPassword: 'super password', |
582 | password: 'new password' | 494 | password: 'new password' |
583 | }) | 495 | }) |
584 | user.password = 'new password' | 496 | user.password = 'new password' |
585 | 497 | ||
586 | await userLogin(server, user, HttpStatusCode.OK_200) | 498 | await server.login.login({ user }) |
587 | }) | 499 | }) |
588 | 500 | ||
589 | it('Should be able to change the NSFW display attribute', async function () { | 501 | it('Should be able to change the NSFW display attribute', async function () { |
590 | await updateMyUser({ | 502 | await server.users.updateMe({ |
591 | url: server.url, | 503 | token: userToken, |
592 | accessToken: accessTokenUser, | ||
593 | nsfwPolicy: 'do_not_list' | 504 | nsfwPolicy: 'do_not_list' |
594 | }) | 505 | }) |
595 | 506 | ||
596 | const res = await getMyUserInformation(server.url, accessTokenUser) | 507 | const user = await server.users.getMyInfo({ token: userToken }) |
597 | const user = res.body | ||
598 | |||
599 | expect(user.username).to.equal('user_1') | 508 | expect(user.username).to.equal('user_1') |
600 | expect(user.email).to.equal('user_1@example.com') | 509 | expect(user.email).to.equal('user_1@example.com') |
601 | expect(user.nsfwPolicy).to.equal('do_not_list') | 510 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -606,42 +515,33 @@ describe('Test users', function () { | |||
606 | }) | 515 | }) |
607 | 516 | ||
608 | it('Should be able to change the autoPlayVideo attribute', async function () { | 517 | it('Should be able to change the autoPlayVideo attribute', async function () { |
609 | await updateMyUser({ | 518 | await server.users.updateMe({ |
610 | url: server.url, | 519 | token: userToken, |
611 | accessToken: accessTokenUser, | ||
612 | autoPlayVideo: false | 520 | autoPlayVideo: false |
613 | }) | 521 | }) |
614 | 522 | ||
615 | const res = await getMyUserInformation(server.url, accessTokenUser) | 523 | const user = await server.users.getMyInfo({ token: userToken }) |
616 | const user = res.body | ||
617 | |||
618 | expect(user.autoPlayVideo).to.be.false | 524 | expect(user.autoPlayVideo).to.be.false |
619 | }) | 525 | }) |
620 | 526 | ||
621 | it('Should be able to change the autoPlayNextVideo attribute', async function () { | 527 | it('Should be able to change the autoPlayNextVideo attribute', async function () { |
622 | await updateMyUser({ | 528 | await server.users.updateMe({ |
623 | url: server.url, | 529 | token: userToken, |
624 | accessToken: accessTokenUser, | ||
625 | autoPlayNextVideo: true | 530 | autoPlayNextVideo: true |
626 | }) | 531 | }) |
627 | 532 | ||
628 | const res = await getMyUserInformation(server.url, accessTokenUser) | 533 | const user = await server.users.getMyInfo({ token: userToken }) |
629 | const user = res.body | ||
630 | |||
631 | expect(user.autoPlayNextVideo).to.be.true | 534 | expect(user.autoPlayNextVideo).to.be.true |
632 | }) | 535 | }) |
633 | 536 | ||
634 | it('Should be able to change the email attribute', async function () { | 537 | it('Should be able to change the email attribute', async function () { |
635 | await updateMyUser({ | 538 | await server.users.updateMe({ |
636 | url: server.url, | 539 | token: userToken, |
637 | accessToken: accessTokenUser, | ||
638 | currentPassword: 'new password', | 540 | currentPassword: 'new password', |
639 | email: 'updated@example.com' | 541 | email: 'updated@example.com' |
640 | }) | 542 | }) |
641 | 543 | ||
642 | const res = await getMyUserInformation(server.url, accessTokenUser) | 544 | const user = await server.users.getMyInfo({ token: userToken }) |
643 | const user = res.body | ||
644 | |||
645 | expect(user.username).to.equal('user_1') | 545 | expect(user.username).to.equal('user_1') |
646 | expect(user.email).to.equal('updated@example.com') | 546 | expect(user.email).to.equal('updated@example.com') |
647 | expect(user.nsfwPolicy).to.equal('do_not_list') | 547 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -654,15 +554,9 @@ describe('Test users', function () { | |||
654 | it('Should be able to update my avatar with a gif', async function () { | 554 | it('Should be able to update my avatar with a gif', async function () { |
655 | const fixture = 'avatar.gif' | 555 | const fixture = 'avatar.gif' |
656 | 556 | ||
657 | await updateMyAvatar({ | 557 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
658 | url: server.url, | ||
659 | accessToken: accessTokenUser, | ||
660 | fixture | ||
661 | }) | ||
662 | |||
663 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
664 | const user = res.body | ||
665 | 558 | ||
559 | const user = await server.users.getMyInfo({ token: userToken }) | ||
666 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') | 560 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') |
667 | }) | 561 | }) |
668 | 562 | ||
@@ -670,29 +564,17 @@ describe('Test users', function () { | |||
670 | for (const extension of [ '.png', '.gif' ]) { | 564 | for (const extension of [ '.png', '.gif' ]) { |
671 | const fixture = 'avatar' + extension | 565 | const fixture = 'avatar' + extension |
672 | 566 | ||
673 | await updateMyAvatar({ | 567 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
674 | url: server.url, | ||
675 | accessToken: accessTokenUser, | ||
676 | fixture | ||
677 | }) | ||
678 | |||
679 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
680 | const user = res.body | ||
681 | 568 | ||
569 | const user = await server.users.getMyInfo({ token: userToken }) | ||
682 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) | 570 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) |
683 | } | 571 | } |
684 | }) | 572 | }) |
685 | 573 | ||
686 | it('Should be able to update my display name', async function () { | 574 | it('Should be able to update my display name', async function () { |
687 | await updateMyUser({ | 575 | await server.users.updateMe({ token: userToken, displayName: 'new display name' }) |
688 | url: server.url, | ||
689 | accessToken: accessTokenUser, | ||
690 | displayName: 'new display name' | ||
691 | }) | ||
692 | |||
693 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
694 | const user = res.body | ||
695 | 576 | ||
577 | const user = await server.users.getMyInfo({ token: userToken }) | ||
696 | expect(user.username).to.equal('user_1') | 578 | expect(user.username).to.equal('user_1') |
697 | expect(user.email).to.equal('updated@example.com') | 579 | expect(user.email).to.equal('updated@example.com') |
698 | expect(user.nsfwPolicy).to.equal('do_not_list') | 580 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -703,15 +585,9 @@ describe('Test users', function () { | |||
703 | }) | 585 | }) |
704 | 586 | ||
705 | it('Should be able to update my description', async function () { | 587 | it('Should be able to update my description', async function () { |
706 | await updateMyUser({ | 588 | await server.users.updateMe({ token: userToken, description: 'my super description updated' }) |
707 | url: server.url, | ||
708 | accessToken: accessTokenUser, | ||
709 | description: 'my super description updated' | ||
710 | }) | ||
711 | |||
712 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
713 | const user: User = res.body | ||
714 | 589 | ||
590 | const user = await server.users.getMyInfo({ token: userToken }) | ||
715 | expect(user.username).to.equal('user_1') | 591 | expect(user.username).to.equal('user_1') |
716 | expect(user.email).to.equal('updated@example.com') | 592 | expect(user.email).to.equal('updated@example.com') |
717 | expect(user.nsfwPolicy).to.equal('do_not_list') | 593 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -725,30 +601,21 @@ describe('Test users', function () { | |||
725 | 601 | ||
726 | it('Should be able to update my theme', async function () { | 602 | it('Should be able to update my theme', async function () { |
727 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | 603 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { |
728 | await updateMyUser({ | 604 | await server.users.updateMe({ token: userToken, theme }) |
729 | url: server.url, | ||
730 | accessToken: accessTokenUser, | ||
731 | theme | ||
732 | }) | ||
733 | 605 | ||
734 | const res = await getMyUserInformation(server.url, accessTokenUser) | 606 | const user = await server.users.getMyInfo({ token: userToken }) |
735 | const body: User = res.body | 607 | expect(user.theme).to.equal(theme) |
736 | |||
737 | expect(body.theme).to.equal(theme) | ||
738 | } | 608 | } |
739 | }) | 609 | }) |
740 | 610 | ||
741 | it('Should be able to update my modal preferences', async function () { | 611 | it('Should be able to update my modal preferences', async function () { |
742 | await updateMyUser({ | 612 | await server.users.updateMe({ |
743 | url: server.url, | 613 | token: userToken, |
744 | accessToken: accessTokenUser, | ||
745 | noInstanceConfigWarningModal: true, | 614 | noInstanceConfigWarningModal: true, |
746 | noWelcomeModal: true | 615 | noWelcomeModal: true |
747 | }) | 616 | }) |
748 | 617 | ||
749 | const res = await getMyUserInformation(server.url, accessTokenUser) | 618 | const user = await server.users.getMyInfo({ token: userToken }) |
750 | const user: User = res.body | ||
751 | |||
752 | expect(user.noWelcomeModal).to.be.true | 619 | expect(user.noWelcomeModal).to.be.true |
753 | expect(user.noInstanceConfigWarningModal).to.be.true | 620 | expect(user.noInstanceConfigWarningModal).to.be.true |
754 | }) | 621 | }) |
@@ -756,10 +623,9 @@ describe('Test users', function () { | |||
756 | 623 | ||
757 | describe('Updating another user', function () { | 624 | describe('Updating another user', function () { |
758 | it('Should be able to update another user', async function () { | 625 | it('Should be able to update another user', async function () { |
759 | await updateUser({ | 626 | await server.users.update({ |
760 | url: server.url, | ||
761 | userId, | 627 | userId, |
762 | accessToken, | 628 | token, |
763 | email: 'updated2@example.com', | 629 | email: 'updated2@example.com', |
764 | emailVerified: true, | 630 | emailVerified: true, |
765 | videoQuota: 42, | 631 | videoQuota: 42, |
@@ -768,8 +634,7 @@ describe('Test users', function () { | |||
768 | pluginAuth: 'toto' | 634 | pluginAuth: 'toto' |
769 | }) | 635 | }) |
770 | 636 | ||
771 | const res = await getUserInformation(server.url, accessToken, userId) | 637 | const user = await server.users.get({ token, userId }) |
772 | const user = res.body as User | ||
773 | 638 | ||
774 | expect(user.username).to.equal('user_1') | 639 | expect(user.username).to.equal('user_1') |
775 | expect(user.email).to.equal('updated2@example.com') | 640 | expect(user.email).to.equal('updated2@example.com') |
@@ -783,57 +648,50 @@ describe('Test users', function () { | |||
783 | }) | 648 | }) |
784 | 649 | ||
785 | it('Should reset the auth plugin', async function () { | 650 | it('Should reset the auth plugin', async function () { |
786 | await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) | 651 | await server.users.update({ userId, token, pluginAuth: null }) |
787 | 652 | ||
788 | const res = await getUserInformation(server.url, accessToken, userId) | 653 | const user = await server.users.get({ token, userId }) |
789 | const user = res.body as User | ||
790 | expect(user.pluginAuth).to.be.null | 654 | expect(user.pluginAuth).to.be.null |
791 | }) | 655 | }) |
792 | 656 | ||
793 | it('Should have removed the user token', async function () { | 657 | it('Should have removed the user token', async function () { |
794 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 658 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
795 | 659 | ||
796 | accessTokenUser = await userLogin(server, user) | 660 | userToken = await server.login.getAccessToken(user) |
797 | }) | 661 | }) |
798 | 662 | ||
799 | it('Should be able to update another user password', async function () { | 663 | it('Should be able to update another user password', async function () { |
800 | await updateUser({ | 664 | await server.users.update({ userId, token, password: 'password updated' }) |
801 | url: server.url, | ||
802 | userId, | ||
803 | accessToken, | ||
804 | password: 'password updated' | ||
805 | }) | ||
806 | 665 | ||
807 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 666 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
808 | 667 | ||
809 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 668 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
810 | 669 | ||
811 | user.password = 'password updated' | 670 | user.password = 'password updated' |
812 | accessTokenUser = await userLogin(server, user) | 671 | userToken = await server.login.getAccessToken(user) |
813 | }) | 672 | }) |
814 | }) | 673 | }) |
815 | 674 | ||
816 | describe('Video blacklists', function () { | 675 | describe('Video blacklists', function () { |
817 | it('Should be able to list video blacklist by a moderator', async function () { | 676 | it('Should be able to list video blacklist by a moderator', async function () { |
818 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | 677 | await server.blacklist.list({ token: userToken }) |
819 | }) | 678 | }) |
820 | }) | 679 | }) |
821 | 680 | ||
822 | describe('Remove a user', function () { | 681 | describe('Remove a user', function () { |
823 | it('Should be able to remove this user', async function () { | 682 | it('Should be able to remove this user', async function () { |
824 | await removeUser(server.url, userId, accessToken) | 683 | await server.users.remove({ userId, token }) |
825 | }) | 684 | }) |
826 | 685 | ||
827 | it('Should not be able to login with this user', async function () { | 686 | it('Should not be able to login with this user', async function () { |
828 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 687 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
829 | }) | 688 | }) |
830 | 689 | ||
831 | it('Should not have videos of this user', async function () { | 690 | it('Should not have videos of this user', async function () { |
832 | const res = await getVideosList(server.url) | 691 | const { data, total } = await server.videos.list() |
833 | 692 | expect(total).to.equal(1) | |
834 | expect(res.body.total).to.equal(1) | ||
835 | 693 | ||
836 | const video = res.body.data[0] | 694 | const video = data[0] |
837 | expect(video.account.name).to.equal('root') | 695 | expect(video.account.name).to.equal('root') |
838 | }) | 696 | }) |
839 | }) | 697 | }) |
@@ -845,7 +703,7 @@ describe('Test users', function () { | |||
845 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } | 703 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
846 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } | 704 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
847 | 705 | ||
848 | await registerUserWithChannel({ url: server.url, user, channel }) | 706 | await server.users.register({ ...user, channel }) |
849 | }) | 707 | }) |
850 | 708 | ||
851 | it('Should be able to login with this registered user', async function () { | 709 | it('Should be able to login with this registered user', async function () { |
@@ -854,40 +712,36 @@ describe('Test users', function () { | |||
854 | password: 'my super password' | 712 | password: 'my super password' |
855 | } | 713 | } |
856 | 714 | ||
857 | user15AccessToken = await userLogin(server, user15) | 715 | user15AccessToken = await server.login.getAccessToken(user15) |
858 | }) | 716 | }) |
859 | 717 | ||
860 | it('Should have the correct display name', async function () { | 718 | it('Should have the correct display name', async function () { |
861 | const res = await getMyUserInformation(server.url, user15AccessToken) | 719 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
862 | const user: User = res.body | ||
863 | |||
864 | expect(user.account.displayName).to.equal('super user 15') | 720 | expect(user.account.displayName).to.equal('super user 15') |
865 | }) | 721 | }) |
866 | 722 | ||
867 | it('Should have the correct video quota', async function () { | 723 | it('Should have the correct video quota', async function () { |
868 | const res = await getMyUserInformation(server.url, user15AccessToken) | 724 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
869 | const user = res.body | ||
870 | |||
871 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 725 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
872 | }) | 726 | }) |
873 | 727 | ||
874 | it('Should have created the channel', async function () { | 728 | it('Should have created the channel', async function () { |
875 | const res = await getVideoChannel(server.url, 'my_user_15_channel') | 729 | const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' }) |
876 | 730 | ||
877 | expect(res.body.displayName).to.equal('my channel rocks') | 731 | expect(displayName).to.equal('my channel rocks') |
878 | }) | 732 | }) |
879 | 733 | ||
880 | it('Should remove me', async function () { | 734 | it('Should remove me', async function () { |
881 | { | 735 | { |
882 | const res = await getUsersList(server.url, server.accessToken) | 736 | const { data } = await server.users.list() |
883 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | 737 | expect(data.find(u => u.username === 'user_15')).to.not.be.undefined |
884 | } | 738 | } |
885 | 739 | ||
886 | await deleteMe(server.url, user15AccessToken) | 740 | await server.users.deleteMe({ token: user15AccessToken }) |
887 | 741 | ||
888 | { | 742 | { |
889 | const res = await getUsersList(server.url, server.accessToken) | 743 | const { data } = await server.users.list() |
890 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | 744 | expect(data.find(u => u.username === 'user_15')).to.be.undefined |
891 | } | 745 | } |
892 | }) | 746 | }) |
893 | }) | 747 | }) |
@@ -901,49 +755,40 @@ describe('Test users', function () { | |||
901 | } | 755 | } |
902 | 756 | ||
903 | it('Should block a user', async function () { | 757 | it('Should block a user', async function () { |
904 | const resUser = await createUser({ | 758 | const user = await server.users.create({ ...user16 }) |
905 | url: server.url, | 759 | user16Id = user.id |
906 | accessToken: server.accessToken, | ||
907 | username: user16.username, | ||
908 | password: user16.password | ||
909 | }) | ||
910 | user16Id = resUser.body.user.id | ||
911 | 760 | ||
912 | user16AccessToken = await userLogin(server, user16) | 761 | user16AccessToken = await server.login.getAccessToken(user16) |
913 | 762 | ||
914 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 763 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
915 | await blockUser(server.url, user16Id, server.accessToken) | 764 | await server.users.banUser({ userId: user16Id }) |
916 | 765 | ||
917 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) | 766 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
918 | await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) | 767 | await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
919 | }) | 768 | }) |
920 | 769 | ||
921 | it('Should search user by banned status', async function () { | 770 | it('Should search user by banned status', async function () { |
922 | { | 771 | { |
923 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) | 772 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) |
924 | const users = res.body.data as User[] | 773 | expect(total).to.equal(1) |
774 | expect(data.length).to.equal(1) | ||
925 | 775 | ||
926 | expect(res.body.total).to.equal(1) | 776 | expect(data[0].username).to.equal(user16.username) |
927 | expect(users.length).to.equal(1) | ||
928 | |||
929 | expect(users[0].username).to.equal(user16.username) | ||
930 | } | 777 | } |
931 | 778 | ||
932 | { | 779 | { |
933 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) | 780 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) |
934 | const users = res.body.data as User[] | 781 | expect(total).to.equal(1) |
935 | 782 | expect(data.length).to.equal(1) | |
936 | expect(res.body.total).to.equal(1) | ||
937 | expect(users.length).to.equal(1) | ||
938 | 783 | ||
939 | expect(users[0].username).to.not.equal(user16.username) | 784 | expect(data[0].username).to.not.equal(user16.username) |
940 | } | 785 | } |
941 | }) | 786 | }) |
942 | 787 | ||
943 | it('Should unblock a user', async function () { | 788 | it('Should unblock a user', async function () { |
944 | await unblockUser(server.url, user16Id, server.accessToken) | 789 | await server.users.unbanUser({ userId: user16Id }) |
945 | user16AccessToken = await userLogin(server, user16) | 790 | user16AccessToken = await server.login.getAccessToken(user16) |
946 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 791 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
947 | }) | 792 | }) |
948 | }) | 793 | }) |
949 | 794 | ||
@@ -956,19 +801,12 @@ describe('Test users', function () { | |||
956 | username: 'user_17', | 801 | username: 'user_17', |
957 | password: 'my super password' | 802 | password: 'my super password' |
958 | } | 803 | } |
959 | const resUser = await createUser({ | 804 | const created = await server.users.create({ ...user17 }) |
960 | url: server.url, | ||
961 | accessToken: server.accessToken, | ||
962 | username: user17.username, | ||
963 | password: user17.password | ||
964 | }) | ||
965 | 805 | ||
966 | user17Id = resUser.body.user.id | 806 | user17Id = created.id |
967 | user17AccessToken = await userLogin(server, user17) | 807 | user17AccessToken = await server.login.getAccessToken(user17) |
968 | |||
969 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
970 | const user: User = res.body | ||
971 | 808 | ||
809 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
972 | expect(user.videosCount).to.equal(0) | 810 | expect(user.videosCount).to.equal(0) |
973 | expect(user.videoCommentsCount).to.equal(0) | 811 | expect(user.videoCommentsCount).to.equal(0) |
974 | expect(user.abusesCount).to.equal(0) | 812 | expect(user.abusesCount).to.equal(0) |
@@ -977,54 +815,43 @@ describe('Test users', function () { | |||
977 | }) | 815 | }) |
978 | 816 | ||
979 | it('Should report correct videos count', async function () { | 817 | it('Should report correct videos count', async function () { |
980 | const videoAttributes = { | 818 | const attributes = { name: 'video to test user stats' } |
981 | name: 'video to test user stats' | 819 | await server.videos.upload({ token: user17AccessToken, attributes }) |
982 | } | ||
983 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | ||
984 | const res1 = await getVideosList(server.url) | ||
985 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | ||
986 | 820 | ||
987 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 821 | const { data } = await server.videos.list() |
988 | const user: User = res2.body | 822 | videoId = data.find(video => video.name === attributes.name).id |
989 | 823 | ||
824 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
990 | expect(user.videosCount).to.equal(1) | 825 | expect(user.videosCount).to.equal(1) |
991 | }) | 826 | }) |
992 | 827 | ||
993 | it('Should report correct video comments for user', async function () { | 828 | it('Should report correct video comments for user', async function () { |
994 | const text = 'super comment' | 829 | const text = 'super comment' |
995 | await addVideoCommentThread(server.url, user17AccessToken, videoId, text) | 830 | await server.comments.createThread({ token: user17AccessToken, videoId, text }) |
996 | |||
997 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
998 | const user: User = res.body | ||
999 | 831 | ||
832 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
1000 | expect(user.videoCommentsCount).to.equal(1) | 833 | expect(user.videoCommentsCount).to.equal(1) |
1001 | }) | 834 | }) |
1002 | 835 | ||
1003 | it('Should report correct abuses counts', async function () { | 836 | it('Should report correct abuses counts', async function () { |
1004 | const reason = 'my super bad reason' | 837 | const reason = 'my super bad reason' |
1005 | await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) | 838 | await server.abuses.report({ token: user17AccessToken, videoId, reason }) |
1006 | |||
1007 | const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) | ||
1008 | const abuseId = res1.body.data[0].id | ||
1009 | 839 | ||
1010 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 840 | const body1 = await server.abuses.getAdminList() |
1011 | const user2: User = res2.body | 841 | const abuseId = body1.data[0].id |
1012 | 842 | ||
843 | const user2 = await server.users.get({ userId: user17Id, withStats: true }) | ||
1013 | expect(user2.abusesCount).to.equal(1) // number of incriminations | 844 | expect(user2.abusesCount).to.equal(1) // number of incriminations |
1014 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created | 845 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created |
1015 | 846 | ||
1016 | const body: AbuseUpdate = { state: AbuseState.ACCEPTED } | 847 | await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
1017 | await updateAbuse(server.url, server.accessToken, abuseId, body) | ||
1018 | |||
1019 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
1020 | const user3: User = res3.body | ||
1021 | 848 | ||
849 | const user3 = await server.users.get({ userId: user17Id, withStats: true }) | ||
1022 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted | 850 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted |
1023 | }) | 851 | }) |
1024 | }) | 852 | }) |
1025 | 853 | ||
1026 | after(async function () { | 854 | after(async function () { |
1027 | await closeAllSequelize([ server ]) | ||
1028 | await cleanupTests([ server ]) | 855 | await cleanupTests([ server ]) |
1029 | }) | 856 | }) |
1030 | }) | 857 | }) |