aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/activitypub/fetch.ts3
-rw-r--r--server/tests/api/activitypub/refresher.ts5
-rw-r--r--server/tests/api/check-params/abuses.ts6
-rw-r--r--server/tests/api/check-params/blocklist.ts3
-rw-r--r--server/tests/api/check-params/bulk.ts3
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/custom-pages.ts3
-rw-r--r--server/tests/api/check-params/debug.ts3
-rw-r--r--server/tests/api/check-params/follows.ts3
-rw-r--r--server/tests/api/check-params/jobs.ts3
-rw-r--r--server/tests/api/check-params/live.ts20
-rw-r--r--server/tests/api/check-params/logs.ts3
-rw-r--r--server/tests/api/check-params/plugins.ts3
-rw-r--r--server/tests/api/check-params/redundancy.ts3
-rw-r--r--server/tests/api/check-params/upload-quota.ts35
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts3
-rw-r--r--server/tests/api/check-params/users.ts243
-rw-r--r--server/tests/api/check-params/video-blacklist.ts5
-rw-r--r--server/tests/api/check-params/video-captions.ts3
-rw-r--r--server/tests/api/check-params/video-channels.ts3
-rw-r--r--server/tests/api/check-params/video-comments.ts5
-rw-r--r--server/tests/api/check-params/video-imports.ts14
-rw-r--r--server/tests/api/check-params/video-playlists.ts3
-rw-r--r--server/tests/api/check-params/videos-filter.ts16
-rw-r--r--server/tests/api/check-params/videos.ts18
-rw-r--r--server/tests/api/live/live-constraints.ts8
-rw-r--r--server/tests/api/moderation/abuses.ts15
-rw-r--r--server/tests/api/moderation/blocklist-notification.ts9
-rw-r--r--server/tests/api/moderation/blocklist.ts7
-rw-r--r--server/tests/api/moderation/video-blacklist.ts17
-rw-r--r--server/tests/api/notifications/comments-notifications.ts14
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts11
-rw-r--r--server/tests/api/notifications/notifications-api.ts25
-rw-r--r--server/tests/api/notifications/user-notifications.ts18
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts8
-rw-r--r--server/tests/api/search/search-channels.ts4
-rw-r--r--server/tests/api/server/bulk.ts7
-rw-r--r--server/tests/api/server/config.ts7
-rw-r--r--server/tests/api/server/email.ts73
-rw-r--r--server/tests/api/server/follow-constraints.ts3
-rw-r--r--server/tests/api/server/follows.ts5
-rw-r--r--server/tests/api/server/jobs.ts2
-rw-r--r--server/tests/api/server/plugins.ts18
-rw-r--r--server/tests/api/server/reverse-proxy.ts18
-rw-r--r--server/tests/api/server/stats.ts3
-rw-r--r--server/tests/api/users/user-subscriptions.ts3
-rw-r--r--server/tests/api/users/users-multiple-servers.ts45
-rw-r--r--server/tests/api/users/users-verification.ts48
-rw-r--r--server/tests/api/users/users.ts374
-rw-r--r--server/tests/api/videos/multiple-servers.ts3
-rw-r--r--server/tests/api/videos/resumable-upload.ts17
-rw-r--r--server/tests/api/videos/video-change-ownership.ts89
-rw-r--r--server/tests/api/videos/video-channels.ts22
-rw-r--r--server/tests/api/videos/video-comments.ts16
-rw-r--r--server/tests/api/videos/video-imports.ts9
-rw-r--r--server/tests/api/videos/video-nsfw.ts26
-rw-r--r--server/tests/api/videos/video-playlists.ts34
-rw-r--r--server/tests/api/videos/video-privacy.ts3
-rw-r--r--server/tests/api/videos/videos-filter.ts13
-rw-r--r--server/tests/api/videos/videos-history.ts12
-rw-r--r--server/tests/api/videos/videos-overview.ts12
61 files changed, 484 insertions, 926 deletions
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index c1af23016..162f3ec83 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 getVideosListSort, 9 getVideosListSort,
@@ -32,7 +31,7 @@ describe('Test ActivityPub fetcher', function () {
32 31
33 const user = { username: 'user1', password: 'password' } 32 const user = { username: 'user1', password: 'password' }
34 for (const server of servers) { 33 for (const server of servers) {
35 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 34 await server.usersCommand.create({ username: user.username, password: user.password })
36 } 35 }
37 36
38 const userAccessToken = await servers[0].loginCommand.getAccessToken(user) 37 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index af919f2f3..5a37dbc40 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -6,7 +6,6 @@ import {
6 cleanupTests, 6 cleanupTests,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
9 generateUserAccessToken,
10 getVideo, 9 getVideo,
11 killallServers, 10 killallServers,
12 reRunServer, 11 reRunServer,
@@ -44,10 +43,10 @@ describe('Test AP refresher', function () {
44 } 43 }
45 44
46 { 45 {
47 const a1 = await generateUserAccessToken(servers[1], 'user1') 46 const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
48 await uploadVideo(servers[1].url, a1, { name: 'video4' }) 47 await uploadVideo(servers[1].url, a1, { name: 'video4' })
49 48
50 const a2 = await generateUserAccessToken(servers[1], 'user2') 49 const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
51 await uploadVideo(servers[1].url, a2, { name: 'video5' }) 50 await uploadVideo(servers[1].url, a2, { name: 'video5' })
52 } 51 }
53 52
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 14949d301..4cd10a6fd 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -8,10 +8,8 @@ import {
8 checkBadSortPagination, 8 checkBadSortPagination,
9 checkBadStartPagination, 9 checkBadStartPagination,
10 cleanupTests, 10 cleanupTests,
11 createUser,
12 doubleFollow, 11 doubleFollow,
13 flushAndRunServer, 12 flushAndRunServer,
14 generateUserAccessToken,
15 getVideoIdFromUUID, 13 getVideoIdFromUUID,
16 makeGetRequest, 14 makeGetRequest,
17 makePostBodyRequest, 15 makePostBodyRequest,
@@ -45,10 +43,10 @@ describe('Test abuses API validators', function () {
45 43
46 const username = 'user1' 44 const username = 'user1'
47 const password = 'my super password' 45 const password = 'my super password'
48 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 46 await server.usersCommand.create({ username: username, password: password })
49 userToken = await server.loginCommand.getAccessToken({ username, password }) 47 userToken = await server.loginCommand.getAccessToken({ username, password })
50 48
51 userToken2 = await generateUserAccessToken(server, 'user_2') 49 userToken2 = await server.usersCommand.generateUserAndToken('user_2')
52 50
53 const res = await uploadVideo(server.url, server.accessToken, {}) 51 const res = await uploadVideo(server.url, server.accessToken, {})
54 server.video = res.body.video 52 server.video = res.body.video
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 11a79387f..18238bb04 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 makeDeleteRequest, 9 makeDeleteRequest,
@@ -34,7 +33,7 @@ describe('Test blocklist API validators', function () {
34 server = servers[0] 33 server = servers[0]
35 34
36 const user = { username: 'user1', password: 'password' } 35 const user = { username: 'user1', password: 'password' }
37 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 36 await server.usersCommand.create({ username: user.username, password: user.password })
38 37
39 userAccessToken = await server.loginCommand.getAccessToken(user) 38 userAccessToken = await server.loginCommand.getAccessToken(user)
40 39
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 85520b3bd..3f80c79a8 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests, 5 cleanupTests,
6 createUser,
7 flushAndRunServer, 6 flushAndRunServer,
8 ServerInfo, 7 ServerInfo,
9 setAccessTokensToServers 8 setAccessTokensToServers
@@ -24,7 +23,7 @@ describe('Test bulk API validators', function () {
24 await setAccessTokensToServers([ server ]) 23 await setAccessTokensToServers([ server ])
25 24
26 const user = { username: 'user1', password: 'password' } 25 const user = { username: 'user1', password: 'password' }
27 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 26 await server.usersCommand.create({ username: user.username, password: user.password })
28 27
29 userAccessToken = await server.loginCommand.getAccessToken(user) 28 userAccessToken = await server.loginCommand.getAccessToken(user)
30 }) 29 })
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index e93523e4b..c204d9415 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -5,7 +5,6 @@ import { omit } from 'lodash'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 flushAndRunServer, 8 flushAndRunServer,
10 makeDeleteRequest, 9 makeDeleteRequest,
11 makeGetRequest, 10 makeGetRequest,
@@ -206,7 +205,7 @@ describe('Test config API validators', function () {
206 username: 'user1', 205 username: 'user1',
207 password: 'password' 206 password: 'password'
208 } 207 }
209 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 208 await server.usersCommand.create({ username: user.username, password: user.password })
210 userAccessToken = await server.loginCommand.getAccessToken(user) 209 userAccessToken = await server.loginCommand.getAccessToken(user)
211 }) 210 })
212 211
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts
index c1dd258aa..58b0b8600 100644
--- a/server/tests/api/check-params/custom-pages.ts
+++ b/server/tests/api/check-params/custom-pages.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 ServerInfo, 8 ServerInfo,
10 setAccessTokensToServers 9 setAccessTokensToServers
@@ -26,7 +25,7 @@ describe('Test custom pages validators', function () {
26 await setAccessTokensToServers([ server ]) 25 await setAccessTokensToServers([ server ])
27 26
28 const user = { username: 'user1', password: 'password' } 27 const user = { username: 'user1', password: 'password' }
29 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 28 await server.usersCommand.create({ username: user.username, password: user.password })
30 29
31 userAccessToken = await server.loginCommand.getAccessToken(user) 30 userAccessToken = await server.loginCommand.getAccessToken(user)
32 }) 31 })
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index dc033a441..2a7485cf3 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 ServerInfo, 8 ServerInfo,
10 setAccessTokensToServers 9 setAccessTokensToServers
@@ -30,7 +29,7 @@ describe('Test debug API validators', function () {
30 username: 'user1', 29 username: 'user1',
31 password: 'my super password' 30 password: 'my super password'
32 } 31 }
33 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 32 await server.usersCommand.create({ username: user.username, password: user.password })
34 userAccessToken = await server.loginCommand.getAccessToken(user) 33 userAccessToken = await server.loginCommand.getAccessToken(user)
35 }) 34 })
36 35
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 8cf5b130e..24e483448 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 makeDeleteRequest, makeGetRequest, 8 makeDeleteRequest, makeGetRequest,
10 makePostBodyRequest, 9 makePostBodyRequest,
@@ -40,7 +39,7 @@ describe('Test server follows API validators', function () {
40 password: 'password' 39 password: 'password'
41 } 40 }
42 41
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 42 await server.usersCommand.create({ username: user.username, password: user.password })
44 userAccessToken = await server.loginCommand.getAccessToken(user) 43 userAccessToken = await server.loginCommand.getAccessToken(user)
45 }) 44 })
46 45
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index cbe6a28b8..29439bebf 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 ServerInfo, 8 ServerInfo,
10 setAccessTokensToServers 9 setAccessTokensToServers
@@ -35,7 +34,7 @@ describe('Test jobs API validators', function () {
35 username: 'user1', 34 username: 'user1',
36 password: 'my super password' 35 password: 'my super password'
37 } 36 }
38 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 37 await server.usersCommand.create({ username: user.username, password: user.password })
39 userAccessToken = await server.loginCommand.getAccessToken(user) 38 userAccessToken = await server.loginCommand.getAccessToken(user)
40 }) 39 })
41 40
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 045f3a1b1..78863fd50 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -2,14 +2,11 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { VideoCreateResult, VideoPrivacy } from '@shared/models' 5import { HttpStatusCode } from '@shared/core-utils'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
9 cleanupTests, 8 cleanupTests,
10 createUser,
11 flushAndRunServer, 9 flushAndRunServer,
12 getMyUserInformation,
13 LiveCommand, 10 LiveCommand,
14 makePostBodyRequest, 11 makePostBodyRequest,
15 makeUploadRequest, 12 makeUploadRequest,
@@ -18,7 +15,8 @@ import {
18 setAccessTokensToServers, 15 setAccessTokensToServers,
19 stopFfmpeg, 16 stopFfmpeg,
20 uploadVideoAndGetId 17 uploadVideoAndGetId
21} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
19import { VideoCreateResult, VideoPrivacy } from '@shared/models'
22 20
23describe('Test video lives API validator', function () { 21describe('Test video lives API validator', function () {
24 const path = '/api/v1/videos/live' 22 const path = '/api/v1/videos/live'
@@ -51,12 +49,12 @@ describe('Test video lives API validator', function () {
51 49
52 const username = 'user1' 50 const username = 'user1'
53 const password = 'my super password' 51 const password = 'my super password'
54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 52 await server.usersCommand.create({ username: username, password: password })
55 userAccessToken = await server.loginCommand.getAccessToken({ username, password }) 53 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
56 54
57 { 55 {
58 const res = await getMyUserInformation(server.url, server.accessToken) 56 const { videoChannels } = await server.usersCommand.getMyInfo()
59 channelId = res.body.videoChannels[0].id 57 channelId = videoChannels[0].id
60 } 58 }
61 59
62 { 60 {
@@ -147,11 +145,11 @@ describe('Test video lives API validator', function () {
147 username: 'fake', 145 username: 'fake',
148 password: 'fake_password' 146 password: 'fake_password'
149 } 147 }
150 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 148 await server.usersCommand.create({ username: user.username, password: user.password })
151 149
152 const accessTokenUser = await server.loginCommand.getAccessToken(user) 150 const accessTokenUser = await server.loginCommand.getAccessToken(user)
153 const res = await getMyUserInformation(server.url, accessTokenUser) 151 const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
154 const customChannelId = res.body.videoChannels[0].id 152 const customChannelId = videoChannels[0].id
155 153
156 const fields = { ...baseCorrectParams, channelId: customChannelId } 154 const fields = { ...baseCorrectParams, channelId: customChannelId }
157 155
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 83ecfec93..69eaad69f 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 ServerInfo, 8 ServerInfo,
10 setAccessTokensToServers 9 setAccessTokensToServers
@@ -30,7 +29,7 @@ describe('Test logs API validators', function () {
30 username: 'user1', 29 username: 'user1',
31 password: 'my super password' 30 password: 'my super password'
32 } 31 }
33 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 32 await server.usersCommand.create({ username: user.username, password: user.password })
34 userAccessToken = await server.loginCommand.getAccessToken(user) 33 userAccessToken = await server.loginCommand.getAccessToken(user)
35 }) 34 })
36 35
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 130cf6869..08fb2397f 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -7,7 +7,6 @@ import {
7 checkBadSortPagination, 7 checkBadSortPagination,
8 checkBadStartPagination, 8 checkBadStartPagination,
9 cleanupTests, 9 cleanupTests,
10 createUser,
11 flushAndRunServer, 10 flushAndRunServer,
12 makeGetRequest, 11 makeGetRequest,
13 makePostBodyRequest, 12 makePostBodyRequest,
@@ -43,7 +42,7 @@ describe('Test server plugins API validators', function () {
43 password: 'password' 42 password: 'password'
44 } 43 }
45 44
46 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 45 await server.usersCommand.create({ username: user.username, password: user.password })
47 userAccessToken = await server.loginCommand.getAccessToken(user) 46 userAccessToken = await server.loginCommand.getAccessToken(user)
48 47
49 { 48 {
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index 2e10e378a..d93022c32 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -8,7 +8,6 @@ import {
8 checkBadSortPagination, 8 checkBadSortPagination,
9 checkBadStartPagination, 9 checkBadStartPagination,
10 cleanupTests, 10 cleanupTests,
11 createUser,
12 doubleFollow, 11 doubleFollow,
13 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
14 getVideo, 13 getVideo,
@@ -43,7 +42,7 @@ describe('Test server redundancy API validators', function () {
43 password: 'password' 42 password: 'password'
44 } 43 }
45 44
46 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 45 await servers[0].usersCommand.create({ username: user.username, password: user.password })
47 userAccessToken = await servers[0].loginCommand.getAccessToken(user) 46 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
48 47
49 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id 48 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index 3dc6cf2b4..d94dec624 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -3,17 +3,14 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { HttpStatusCode, randomInt } from '@shared/core-utils'
6import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' 6import { VideoImportState, VideoPrivacy } from '@shared/models'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 flushAndRunServer, 9 flushAndRunServer,
10 getMyUserInformation,
11 ImportsCommand, 10 ImportsCommand,
12 registerUser,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 setDefaultVideoChannel, 13 setDefaultVideoChannel,
16 updateUser,
17 uploadVideo, 14 uploadVideo,
18 waitJobs 15 waitJobs
19} from '../../../../shared/extra-utils' 16} from '../../../../shared/extra-utils'
@@ -31,15 +28,10 @@ describe('Test upload quota', function () {
31 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
32 await setDefaultVideoChannel([ server ]) 29 await setDefaultVideoChannel([ server ])
33 30
34 const res = await getMyUserInformation(server.url, server.accessToken) 31 const user = await server.usersCommand.getMyInfo()
35 rootId = (res.body as MyUser).id 32 rootId = user.id
36 33
37 await updateUser({ 34 await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
38 url: server.url,
39 userId: rootId,
40 accessToken: server.accessToken,
41 videoQuota: 42
42 })
43 }) 35 })
44 36
45 describe('When having a video quota', function () { 37 describe('When having a video quota', function () {
@@ -48,7 +40,7 @@ describe('Test upload quota', function () {
48 this.timeout(30000) 40 this.timeout(30000)
49 41
50 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 42 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
51 await registerUser(server.url, user.username, user.password) 43 await server.usersCommand.register(user)
52 const userAccessToken = await server.loginCommand.getAccessToken(user) 44 const userAccessToken = await server.loginCommand.getAccessToken(user)
53 45
54 const videoAttributes = { fixture: 'video_short2.webm' } 46 const videoAttributes = { fixture: 'video_short2.webm' }
@@ -63,7 +55,7 @@ describe('Test upload quota', function () {
63 this.timeout(30000) 55 this.timeout(30000)
64 56
65 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 57 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
66 await registerUser(server.url, user.username, user.password) 58 await server.usersCommand.register(user)
67 const userAccessToken = await server.loginCommand.getAccessToken(user) 59 const userAccessToken = await server.loginCommand.getAccessToken(user)
68 60
69 const videoAttributes = { fixture: 'video_short2.webm' } 61 const videoAttributes = { fixture: 'video_short2.webm' }
@@ -103,12 +95,7 @@ describe('Test upload quota', function () {
103 describe('When having a daily video quota', function () { 95 describe('When having a daily video quota', function () {
104 96
105 it('Should fail with a user having too many videos daily', async function () { 97 it('Should fail with a user having too many videos daily', async function () {
106 await updateUser({ 98 await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
107 url: server.url,
108 userId: rootId,
109 accessToken: server.accessToken,
110 videoQuotaDaily: 42
111 })
112 99
113 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 100 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
114 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 101 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
@@ -117,10 +104,8 @@ describe('Test upload quota', function () {
117 104
118 describe('When having an absolute and daily video quota', function () { 105 describe('When having an absolute and daily video quota', function () {
119 it('Should fail if exceeding total quota', async function () { 106 it('Should fail if exceeding total quota', async function () {
120 await updateUser({ 107 await server.usersCommand.update({
121 url: server.url,
122 userId: rootId, 108 userId: rootId,
123 accessToken: server.accessToken,
124 videoQuota: 42, 109 videoQuota: 42,
125 videoQuotaDaily: 1024 * 1024 * 1024 110 videoQuotaDaily: 1024 * 1024 * 1024
126 }) 111 })
@@ -130,10 +115,8 @@ describe('Test upload quota', function () {
130 }) 115 })
131 116
132 it('Should fail if exceeding daily quota', async function () { 117 it('Should fail if exceeding daily quota', async function () {
133 await updateUser({ 118 await server.usersCommand.update({
134 url: server.url,
135 userId: rootId, 119 userId: rootId,
136 accessToken: server.accessToken,
137 videoQuota: 1024 * 1024 * 1024, 120 videoQuota: 1024 * 1024 * 1024,
138 videoQuotaDaily: 42 121 videoQuotaDaily: 42
139 }) 122 })
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 64e2703b9..8ce201d61 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -4,7 +4,6 @@ import 'mocha'
4 4
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 makeDeleteRequest, 8 makeDeleteRequest,
10 makeGetRequest, 9 makeGetRequest,
@@ -39,7 +38,7 @@ describe('Test user subscriptions API validators', function () {
39 username: 'user1', 38 username: 'user1',
40 password: 'my super password' 39 password: 'my super password'
41 } 40 }
42 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 41 await server.usersCommand.create({ username: user.username, password: user.password })
43 userAccessToken = await server.loginCommand.getAccessToken(user) 42 userAccessToken = await server.loginCommand.getAccessToken(user)
44 }) 43 })
45 44
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 54baeebe1..801131918 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,32 +2,22 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { User, UserRole, VideoCreateResult } from '../../../../shared' 5import { UserRole, VideoCreateResult } from '../../../../shared'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 7import {
8 blockUser,
9 buildAbsoluteFixturePath, 8 buildAbsoluteFixturePath,
10 cleanupTests, 9 cleanupTests,
11 createUser,
12 deleteMe,
13 flushAndRunServer, 10 flushAndRunServer,
14 getMyUserInformation,
15 getMyUserVideoRating,
16 getUserScopedTokens,
17 getUsersList,
18 killallServers, 11 killallServers,
19 makeGetRequest, 12 makeGetRequest,
20 makePostBodyRequest, 13 makePostBodyRequest,
21 makePutBodyRequest, 14 makePutBodyRequest,
22 makeUploadRequest, 15 makeUploadRequest,
23 registerUser,
24 removeUser,
25 renewUserScopedTokens,
26 reRunServer, 16 reRunServer,
27 ServerInfo, 17 ServerInfo,
28 setAccessTokensToServers, 18 setAccessTokensToServers,
29 unblockUser, 19 uploadVideo,
30 uploadVideo 20 UsersCommand
31} from '../../../../shared/extra-utils' 21} from '../../../../shared/extra-utils'
32import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' 22import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
33import { 23import {
@@ -45,8 +35,8 @@ describe('Test users API validators', function () {
45 let video: VideoCreateResult 35 let video: VideoCreateResult
46 let server: ServerInfo 36 let server: ServerInfo
47 let serverWithRegistrationDisabled: ServerInfo 37 let serverWithRegistrationDisabled: ServerInfo
48 let userAccessToken = '' 38 let userToken = ''
49 let moderatorAccessToken = '' 39 let moderatorToken = ''
50 let emailPort: number 40 let emailPort: number
51 let overrideConfig: Object 41 let overrideConfig: Object
52 42
@@ -73,52 +63,20 @@ describe('Test users API validators', function () {
73 } 63 }
74 64
75 { 65 {
76 const user = { 66 const user = { username: 'user1' }
77 username: 'user1', 67 await server.usersCommand.create({ ...user })
78 password: 'my super password' 68 userToken = await server.loginCommand.getAccessToken(user)
79 }
80
81 const videoQuota = 42000000
82 await createUser({
83 url: server.url,
84 accessToken: server.accessToken,
85 username: user.username,
86 password: user.password,
87 videoQuota: videoQuota
88 })
89 userAccessToken = await server.loginCommand.getAccessToken(user)
90 } 69 }
91 70
92 { 71 {
93 const moderator = { 72 const moderator = { username: 'moderator1' }
94 username: 'moderator1', 73 await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
95 password: 'super password' 74 moderatorToken = await server.loginCommand.getAccessToken(moderator)
96 }
97
98 await createUser({
99 url: server.url,
100 accessToken: server.accessToken,
101 username: moderator.username,
102 password: moderator.password,
103 role: UserRole.MODERATOR
104 })
105
106 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
107 } 75 }
108 76
109 { 77 {
110 const moderator = { 78 const moderator = { username: 'moderator2' }
111 username: 'moderator2', 79 await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
112 password: 'super password'
113 }
114
115 await createUser({
116 url: server.url,
117 accessToken: server.accessToken,
118 username: moderator.username,
119 password: moderator.password,
120 role: UserRole.MODERATOR
121 })
122 } 80 }
123 81
124 { 82 {
@@ -127,12 +85,10 @@ describe('Test users API validators', function () {
127 } 85 }
128 86
129 { 87 {
130 const res = await getUsersList(server.url, server.accessToken) 88 const { data } = await server.usersCommand.list()
131 const users: User[] = res.body.data 89 userId = data.find(u => u.username === 'user1').id
132 90 rootId = data.find(u => u.username === 'root').id
133 userId = users.find(u => u.username === 'user1').id 91 moderatorId = data.find(u => u.username === 'moderator2').id
134 rootId = users.find(u => u.username === 'root').id
135 moderatorId = users.find(u => u.username === 'moderator2').id
136 } 92 }
137 }) 93 })
138 94
@@ -161,7 +117,7 @@ describe('Test users API validators', function () {
161 await makeGetRequest({ 117 await makeGetRequest({
162 url: server.url, 118 url: server.url,
163 path, 119 path,
164 token: userAccessToken, 120 token: userToken,
165 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 121 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
166 }) 122 })
167 }) 123 })
@@ -359,7 +315,7 @@ describe('Test users API validators', function () {
359 await makePostBodyRequest({ 315 await makePostBodyRequest({
360 url: server.url, 316 url: server.url,
361 path, 317 path,
362 token: moderatorAccessToken, 318 token: moderatorToken,
363 fields, 319 fields,
364 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 320 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
365 }) 321 })
@@ -372,7 +328,7 @@ describe('Test users API validators', function () {
372 await makePostBodyRequest({ 328 await makePostBodyRequest({
373 url: server.url, 329 url: server.url,
374 path, 330 path,
375 token: moderatorAccessToken, 331 token: moderatorToken,
376 fields, 332 fields,
377 statusCodeExpected: HttpStatusCode.OK_200 333 statusCodeExpected: HttpStatusCode.OK_200
378 }) 334 })
@@ -389,11 +345,8 @@ describe('Test users API validators', function () {
389 }) 345 })
390 346
391 it('Should fail with a non admin user', async function () { 347 it('Should fail with a non admin user', async function () {
392 const user = { 348 const user = { username: 'user1' }
393 username: 'user1', 349 userToken = await server.loginCommand.getAccessToken(user)
394 password: 'my super password'
395 }
396 userAccessToken = await server.loginCommand.getAccessToken(user)
397 350
398 const fields = { 351 const fields = {
399 username: 'user3', 352 username: 'user3',
@@ -401,11 +354,12 @@ describe('Test users API validators', function () {
401 password: 'my super password', 354 password: 'my super password',
402 videoQuota: 42000000 355 videoQuota: 42000000
403 } 356 }
404 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 357 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
405 }) 358 })
406 }) 359 })
407 360
408 describe('When updating my account', function () { 361 describe('When updating my account', function () {
362
409 it('Should fail with an invalid email attribute', async function () { 363 it('Should fail with an invalid email attribute', async function () {
410 const fields = { 364 const fields = {
411 email: 'blabla' 365 email: 'blabla'
@@ -416,29 +370,29 @@ describe('Test users API validators', function () {
416 370
417 it('Should fail with a too small password', async function () { 371 it('Should fail with a too small password', async function () {
418 const fields = { 372 const fields = {
419 currentPassword: 'my super password', 373 currentPassword: 'password',
420 password: 'bla' 374 password: 'bla'
421 } 375 }
422 376
423 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 377 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
424 }) 378 })
425 379
426 it('Should fail with a too long password', async function () { 380 it('Should fail with a too long password', async function () {
427 const fields = { 381 const fields = {
428 currentPassword: 'my super password', 382 currentPassword: 'password',
429 password: 'super'.repeat(61) 383 password: 'super'.repeat(61)
430 } 384 }
431 385
432 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 386 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
433 }) 387 })
434 388
435 it('Should fail without the current password', async function () { 389 it('Should fail without the current password', async function () {
436 const fields = { 390 const fields = {
437 currentPassword: 'my super password', 391 currentPassword: 'password',
438 password: 'super'.repeat(61) 392 password: 'super'.repeat(61)
439 } 393 }
440 394
441 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 395 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
442 }) 396 })
443 397
444 it('Should fail with an invalid current password', async function () { 398 it('Should fail with an invalid current password', async function () {
@@ -450,7 +404,7 @@ describe('Test users API validators', function () {
450 await makePutBodyRequest({ 404 await makePutBodyRequest({
451 url: server.url, 405 url: server.url,
452 path: path + 'me', 406 path: path + 'me',
453 token: userAccessToken, 407 token: userToken,
454 fields, 408 fields,
455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 409 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
456 }) 410 })
@@ -461,7 +415,7 @@ describe('Test users API validators', function () {
461 nsfwPolicy: 'hello' 415 nsfwPolicy: 'hello'
462 } 416 }
463 417
464 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 418 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
465 }) 419 })
466 420
467 it('Should fail with an invalid autoPlayVideo attribute', async function () { 421 it('Should fail with an invalid autoPlayVideo attribute', async function () {
@@ -469,7 +423,7 @@ describe('Test users API validators', function () {
469 autoPlayVideo: -1 423 autoPlayVideo: -1
470 } 424 }
471 425
472 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 426 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
473 }) 427 })
474 428
475 it('Should fail with an invalid autoPlayNextVideo attribute', async function () { 429 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
@@ -477,7 +431,7 @@ describe('Test users API validators', function () {
477 autoPlayNextVideo: -1 431 autoPlayNextVideo: -1
478 } 432 }
479 433
480 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 434 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
481 }) 435 })
482 436
483 it('Should fail with an invalid videosHistoryEnabled attribute', async function () { 437 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
@@ -485,12 +439,12 @@ describe('Test users API validators', function () {
485 videosHistoryEnabled: -1 439 videosHistoryEnabled: -1
486 } 440 }
487 441
488 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 442 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
489 }) 443 })
490 444
491 it('Should fail with an non authenticated user', async function () { 445 it('Should fail with an non authenticated user', async function () {
492 const fields = { 446 const fields = {
493 currentPassword: 'my super password', 447 currentPassword: 'password',
494 password: 'my super password' 448 password: 'my super password'
495 } 449 }
496 450
@@ -508,7 +462,7 @@ describe('Test users API validators', function () {
508 description: 'super'.repeat(201) 462 description: 'super'.repeat(201)
509 } 463 }
510 464
511 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 465 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
512 }) 466 })
513 467
514 it('Should fail with an invalid videoLanguages attribute', async function () { 468 it('Should fail with an invalid videoLanguages attribute', async function () {
@@ -517,7 +471,7 @@ describe('Test users API validators', function () {
517 videoLanguages: 'toto' 471 videoLanguages: 'toto'
518 } 472 }
519 473
520 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 474 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
521 } 475 }
522 476
523 { 477 {
@@ -530,18 +484,18 @@ describe('Test users API validators', function () {
530 videoLanguages: languages 484 videoLanguages: languages
531 } 485 }
532 486
533 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 487 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
534 } 488 }
535 }) 489 })
536 490
537 it('Should fail with an invalid theme', async function () { 491 it('Should fail with an invalid theme', async function () {
538 const fields = { theme: 'invalid' } 492 const fields = { theme: 'invalid' }
539 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 493 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
540 }) 494 })
541 495
542 it('Should fail with an unknown theme', async function () { 496 it('Should fail with an unknown theme', async function () {
543 const fields = { theme: 'peertube-theme-unknown' } 497 const fields = { theme: 'peertube-theme-unknown' }
544 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 498 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
545 }) 499 })
546 500
547 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { 501 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
@@ -549,7 +503,7 @@ describe('Test users API validators', function () {
549 noInstanceConfigWarningModal: -1 503 noInstanceConfigWarningModal: -1
550 } 504 }
551 505
552 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 506 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
553 }) 507 })
554 508
555 it('Should fail with an invalid noWelcomeModal attribute', async function () { 509 it('Should fail with an invalid noWelcomeModal attribute', async function () {
@@ -557,12 +511,12 @@ describe('Test users API validators', function () {
557 noWelcomeModal: -1 511 noWelcomeModal: -1
558 } 512 }
559 513
560 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 514 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
561 }) 515 })
562 516
563 it('Should succeed to change password with the correct params', async function () { 517 it('Should succeed to change password with the correct params', async function () {
564 const fields = { 518 const fields = {
565 currentPassword: 'my super password', 519 currentPassword: 'password',
566 password: 'my super password', 520 password: 'my super password',
567 nsfwPolicy: 'blur', 521 nsfwPolicy: 'blur',
568 autoPlayVideo: false, 522 autoPlayVideo: false,
@@ -575,7 +529,7 @@ describe('Test users API validators', function () {
575 await makePutBodyRequest({ 529 await makePutBodyRequest({
576 url: server.url, 530 url: server.url,
577 path: path + 'me', 531 path: path + 'me',
578 token: userAccessToken, 532 token: userToken,
579 fields, 533 fields,
580 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 534 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
581 }) 535 })
@@ -590,7 +544,7 @@ describe('Test users API validators', function () {
590 await makePutBodyRequest({ 544 await makePutBodyRequest({
591 url: server.url, 545 url: server.url,
592 path: path + 'me', 546 path: path + 'me',
593 token: userAccessToken, 547 token: userToken,
594 fields, 548 fields,
595 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 549 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
596 }) 550 })
@@ -647,28 +601,28 @@ describe('Test users API validators', function () {
647 describe('When managing my scoped tokens', function () { 601 describe('When managing my scoped tokens', function () {
648 602
649 it('Should fail to get my scoped tokens with an non authenticated user', async function () { 603 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
650 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 604 await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
651 }) 605 })
652 606
653 it('Should fail to get my scoped tokens with a bad token', async function () { 607 it('Should fail to get my scoped tokens with a bad token', async function () {
654 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 608 await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
655 609
656 }) 610 })
657 611
658 it('Should succeed to get my scoped tokens', async function () { 612 it('Should succeed to get my scoped tokens', async function () {
659 await getUserScopedTokens(server.url, server.accessToken) 613 await server.usersCommand.getMyScopedTokens()
660 }) 614 })
661 615
662 it('Should fail to renew my scoped tokens with an non authenticated user', async function () { 616 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
663 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 617 await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
664 }) 618 })
665 619
666 it('Should fail to renew my scoped tokens with a bad token', async function () { 620 it('Should fail to renew my scoped tokens with a bad token', async function () {
667 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 621 await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
668 }) 622 })
669 623
670 it('Should succeed to renew my scoped tokens', async function () { 624 it('Should succeed to renew my scoped tokens', async function () {
671 await renewUserScopedTokens(server.url, server.accessToken) 625 await server.usersCommand.renewMyScopedTokens()
672 }) 626 })
673 }) 627 })
674 628
@@ -684,7 +638,7 @@ describe('Test users API validators', function () {
684 }) 638 })
685 639
686 it('Should fail with a non admin user', async function () { 640 it('Should fail with a non admin user', async function () {
687 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 641 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
688 }) 642 })
689 643
690 it('Should succeed with the correct params', async function () { 644 it('Should succeed with the correct params', async function () {
@@ -728,7 +682,7 @@ describe('Test users API validators', function () {
728 682
729 it('Should fail with a too small password', async function () { 683 it('Should fail with a too small password', async function () {
730 const fields = { 684 const fields = {
731 currentPassword: 'my super password', 685 currentPassword: 'password',
732 password: 'bla' 686 password: 'bla'
733 } 687 }
734 688
@@ -737,7 +691,7 @@ describe('Test users API validators', function () {
737 691
738 it('Should fail with a too long password', async function () { 692 it('Should fail with a too long password', async function () {
739 const fields = { 693 const fields = {
740 currentPassword: 'my super password', 694 currentPassword: 'password',
741 password: 'super'.repeat(61) 695 password: 'super'.repeat(61)
742 } 696 }
743 697
@@ -780,7 +734,7 @@ describe('Test users API validators', function () {
780 await makePutBodyRequest({ 734 await makePutBodyRequest({
781 url: server.url, 735 url: server.url,
782 path: path + moderatorId, 736 path: path + moderatorId,
783 token: moderatorAccessToken, 737 token: moderatorToken,
784 fields, 738 fields,
785 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 739 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
786 }) 740 })
@@ -794,7 +748,7 @@ describe('Test users API validators', function () {
794 await makePutBodyRequest({ 748 await makePutBodyRequest({
795 url: server.url, 749 url: server.url,
796 path: path + userId, 750 path: path + userId,
797 token: moderatorAccessToken, 751 token: moderatorToken,
798 fields, 752 fields,
799 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 753 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
800 }) 754 })
@@ -820,31 +774,37 @@ describe('Test users API validators', function () {
820 774
821 describe('When getting my information', function () { 775 describe('When getting my information', function () {
822 it('Should fail with a non authenticated user', async function () { 776 it('Should fail with a non authenticated user', async function () {
823 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) 777 await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
824 }) 778 })
825 779
826 it('Should success with the correct parameters', async function () { 780 it('Should success with the correct parameters', async function () {
827 await getMyUserInformation(server.url, userAccessToken) 781 await server.usersCommand.getMyInfo({ token: userToken })
828 }) 782 })
829 }) 783 })
830 784
831 describe('When getting my video rating', function () { 785 describe('When getting my video rating', function () {
786 let command: UsersCommand
787
788 before(function () {
789 command = server.usersCommand
790 })
791
832 it('Should fail with a non authenticated user', async function () { 792 it('Should fail with a non authenticated user', async function () {
833 await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) 793 await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
834 }) 794 })
835 795
836 it('Should fail with an incorrect video uuid', async function () { 796 it('Should fail with an incorrect video uuid', async function () {
837 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) 797 await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
838 }) 798 })
839 799
840 it('Should fail with an unknown video', async function () { 800 it('Should fail with an unknown video', async function () {
841 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 801 await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
842 }) 802 })
843 803
844 it('Should succeed with the correct parameters', async function () { 804 it('Should succeed with the correct parameters', async function () {
845 await getMyUserVideoRating(server.url, server.accessToken, video.id) 805 await command.getMyRating({ videoId: video.id })
846 await getMyUserVideoRating(server.url, server.accessToken, video.uuid) 806 await command.getMyRating({ videoId: video.uuid })
847 await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) 807 await command.getMyRating({ videoId: video.shortUUID })
848 }) 808 })
849 }) 809 })
850 810
@@ -852,15 +812,15 @@ describe('Test users API validators', function () {
852 const path = '/api/v1/accounts/user1/ratings' 812 const path = '/api/v1/accounts/user1/ratings'
853 813
854 it('Should fail with a bad start pagination', async function () { 814 it('Should fail with a bad start pagination', async function () {
855 await checkBadStartPagination(server.url, path, userAccessToken) 815 await checkBadStartPagination(server.url, path, userToken)
856 }) 816 })
857 817
858 it('Should fail with a bad count pagination', async function () { 818 it('Should fail with a bad count pagination', async function () {
859 await checkBadCountPagination(server.url, path, userAccessToken) 819 await checkBadCountPagination(server.url, path, userToken)
860 }) 820 })
861 821
862 it('Should fail with an incorrect sort', async function () { 822 it('Should fail with an incorrect sort', async function () {
863 await checkBadSortPagination(server.url, path, userAccessToken) 823 await checkBadSortPagination(server.url, path, userToken)
864 }) 824 })
865 825
866 it('Should fail with a unauthenticated user', async function () { 826 it('Should fail with a unauthenticated user', async function () {
@@ -875,57 +835,70 @@ describe('Test users API validators', function () {
875 await makeGetRequest({ 835 await makeGetRequest({
876 url: server.url, 836 url: server.url,
877 path, 837 path,
878 token: userAccessToken, 838 token: userToken,
879 query: { rating: 'toto ' }, 839 query: { rating: 'toto ' },
880 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 840 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
881 }) 841 })
882 }) 842 })
883 843
884 it('Should succeed with the correct params', async function () { 844 it('Should succeed with the correct params', async function () {
885 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) 845 await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 })
886 }) 846 })
887 }) 847 })
888 848
889 describe('When blocking/unblocking/removing user', function () { 849 describe('When blocking/unblocking/removing user', function () {
850
890 it('Should fail with an incorrect id', async function () { 851 it('Should fail with an incorrect id', async function () {
891 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 852 const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
892 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 853
893 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 854 await server.usersCommand.remove(options)
855 await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
856 await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
894 }) 857 })
895 858
896 it('Should fail with the root user', async function () { 859 it('Should fail with the root user', async function () {
897 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 860 const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
898 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 861
899 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 862 await server.usersCommand.remove(options)
863 await server.usersCommand.banUser(options)
864 await server.usersCommand.unbanUser(options)
900 }) 865 })
901 866
902 it('Should return 404 with a non existing id', async function () { 867 it('Should return 404 with a non existing id', async function () {
903 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 868 const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
904 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 869
905 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 870 await server.usersCommand.remove(options)
871 await server.usersCommand.banUser(options)
872 await server.usersCommand.unbanUser(options)
906 }) 873 })
907 874
908 it('Should fail with a non admin user', async function () { 875 it('Should fail with a non admin user', async function () {
909 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 876 const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
910 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 877
911 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 878 await server.usersCommand.remove(options)
879 await server.usersCommand.banUser(options)
880 await server.usersCommand.unbanUser(options)
912 }) 881 })
913 882
914 it('Should fail on a moderator with a moderator', async function () { 883 it('Should fail on a moderator with a moderator', async function () {
915 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 884 const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
916 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 885
917 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 886 await server.usersCommand.remove(options)
887 await server.usersCommand.banUser(options)
888 await server.usersCommand.unbanUser(options)
918 }) 889 })
919 890
920 it('Should succeed on a user with a moderator', async function () { 891 it('Should succeed on a user with a moderator', async function () {
921 await blockUser(server.url, userId, moderatorAccessToken) 892 const options = { userId, token: moderatorToken }
922 await unblockUser(server.url, userId, moderatorAccessToken) 893
894 await server.usersCommand.banUser(options)
895 await server.usersCommand.unbanUser(options)
923 }) 896 })
924 }) 897 })
925 898
926 describe('When deleting our account', function () { 899 describe('When deleting our account', function () {
927 it('Should fail with with the root account', async function () { 900 it('Should fail with with the root account', async function () {
928 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 901 await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
929 }) 902 })
930 }) 903 })
931 904
@@ -1087,7 +1060,7 @@ describe('Test users API validators', function () {
1087 1060
1088 describe('When registering multiple users on a server with users limit', function () { 1061 describe('When registering multiple users on a server with users limit', function () {
1089 it('Should fail when after 3 registrations', async function () { 1062 it('Should fail when after 3 registrations', async function () {
1090 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) 1063 await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
1091 }) 1064 })
1092 }) 1065 })
1093 1066
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index c33bc196d..5097f8069 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -9,7 +9,6 @@ import {
9 checkBadSortPagination, 9 checkBadSortPagination,
10 checkBadStartPagination, 10 checkBadStartPagination,
11 cleanupTests, 11 cleanupTests,
12 createUser,
13 doubleFollow, 12 doubleFollow,
14 flushAndRunMultipleServers, 13 flushAndRunMultipleServers,
15 getVideo, 14 getVideo,
@@ -44,14 +43,14 @@ describe('Test video blacklist API validators', function () {
44 { 43 {
45 const username = 'user1' 44 const username = 'user1'
46 const password = 'my super password' 45 const password = 'my super password'
47 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 46 await servers[0].usersCommand.create({ username: username, password: password })
48 userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password }) 47 userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password })
49 } 48 }
50 49
51 { 50 {
52 const username = 'user2' 51 const username = 'user2'
53 const password = 'my super password' 52 const password = 'my super password'
54 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 53 await servers[0].usersCommand.create({ username: username, password: password })
55 userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password }) 54 userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password })
56 } 55 }
57 56
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index f2fd61b91..631ef4dac 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -5,7 +5,6 @@ import { HttpStatusCode } from '@shared/core-utils'
5import { 5import {
6 buildAbsoluteFixturePath, 6 buildAbsoluteFixturePath,
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 flushAndRunServer, 8 flushAndRunServer,
10 makeDeleteRequest, 9 makeDeleteRequest,
11 makeGetRequest, 10 makeGetRequest,
@@ -42,7 +41,7 @@ describe('Test video captions API validator', function () {
42 username: 'user1', 41 username: 'user1',
43 password: 'my super password' 42 password: 'my super password'
44 } 43 }
45 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 44 await server.usersCommand.create({ username: user.username, password: user.password })
46 userAccessToken = await server.loginCommand.getAccessToken(user) 45 userAccessToken = await server.loginCommand.getAccessToken(user)
47 } 46 }
48 }) 47 })
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 5361f6917..2b4c17ea1 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -11,7 +11,6 @@ import {
11 checkBadSortPagination, 11 checkBadSortPagination,
12 checkBadStartPagination, 12 checkBadStartPagination,
13 cleanupTests, 13 cleanupTests,
14 createUser,
15 flushAndRunServer, 14 flushAndRunServer,
16 makeGetRequest, 15 makeGetRequest,
17 makePostBodyRequest, 16 makePostBodyRequest,
@@ -45,7 +44,7 @@ describe('Test video channels API validator', function () {
45 } 44 }
46 45
47 { 46 {
48 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 47 await server.usersCommand.create({ username: user.username, password: user.password })
49 accessTokenUser = await server.loginCommand.getAccessToken(user) 48 accessTokenUser = await server.loginCommand.getAccessToken(user)
50 } 49 }
51 50
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index c21aebaae..b7656a176 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -8,7 +8,6 @@ import {
8 checkBadSortPagination, 8 checkBadSortPagination,
9 checkBadStartPagination, 9 checkBadStartPagination,
10 cleanupTests, 10 cleanupTests,
11 createUser,
12 flushAndRunServer, 11 flushAndRunServer,
13 makeDeleteRequest, 12 makeDeleteRequest,
14 makeGetRequest, 13 makeGetRequest,
@@ -53,13 +52,13 @@ describe('Test video comments API validator', function () {
53 52
54 { 53 {
55 const user = { username: 'user1', password: 'my super password' } 54 const user = { username: 'user1', password: 'my super password' }
56 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 55 await server.usersCommand.create({ username: user.username, password: user.password })
57 userAccessToken = await server.loginCommand.getAccessToken(user) 56 userAccessToken = await server.loginCommand.getAccessToken(user)
58 } 57 }
59 58
60 { 59 {
61 const user = { username: 'user2', password: 'my super password' } 60 const user = { username: 'user2', password: 'my super password' }
62 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 61 await server.usersCommand.create({ username: user.username, password: user.password })
63 userAccessToken2 = await server.loginCommand.getAccessToken(user) 62 userAccessToken2 = await server.loginCommand.getAccessToken(user)
64 } 63 }
65 }) 64 })
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 51260affa..d09e473de 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -9,9 +9,7 @@ import {
9 checkBadSortPagination, 9 checkBadSortPagination,
10 checkBadStartPagination, 10 checkBadStartPagination,
11 cleanupTests, 11 cleanupTests,
12 createUser,
13 flushAndRunServer, 12 flushAndRunServer,
14 getMyUserInformation,
15 ImportsCommand, 13 ImportsCommand,
16 makeGetRequest, 14 makeGetRequest,
17 makePostBodyRequest, 15 makePostBodyRequest,
@@ -38,12 +36,12 @@ describe('Test video imports API validator', function () {
38 36
39 const username = 'user1' 37 const username = 'user1'
40 const password = 'my super password' 38 const password = 'my super password'
41 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 39 await server.usersCommand.create({ username: username, password: password })
42 userAccessToken = await server.loginCommand.getAccessToken({ username, password }) 40 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
43 41
44 { 42 {
45 const res = await getMyUserInformation(server.url, server.accessToken) 43 const { videoChannels } = await server.usersCommand.getMyInfo()
46 channelId = res.body.videoChannels[0].id 44 channelId = videoChannels[0].id
47 } 45 }
48 }) 46 })
49 47
@@ -164,11 +162,11 @@ describe('Test video imports API validator', function () {
164 username: 'fake', 162 username: 'fake',
165 password: 'fake_password' 163 password: 'fake_password'
166 } 164 }
167 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 165 await server.usersCommand.create({ username: user.username, password: user.password })
168 166
169 const accessTokenUser = await server.loginCommand.getAccessToken(user) 167 const accessTokenUser = await server.loginCommand.getAccessToken(user)
170 const res = await getMyUserInformation(server.url, accessTokenUser) 168 const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
171 const customChannelId = res.body.videoChannels[0].id 169 const customChannelId = videoChannels[0].id
172 170
173 const fields = { ...baseCorrectParams, channelId: customChannelId } 171 const fields = { ...baseCorrectParams, channelId: customChannelId }
174 172
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 3799e73b6..46c09bb11 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -17,7 +17,6 @@ import {
17 checkBadStartPagination, 17 checkBadStartPagination,
18 cleanupTests, 18 cleanupTests,
19 flushAndRunServer, 19 flushAndRunServer,
20 generateUserAccessToken,
21 makeGetRequest, 20 makeGetRequest,
22 PlaylistsCommand, 21 PlaylistsCommand,
23 ServerInfo, 22 ServerInfo,
@@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () {
49 await setAccessTokensToServers([ server ]) 48 await setAccessTokensToServers([ server ])
50 await setDefaultVideoChannel([ server ]) 49 await setDefaultVideoChannel([ server ])
51 50
52 userAccessToken = await generateUserAccessToken(server, 'user1') 51 userAccessToken = await server.usersCommand.generateUserAndToken('user1')
53 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id 52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
54 53
55 command = server.playlistsCommand 54 command = server.playlistsCommand
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index 095b94656..d7bf081d4 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -3,7 +3,6 @@
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests, 5 cleanupTests,
6 createUser,
7 flushAndRunServer, 6 flushAndRunServer,
8 makeGetRequest, 7 makeGetRequest,
9 ServerInfo, 8 ServerInfo,
@@ -50,21 +49,12 @@ describe('Test video filters validators', function () {
50 await setDefaultVideoChannel([ server ]) 49 await setDefaultVideoChannel([ server ])
51 50
52 const user = { username: 'user1', password: 'my super password' } 51 const user = { username: 'user1', password: 'my super password' }
53 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 52 await server.usersCommand.create({ username: user.username, password: user.password })
54 userAccessToken = await server.loginCommand.getAccessToken(user) 53 userAccessToken = await server.loginCommand.getAccessToken(user)
55 54
56 const moderator = { username: 'moderator', password: 'my super password' } 55 const moderator = { username: 'moderator', password: 'my super password' }
57 await createUser( 56 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
58 { 57
59 url: server.url,
60 accessToken: server.accessToken,
61 username: moderator.username,
62 password: moderator.password,
63 videoQuota: undefined,
64 videoQuotaDaily: undefined,
65 role: UserRole.MODERATOR
66 }
67 )
68 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator) 58 moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
69 }) 59 })
70 60
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 8e11232bd..855b09f39 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -10,9 +10,7 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
10import { 10import {
11 checkUploadVideoParam, 11 checkUploadVideoParam,
12 cleanupTests, 12 cleanupTests,
13 createUser,
14 flushAndRunServer, 13 flushAndRunServer,
15 getMyUserInformation,
16 getVideo, 14 getVideo,
17 getVideosList, 15 getVideosList,
18 makeDeleteRequest, 16 makeDeleteRequest,
@@ -53,14 +51,14 @@ describe('Test videos API validator', function () {
53 51
54 const username = 'user1' 52 const username = 'user1'
55 const password = 'my super password' 53 const password = 'my super password'
56 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 54 await server.usersCommand.create({ username: username, password: password })
57 userAccessToken = await server.loginCommand.getAccessToken({ username, password }) 55 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
58 56
59 { 57 {
60 const res = await getMyUserInformation(server.url, server.accessToken) 58 const body = await server.usersCommand.getMyInfo()
61 channelId = res.body.videoChannels[0].id 59 channelId = body.videoChannels[0].id
62 channelName = res.body.videoChannels[0].name 60 channelName = body.videoChannels[0].name
63 accountName = res.body.account.name + '@' + res.body.account.host 61 accountName = body.account.name + '@' + body.account.host
64 } 62 }
65 }) 63 })
66 64
@@ -283,11 +281,11 @@ describe('Test videos API validator', function () {
283 username: 'fake' + randomInt(0, 1500), 281 username: 'fake' + randomInt(0, 1500),
284 password: 'fake_password' 282 password: 'fake_password'
285 } 283 }
286 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 284 await server.usersCommand.create({ username: user.username, password: user.password })
287 285
288 const accessTokenUser = await server.loginCommand.getAccessToken(user) 286 const accessTokenUser = await server.loginCommand.getAccessToken(user)
289 const res = await getMyUserInformation(server.url, accessTokenUser) 287 const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
290 const customChannelId = res.body.videoChannels[0].id 288 const customChannelId = videoChannels[0].id
291 289
292 const fields = { ...baseCorrectParams, channelId: customChannelId } 290 const fields = { ...baseCorrectParams, channelId: customChannelId }
293 const attaches = baseCorrectAttaches 291 const attaches = baseCorrectAttaches
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index 46153f7b1..290d325d4 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -9,12 +9,10 @@ import {
9 ConfigCommand, 9 ConfigCommand,
10 doubleFollow, 10 doubleFollow,
11 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
12 generateUser,
13 getVideo, 12 getVideo,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
16 setDefaultVideoChannel, 15 setDefaultVideoChannel,
17 updateUser,
18 wait, 16 wait,
19 waitJobs 17 waitJobs
20} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
@@ -58,9 +56,7 @@ describe('Test live constraints', function () {
58 } 56 }
59 57
60 function updateQuota (options: { total: number, daily: number }) { 58 function updateQuota (options: { total: number, daily: number }) {
61 return updateUser({ 59 return servers[0].usersCommand.update({
62 url: servers[0].url,
63 accessToken: servers[0].accessToken,
64 userId, 60 userId,
65 videoQuota: options.total, 61 videoQuota: options.total,
66 videoQuotaDaily: options.daily 62 videoQuotaDaily: options.daily
@@ -89,7 +85,7 @@ describe('Test live constraints', function () {
89 }) 85 })
90 86
91 { 87 {
92 const res = await generateUser(servers[0], 'user1') 88 const res = await servers[0].usersCommand.generate('user1')
93 userId = res.userId 89 userId = res.userId
94 userChannelId = res.userChannelId 90 userChannelId = res.userChannelId
95 userAccessToken = res.token 91 userAccessToken = res.token
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index d7462f38f..a7119263c 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -5,13 +5,10 @@ import * as chai from 'chai'
5import { 5import {
6 AbusesCommand, 6 AbusesCommand,
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
11 generateUserAccessToken,
12 getVideoIdFromUUID, 10 getVideoIdFromUUID,
13 getVideosList, 11 getVideosList,
14 removeUser,
15 removeVideo, 12 removeVideo,
16 ServerInfo, 13 ServerInfo,
17 setAccessTokensToServers, 14 setAccessTokensToServers,
@@ -278,7 +275,7 @@ describe('Test abuses', function () {
278 275
279 // register a second user to have two reporters/reportees 276 // register a second user to have two reporters/reportees
280 const user = { username: 'user2', password: 'password' } 277 const user = { username: 'user2', password: 'password' }
281 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) 278 await servers[0].usersCommand.create({ ...user })
282 const userAccessToken = await servers[0].loginCommand.getAccessToken(user) 279 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
283 280
284 // upload a third video via this user 281 // upload a third video via this user
@@ -604,9 +601,9 @@ describe('Test abuses', function () {
604 before(async function () { 601 before(async function () {
605 this.timeout(50000) 602 this.timeout(50000)
606 603
607 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' }) 604 await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
608 605
609 const token = await generateUserAccessToken(servers[1], 'user_2') 606 const token = await servers[1].usersCommand.generateUserAndToken('user_2')
610 await uploadVideo(servers[1].url, token, { name: 'super video' }) 607 await uploadVideo(servers[1].url, token, { name: 'super video' })
611 608
612 await waitJobs(servers) 609 await waitJobs(servers)
@@ -708,7 +705,7 @@ describe('Test abuses', function () {
708 this.timeout(10000) 705 this.timeout(10000)
709 706
710 const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) 707 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
711 await removeUser(servers[1].url, account.userId, servers[1].accessToken) 708 await servers[1].usersCommand.remove({ userId: account.userId })
712 709
713 await waitJobs(servers) 710 await waitJobs(servers)
714 711
@@ -765,7 +762,7 @@ describe('Test abuses', function () {
765 let userAccessToken: string 762 let userAccessToken: string
766 763
767 before(async function () { 764 before(async function () {
768 userAccessToken = await generateUserAccessToken(servers[0], 'user_42') 765 userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42')
769 766
770 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' }) 767 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
771 768
@@ -836,7 +833,7 @@ describe('Test abuses', function () {
836 let abuseMessageModerationId: number 833 let abuseMessageModerationId: number
837 834
838 before(async function () { 835 before(async function () {
839 userToken = await generateUserAccessToken(servers[0], 'user_43') 836 userToken = await servers[0].usersCommand.generateUserAndToken('user_43')
840 837
841 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' }) 838 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
842 abuseId = body.abuse.id 839 abuseId = body.abuse.id
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index 4f2be6198..b44bcb012 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 ServerInfo, 9 ServerInfo,
@@ -76,9 +75,7 @@ describe('Test blocklist', function () {
76 75
77 { 76 {
78 const user = { username: 'user1', password: 'password' } 77 const user = { username: 'user1', password: 'password' }
79 await createUser({ 78 await servers[0].usersCommand.create({
80 url: servers[0].url,
81 accessToken: servers[0].accessToken,
82 username: user.username, 79 username: user.username,
83 password: user.password, 80 password: user.password,
84 videoQuota: -1, 81 videoQuota: -1,
@@ -91,14 +88,14 @@ describe('Test blocklist', function () {
91 88
92 { 89 {
93 const user = { username: 'user2', password: 'password' } 90 const user = { username: 'user2', password: 'password' }
94 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 91 await servers[0].usersCommand.create({ username: user.username, password: user.password })
95 92
96 userToken2 = await servers[0].loginCommand.getAccessToken(user) 93 userToken2 = await servers[0].loginCommand.getAccessToken(user)
97 } 94 }
98 95
99 { 96 {
100 const user = { username: 'user3', password: 'password' } 97 const user = { username: 'user3', password: 'password' }
101 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 98 await servers[1].usersCommand.create({ username: user.username, password: user.password })
102 99
103 remoteUserToken = await servers[1].loginCommand.getAccessToken(user) 100 remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
104 } 101 }
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index c38a7dad4..c253b5c11 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -6,7 +6,6 @@ import {
6 BlocklistCommand, 6 BlocklistCommand,
7 cleanupTests, 7 cleanupTests,
8 CommentsCommand, 8 CommentsCommand,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 getVideosList, 11 getVideosList,
@@ -91,7 +90,7 @@ describe('Test blocklist', function () {
91 90
92 { 91 {
93 const user = { username: 'user1', password: 'password' } 92 const user = { username: 'user1', password: 'password' }
94 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 93 await servers[0].usersCommand.create({ username: user.username, password: user.password })
95 94
96 userToken1 = await servers[0].loginCommand.getAccessToken(user) 95 userToken1 = await servers[0].loginCommand.getAccessToken(user)
97 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' }) 96 await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@@ -99,14 +98,14 @@ describe('Test blocklist', function () {
99 98
100 { 99 {
101 const user = { username: 'moderator', password: 'password' } 100 const user = { username: 'moderator', password: 'password' }
102 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 101 await servers[0].usersCommand.create({ username: user.username, password: user.password })
103 102
104 userModeratorToken = await servers[0].loginCommand.getAccessToken(user) 103 userModeratorToken = await servers[0].loginCommand.getAccessToken(user)
105 } 104 }
106 105
107 { 106 {
108 const user = { username: 'user2', password: 'password' } 107 const user = { username: 'user2', password: 'password' }
109 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 108 await servers[1].usersCommand.create({ username: user.username, password: user.password })
110 109
111 userToken2 = await servers[1].loginCommand.getAccessToken(user) 110 userToken2 = await servers[1].loginCommand.getAccessToken(user)
112 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' }) 111 await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index b61effc57..ef25cfb8e 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -6,10 +6,8 @@ import { orderBy } from 'lodash'
6import { 6import {
7 BlacklistCommand, 7 BlacklistCommand,
8 cleanupTests, 8 cleanupTests,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 getMyUserInformation,
13 getMyVideos, 11 getMyVideos,
14 getVideosList, 12 getVideosList,
15 ImportsCommand, 13 ImportsCommand,
@@ -21,7 +19,7 @@ import {
21 uploadVideo, 19 uploadVideo,
22 waitJobs 20 waitJobs
23} from '@shared/extra-utils' 21} from '@shared/extra-utils'
24import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' 22import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
25 23
26const expect = chai.expect 24const expect = chai.expect
27 25
@@ -356,9 +354,7 @@ describe('Test video blacklist', function () {
356 354
357 { 355 {
358 const user = { username: 'user_without_flag', password: 'password' } 356 const user = { username: 'user_without_flag', password: 'password' }
359 await createUser({ 357 await servers[0].usersCommand.create({
360 url: servers[0].url,
361 accessToken: servers[0].accessToken,
362 username: user.username, 358 username: user.username,
363 adminFlags: UserAdminFlag.NONE, 359 adminFlags: UserAdminFlag.NONE,
364 password: user.password, 360 password: user.password,
@@ -367,16 +363,13 @@ describe('Test video blacklist', function () {
367 363
368 userWithoutFlag = await servers[0].loginCommand.getAccessToken(user) 364 userWithoutFlag = await servers[0].loginCommand.getAccessToken(user)
369 365
370 const res = await getMyUserInformation(servers[0].url, userWithoutFlag) 366 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag })
371 const body: User = res.body 367 channelOfUserWithoutFlag = videoChannels[0].id
372 channelOfUserWithoutFlag = body.videoChannels[0].id
373 } 368 }
374 369
375 { 370 {
376 const user = { username: 'user_with_flag', password: 'password' } 371 const user = { username: 'user_with_flag', password: 'password' }
377 await createUser({ 372 await servers[0].usersCommand.create({
378 url: servers[0].url,
379 accessToken: servers[0].accessToken,
380 username: user.username, 373 username: user.username,
381 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, 374 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
382 password: user.password, 375 password: user.password,
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index ea6055386..62569f810 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -10,7 +10,6 @@ import {
10 MockSmtpServer, 10 MockSmtpServer,
11 prepareNotificationsTest, 11 prepareNotificationsTest,
12 ServerInfo, 12 ServerInfo,
13 updateMyUser,
14 uploadVideo, 13 uploadVideo,
15 waitJobs 14 waitJobs
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
@@ -193,17 +192,8 @@ describe('Test comments notifications', function () {
193 token: userToken 192 token: userToken
194 } 193 }
195 194
196 await updateMyUser({ 195 await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
197 url: servers[0].url, 196 await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
198 accessToken: servers[0].accessToken,
199 displayName: 'super root name'
200 })
201
202 await updateMyUser({
203 url: servers[1].url,
204 accessToken: servers[1].accessToken,
205 displayName: 'super root 2 name'
206 })
207 }) 197 })
208 198
209 it('Should not send a new mention comment notification if I mention the video owner', async function () { 199 it('Should not send a new mention comment notification if I mention the video owner', async function () {
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 99b434606..0269124c5 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -17,13 +17,10 @@ import {
17 checkVideoAutoBlacklistForModerators, 17 checkVideoAutoBlacklistForModerators,
18 checkVideoIsPublished, 18 checkVideoIsPublished,
19 cleanupTests, 19 cleanupTests,
20 createUser,
21 generateUserAccessToken,
22 getVideoIdFromUUID, 20 getVideoIdFromUUID,
23 MockInstancesIndex, 21 MockInstancesIndex,
24 MockSmtpServer, 22 MockSmtpServer,
25 prepareNotificationsTest, 23 prepareNotificationsTest,
26 registerUser,
27 ServerInfo, 24 ServerInfo,
28 uploadVideo, 25 uploadVideo,
29 wait, 26 wait,
@@ -139,8 +136,8 @@ describe('Test moderation notifications', function () {
139 this.timeout(20000) 136 this.timeout(20000)
140 137
141 const username = 'user' + new Date().getTime() 138 const username = 'user' + new Date().getTime()
142 const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) 139 const { account } = await servers[0].usersCommand.create({ username, password: 'donald' })
143 const accountId = resUser.body.user.account.id 140 const accountId = account.id
144 141
145 await servers[0].abusesCommand.report({ accountId, reason: 'super reason' }) 142 await servers[0].abusesCommand.report({ accountId, reason: 'super reason' })
146 143
@@ -152,7 +149,7 @@ describe('Test moderation notifications', function () {
152 this.timeout(20000) 149 this.timeout(20000)
153 150
154 const username = 'user' + new Date().getTime() 151 const username = 'user' + new Date().getTime()
155 const tmpToken = await generateUserAccessToken(servers[0], username) 152 const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
156 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) 153 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' })
157 154
158 await waitJobs(servers) 155 await waitJobs(servers)
@@ -339,7 +336,7 @@ describe('Test moderation notifications', function () {
339 it('Should send a notification only to moderators when a user registers on the instance', async function () { 336 it('Should send a notification only to moderators when a user registers on the instance', async function () {
340 this.timeout(10000) 337 this.timeout(10000)
341 338
342 await registerUser(servers[0].url, 'user_45', 'password') 339 await servers[0].usersCommand.register({ username: 'user_45' })
343 340
344 await waitJobs(servers) 341 await waitJobs(servers)
345 342
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index e5864f1c2..f33d8e64d 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -7,14 +7,13 @@ import {
7 checkNewVideoFromSubscription, 7 checkNewVideoFromSubscription,
8 cleanupTests, 8 cleanupTests,
9 getAllNotificationsSettings, 9 getAllNotificationsSettings,
10 getMyUserInformation,
11 MockSmtpServer, 10 MockSmtpServer,
12 prepareNotificationsTest, 11 prepareNotificationsTest,
13 ServerInfo, 12 ServerInfo,
14 uploadRandomVideo, 13 uploadRandomVideo,
15 waitJobs 14 waitJobs
16} from '@shared/extra-utils' 15} from '@shared/extra-utils'
17import { User, UserNotification, UserNotificationSettingValue } from '@shared/models' 16import { UserNotification, UserNotificationSettingValue } from '@shared/models'
18 17
19const expect = chai.expect 18const expect = chai.expect
20 19
@@ -109,15 +108,14 @@ describe('Test notifications API', function () {
109 }) 108 })
110 109
111 { 110 {
112 const res = await getMyUserInformation(server.url, userToken) 111 const info = await server.usersCommand.getMyInfo({ token: userToken })
113 const info = res.body as User
114 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE) 112 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
115 } 113 }
116 114
117 const { name, uuid } = await uploadRandomVideo(server) 115 const { name, uuid } = await uploadRandomVideo(server)
118 116
119 const check = { web: true, mail: true } 117 const check = { web: true, mail: true }
120 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 118 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
121 }) 119 })
122 120
123 it('Should only have web notifications', async function () { 121 it('Should only have web notifications', async function () {
@@ -129,8 +127,7 @@ describe('Test notifications API', function () {
129 }) 127 })
130 128
131 { 129 {
132 const res = await getMyUserInformation(server.url, userToken) 130 const info = await server.usersCommand.getMyInfo({ token: userToken })
133 const info = res.body as User
134 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB) 131 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
135 } 132 }
136 133
@@ -138,12 +135,12 @@ describe('Test notifications API', function () {
138 135
139 { 136 {
140 const check = { mail: true, web: false } 137 const check = { mail: true, web: false }
141 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 138 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
142 } 139 }
143 140
144 { 141 {
145 const check = { mail: false, web: true } 142 const check = { mail: false, web: true }
146 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') 143 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
147 } 144 }
148 }) 145 })
149 146
@@ -156,8 +153,7 @@ describe('Test notifications API', function () {
156 }) 153 })
157 154
158 { 155 {
159 const res = await getMyUserInformation(server.url, userToken) 156 const info = await server.usersCommand.getMyInfo({ token: userToken })
160 const info = res.body as User
161 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL) 157 expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
162 } 158 }
163 159
@@ -165,12 +161,12 @@ describe('Test notifications API', function () {
165 161
166 { 162 {
167 const check = { mail: false, web: true } 163 const check = { mail: false, web: true }
168 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence') 164 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
169 } 165 }
170 166
171 { 167 {
172 const check = { mail: true, web: false } 168 const check = { mail: true, web: false }
173 await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence') 169 await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
174 } 170 }
175 }) 171 })
176 172
@@ -186,8 +182,7 @@ describe('Test notifications API', function () {
186 }) 182 })
187 183
188 { 184 {
189 const res = await getMyUserInformation(server.url, userToken) 185 const info = await server.usersCommand.getMyInfo({ token: userToken })
190 const info = res.body as User
191 expect(info.notificationSettings.newVideoFromSubscription).to.equal( 186 expect(info.notificationSettings.newVideoFromSubscription).to.equal(
192 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL 187 UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
193 ) 188 )
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 4b31edf25..465349fb9 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -14,7 +14,6 @@ import {
14 MockSmtpServer, 14 MockSmtpServer,
15 prepareNotificationsTest, 15 prepareNotificationsTest,
16 ServerInfo, 16 ServerInfo,
17 updateMyUser,
18 updateVideo, 17 updateVideo,
19 uploadRandomVideoOnServers, 18 uploadRandomVideoOnServers,
20 wait, 19 wait,
@@ -384,23 +383,14 @@ describe('Test user notifications', function () {
384 token: userAccessToken 383 token: userAccessToken
385 } 384 }
386 385
387 await updateMyUser({ 386 await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
388 url: servers[0].url,
389 accessToken: servers[0].accessToken,
390 displayName: 'super root name'
391 })
392 387
393 await updateMyUser({ 388 await servers[0].usersCommand.updateMe({
394 url: servers[0].url, 389 token: userAccessToken,
395 accessToken: userAccessToken,
396 displayName: myUserName 390 displayName: myUserName
397 }) 391 })
398 392
399 await updateMyUser({ 393 await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
400 url: servers[1].url,
401 accessToken: servers[1].accessToken,
402 displayName: 'super root 2 name'
403 })
404 394
405 await servers[0].channelsCommand.update({ 395 await servers[0].channelsCommand.update({
406 token: userAccessToken, 396 token: userAccessToken,
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index 3cba2b019..bcc21381c 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -4,13 +4,11 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
9 getVideoChannelVideos, 8 getVideoChannelVideos,
10 SearchCommand, 9 SearchCommand,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 updateMyUser,
14 updateVideo, 12 updateVideo,
15 uploadVideo, 13 uploadVideo,
16 wait, 14 wait,
@@ -35,7 +33,7 @@ describe('Test ActivityPub video channels search', function () {
35 await setAccessTokensToServers(servers) 33 await setAccessTokensToServers(servers)
36 34
37 { 35 {
38 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' }) 36 await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' })
39 const channel = { 37 const channel = {
40 name: 'channel1_server1', 38 name: 'channel1_server1',
41 displayName: 'Channel 1 server 1' 39 displayName: 'Channel 1 server 1'
@@ -45,7 +43,7 @@ describe('Test ActivityPub video channels search', function () {
45 43
46 { 44 {
47 const user = { username: 'user1_server2', password: 'password' } 45 const user = { username: 'user1_server2', password: 'password' }
48 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 46 await servers[1].usersCommand.create({ username: user.username, password: user.password })
49 userServer2Token = await servers[1].loginCommand.getAccessToken(user) 47 userServer2Token = await servers[1].loginCommand.getAccessToken(user)
50 48
51 const channel = { 49 const channel = {
@@ -171,7 +169,7 @@ describe('Test ActivityPub video channels search', function () {
171 channelName: 'channel1_server2', 169 channelName: 'channel1_server2',
172 attributes: { displayName: 'channel updated' } 170 attributes: { displayName: 'channel updated' }
173 }) 171 })
174 await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' }) 172 await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' })
175 173
176 await waitJobs(servers) 174 await waitJobs(servers)
177 // Expire video channel 175 // Expire video channel
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts
index 6c9ee73ce..4d2104708 100644
--- a/server/tests/api/search/search-channels.ts
+++ b/server/tests/api/search/search-channels.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils' 5import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
6import { VideoChannel } from '@shared/models' 6import { VideoChannel } from '@shared/models'
7 7
8const expect = chai.expect 8const expect = chai.expect
@@ -19,7 +19,7 @@ describe('Test channels search', function () {
19 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
20 20
21 { 21 {
22 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' }) 22 await server.usersCommand.create({ username: 'user1', password: 'password' })
23 const channel = { 23 const channel = {
24 name: 'squall_channel', 24 name: 'squall_channel',
25 displayName: 'Squall channel' 25 displayName: 'Squall channel'
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index a09c21228..20a9a3dc7 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { 5import {
6 BulkCommand, 6 BulkCommand,
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
11 getVideosList, 10 getVideosList,
@@ -38,21 +37,21 @@ describe('Test bulk actions', function () {
38 37
39 { 38 {
40 const user = { username: 'user1', password: 'password' } 39 const user = { username: 'user1', password: 'password' }
41 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 40 await servers[0].usersCommand.create({ username: user.username, password: user.password })
42 41
43 user1Token = await servers[0].loginCommand.getAccessToken(user) 42 user1Token = await servers[0].loginCommand.getAccessToken(user)
44 } 43 }
45 44
46 { 45 {
47 const user = { username: 'user2', password: 'password' } 46 const user = { username: 'user2', password: 'password' }
48 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 47 await servers[0].usersCommand.create({ username: user.username, password: user.password })
49 48
50 user2Token = await servers[0].loginCommand.getAccessToken(user) 49 user2Token = await servers[0].loginCommand.getAccessToken(user)
51 } 50 }
52 51
53 { 52 {
54 const user = { username: 'user3', password: 'password' } 53 const user = { username: 'user3', password: 'password' }
55 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 54 await servers[1].usersCommand.create({ username: user.username, password: user.password })
56 55
57 user3Token = await servers[1].loginCommand.getAccessToken(user) 56 user3Token = await servers[1].loginCommand.getAccessToken(user)
58 } 57 }
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 55cf2a1b8..95dafd378 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -9,7 +9,6 @@ import {
9 killallServers, 9 killallServers,
10 makeGetRequest, 10 makeGetRequest,
11 parallelTests, 11 parallelTests,
12 registerUser,
13 reRunServer, 12 reRunServer,
14 ServerInfo, 13 ServerInfo,
15 setAccessTokensToServers, 14 setAccessTokensToServers,
@@ -225,9 +224,9 @@ describe('Test config', function () {
225 this.timeout(5000) 224 this.timeout(5000)
226 225
227 await Promise.all([ 226 await Promise.all([
228 registerUser(server.url, 'user1', 'super password'), 227 server.usersCommand.register({ username: 'user1' }),
229 registerUser(server.url, 'user2', 'super password'), 228 server.usersCommand.register({ username: 'user2' }),
230 registerUser(server.url, 'user3', 'super password') 229 server.usersCommand.register({ username: 'user3' })
231 ]) 230 ])
232 231
233 const data = await server.configCommand.getConfig() 232 const data = await server.configCommand.getConfig()
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index c64c120e3..422db6ceb 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -2,23 +2,16 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 askResetPassword,
8 askSendVerifyEmail,
9 blockUser,
10 cleanupTests, 7 cleanupTests,
11 createUser,
12 flushAndRunServer, 8 flushAndRunServer,
13 resetPassword, 9 MockSmtpServer,
14 ServerInfo, 10 ServerInfo,
15 setAccessTokensToServers, 11 setAccessTokensToServers,
16 unblockUser,
17 uploadVideo, 12 uploadVideo,
18 verifyEmail 13 waitJobs
19} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
20import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22 15
23const expect = chai.expect 16const expect = chai.expect
24 17
@@ -58,8 +51,8 @@ describe('Test emails', function () {
58 await setAccessTokensToServers([ server ]) 51 await setAccessTokensToServers([ server ])
59 52
60 { 53 {
61 const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 54 const created = await server.usersCommand.create({ username: user.username, password: user.password })
62 userId = res.body.user.id 55 userId = created.id
63 56
64 userAccessToken = await server.loginCommand.getAccessToken(user) 57 userAccessToken = await server.loginCommand.getAccessToken(user)
65 } 58 }
@@ -87,7 +80,7 @@ describe('Test emails', function () {
87 it('Should ask to reset the password', async function () { 80 it('Should ask to reset the password', async function () {
88 this.timeout(10000) 81 this.timeout(10000)
89 82
90 await askResetPassword(server.url, 'user_1@example.com') 83 await server.usersCommand.askResetPassword({ email: 'user_1@example.com' })
91 84
92 await waitJobs(server) 85 await waitJobs(server)
93 expect(emails).to.have.lengthOf(1) 86 expect(emails).to.have.lengthOf(1)
@@ -113,15 +106,25 @@ describe('Test emails', function () {
113 }) 106 })
114 107
115 it('Should not reset the password with an invalid verification string', async function () { 108 it('Should not reset the password with an invalid verification string', async function () {
116 await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', HttpStatusCode.FORBIDDEN_403) 109 await server.usersCommand.resetPassword({
110 userId,
111 verificationString: verificationString + 'b',
112 password: 'super_password2',
113 expectedStatus: HttpStatusCode.FORBIDDEN_403
114 })
117 }) 115 })
118 116
119 it('Should reset the password', async function () { 117 it('Should reset the password', async function () {
120 await resetPassword(server.url, userId, verificationString, 'super_password2') 118 await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' })
121 }) 119 })
122 120
123 it('Should not reset the password with the same verification string', async function () { 121 it('Should not reset the password with the same verification string', async function () {
124 await resetPassword(server.url, userId, verificationString, 'super_password3', HttpStatusCode.FORBIDDEN_403) 122 await server.usersCommand.resetPassword({
123 userId,
124 verificationString,
125 password: 'super_password3',
126 expectedStatus: HttpStatusCode.FORBIDDEN_403
127 })
125 }) 128 })
126 129
127 it('Should login with this new password', async function () { 130 it('Should login with this new password', async function () {
@@ -132,15 +135,11 @@ describe('Test emails', function () {
132 }) 135 })
133 136
134 describe('When creating a user without password', function () { 137 describe('When creating a user without password', function () {
138
135 it('Should send a create password email', async function () { 139 it('Should send a create password email', async function () {
136 this.timeout(10000) 140 this.timeout(10000)
137 141
138 await createUser({ 142 await server.usersCommand.create({ username: 'create_password', password: '' })
139 url: server.url,
140 accessToken: server.accessToken,
141 username: 'create_password',
142 password: ''
143 })
144 143
145 await waitJobs(server) 144 await waitJobs(server)
146 expect(emails).to.have.lengthOf(2) 145 expect(emails).to.have.lengthOf(2)
@@ -166,11 +165,20 @@ describe('Test emails', function () {
166 }) 165 })
167 166
168 it('Should not reset the password with an invalid verification string', async function () { 167 it('Should not reset the password with an invalid verification string', async function () {
169 await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', HttpStatusCode.FORBIDDEN_403) 168 await server.usersCommand.resetPassword({
169 userId: userId2,
170 verificationString: verificationString2 + 'c',
171 password: 'newly_created_password',
172 expectedStatus: HttpStatusCode.FORBIDDEN_403
173 })
170 }) 174 })
171 175
172 it('Should reset the password', async function () { 176 it('Should reset the password', async function () {
173 await resetPassword(server.url, userId2, verificationString2, 'newly_created_password') 177 await server.usersCommand.resetPassword({
178 userId: userId2,
179 verificationString: verificationString2,
180 password: 'newly_created_password'
181 })
174 }) 182 })
175 183
176 it('Should login with this new password', async function () { 184 it('Should login with this new password', async function () {
@@ -207,7 +215,7 @@ describe('Test emails', function () {
207 this.timeout(10000) 215 this.timeout(10000)
208 216
209 const reason = 'my super bad reason' 217 const reason = 'my super bad reason'
210 await blockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204, reason) 218 await server.usersCommand.banUser({ userId, reason })
211 219
212 await waitJobs(server) 220 await waitJobs(server)
213 expect(emails).to.have.lengthOf(4) 221 expect(emails).to.have.lengthOf(4)
@@ -225,7 +233,7 @@ describe('Test emails', function () {
225 it('Should send the notification email when unblocking a user', async function () { 233 it('Should send the notification email when unblocking a user', async function () {
226 this.timeout(10000) 234 this.timeout(10000)
227 235
228 await unblockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204) 236 await server.usersCommand.unbanUser({ userId })
229 237
230 await waitJobs(server) 238 await waitJobs(server)
231 expect(emails).to.have.lengthOf(5) 239 expect(emails).to.have.lengthOf(5)
@@ -288,7 +296,7 @@ describe('Test emails', function () {
288 it('Should ask to send the verification email', async function () { 296 it('Should ask to send the verification email', async function () {
289 this.timeout(10000) 297 this.timeout(10000)
290 298
291 await askSendVerifyEmail(server.url, 'user_1@example.com') 299 await server.usersCommand.askSendVerifyEmail({ email: 'user_1@example.com' })
292 300
293 await waitJobs(server) 301 await waitJobs(server)
294 expect(emails).to.have.lengthOf(8) 302 expect(emails).to.have.lengthOf(8)
@@ -314,11 +322,16 @@ describe('Test emails', function () {
314 }) 322 })
315 323
316 it('Should not verify the email with an invalid verification string', async function () { 324 it('Should not verify the email with an invalid verification string', async function () {
317 await verifyEmail(server.url, userId, verificationString + 'b', false, HttpStatusCode.FORBIDDEN_403) 325 await server.usersCommand.verifyEmail({
326 userId,
327 verificationString: verificationString + 'b',
328 isPendingEmail: false,
329 expectedStatus: HttpStatusCode.FORBIDDEN_403
330 })
318 }) 331 })
319 332
320 it('Should verify the email', async function () { 333 it('Should verify the email', async function () {
321 await verifyEmail(server.url, userId, verificationString) 334 await server.usersCommand.verifyEmail({ userId, verificationString })
322 }) 335 })
323 }) 336 })
324 337
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 74cdf353b..29ccb264d 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' 6import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 getAccountVideos, 11 getAccountVideos,
@@ -47,7 +46,7 @@ describe('Test follow constraints', function () {
47 username: 'user1', 46 username: 'user1',
48 password: 'super_password' 47 password: 'super_password'
49 } 48 }
50 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 49 await servers[0].usersCommand.create({ username: user.username, password: user.password })
51 userAccessToken = await servers[0].loginCommand.getAccessToken(user) 50 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
52 51
53 await doubleFollow(servers[0], servers[1]) 52 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index c2a0620a5..02d25e67f 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 completeVideoCheck, 7 completeVideoCheck,
8 createUser,
9 dateIsValid, 8 dateIsValid,
10 expectAccountFollows, 9 expectAccountFollows,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -327,9 +326,7 @@ describe('Test follows', function () {
327 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' }) 326 await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
328 327
329 { 328 {
330 const user = { username: 'captain', password: 'password' } 329 const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
331 await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password })
332 const userAccessToken = await servers[2].loginCommand.getAccessToken(user)
333 330
334 const resVideos = await getVideosList(servers[2].url) 331 const resVideos = await getVideosList(servers[2].url)
335 video4 = resVideos.body.data.find(v => v.name === 'server3-4') 332 video4 = resVideos.body.data.find(v => v.name === 'server3-4')
diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts
index c0b9facff..6854568d3 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -30,7 +30,7 @@ describe('Test jobs', function () {
30 }) 30 })
31 31
32 it('Should create some jobs', async function () { 32 it('Should create some jobs', async function () {
33 this.timeout(60000) 33 this.timeout(120000)
34 34
35 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' }) 35 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
36 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) 36 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index a81ac961a..1fd5e613b 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -6,17 +6,15 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 flushAndRunServer,
9 getMyUserInformation,
10 killallServers, 9 killallServers,
11 PluginsCommand, 10 PluginsCommand,
12 reRunServer, 11 reRunServer,
13 ServerInfo, 12 ServerInfo,
14 setAccessTokensToServers, 13 setAccessTokensToServers,
15 testHelloWorldRegisteredSettings, 14 testHelloWorldRegisteredSettings,
16 updateMyUser,
17 wait 15 wait
18} from '@shared/extra-utils' 16} from '@shared/extra-utils'
19import { PluginType, User } from '@shared/models' 17import { PluginType } from '@shared/models'
20 18
21const expect = chai.expect 19const expect = chai.expect
22 20
@@ -120,14 +118,10 @@ describe('Test plugins', function () {
120 }) 118 })
121 119
122 it('Should update my default theme', async function () { 120 it('Should update my default theme', async function () {
123 await updateMyUser({ 121 await server.usersCommand.updateMe({ theme: 'background-red' })
124 url: server.url,
125 accessToken: server.accessToken,
126 theme: 'background-red'
127 })
128 122
129 const res = await getMyUserInformation(server.url, server.accessToken) 123 const user = await server.usersCommand.getMyInfo()
130 expect((res.body as User).theme).to.equal('background-red') 124 expect(user.theme).to.equal('background-red')
131 }) 125 })
132 126
133 it('Should list plugins and themes', async function () { 127 it('Should list plugins and themes', async function () {
@@ -311,8 +305,8 @@ describe('Test plugins', function () {
311 }) 305 })
312 306
313 it('Should have updated the user theme', async function () { 307 it('Should have updated the user theme', async function () {
314 const res = await getMyUserInformation(server.url, server.accessToken) 308 const user = await server.usersCommand.getMyInfo()
315 expect((res.body as User).theme).to.equal('instance-default') 309 expect(user.theme).to.equal('instance-default')
316 }) 310 })
317 311
318 it('Should not install a broken plugin', async function () { 312 it('Should not install a broken plugin', async function () {
diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts
index d9c669571..b8bae161a 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -6,7 +6,7 @@ import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunServer, 7 flushAndRunServer,
8 getVideo, 8 getVideo,
9 registerUser, 9 ServerInfo,
10 setAccessTokensToServers, 10 setAccessTokensToServers,
11 uploadVideo, 11 uploadVideo,
12 viewVideo, 12 viewVideo,
@@ -14,8 +14,8 @@ import {
14} from '@shared/extra-utils' 14} from '@shared/extra-utils'
15 15
16describe('Test application behind a reverse proxy', function () { 16describe('Test application behind a reverse proxy', function () {
17 let server = null 17 let server: ServerInfo
18 let videoId 18 let videoId: number
19 19
20 before(async function () { 20 before(async function () {
21 this.timeout(30000) 21 this.timeout(30000)
@@ -102,22 +102,22 @@ describe('Test application behind a reverse proxy', function () {
102 const user = { username: 'root', password: 'fail' } 102 const user = { username: 'root', password: 'fail' }
103 103
104 for (let i = 0; i < 19; i++) { 104 for (let i = 0; i < 19; i++) {
105 await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400) 105 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
106 } 106 }
107 107
108 await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429) 108 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
109 }) 109 })
110 110
111 it('Should rate limit signup', async function () { 111 it('Should rate limit signup', async function () {
112 for (let i = 0; i < 10; i++) { 112 for (let i = 0; i < 10; i++) {
113 try { 113 try {
114 await registerUser(server.url, 'test' + i, 'password') 114 await server.usersCommand.register({ username: 'test' + i })
115 } catch { 115 } catch {
116 // empty 116 // empty
117 } 117 }
118 } 118 }
119 119
120 await registerUser(server.url, 'test42', 'password', HttpStatusCode.TOO_MANY_REQUESTS_429) 120 await server.usersCommand.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
121 }) 121 })
122 122
123 it('Should not rate limit failed signup', async function () { 123 it('Should not rate limit failed signup', async function () {
@@ -126,10 +126,10 @@ describe('Test application behind a reverse proxy', function () {
126 await wait(7000) 126 await wait(7000)
127 127
128 for (let i = 0; i < 3; i++) { 128 for (let i = 0; i < 3; i++) {
129 await registerUser(server.url, 'test' + i, 'password', HttpStatusCode.CONFLICT_409) 129 await server.usersCommand.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 })
130 } 130 }
131 131
132 await registerUser(server.url, 'test43', 'password', HttpStatusCode.NO_CONTENT_204) 132 await server.usersCommand.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
133 133
134 }) 134 })
135 135
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index aa26f978d..a35709c26 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 ServerInfo, 9 ServerInfo,
@@ -35,7 +34,7 @@ describe('Test stats (excluding redundancy)', function () {
35 34
36 await doubleFollow(servers[0], servers[1]) 35 await doubleFollow(servers[0], servers[1])
37 36
38 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 37 await servers[0].usersCommand.create({ username: user.username, password: user.password })
39 38
40 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' }) 39 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
41 const videoUUID = resVideo.body.video.uuid 40 const videoUUID = resVideo.body.video.uuid
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts
index 1d0fc35f1..c09a85a32 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -4,7 +4,6 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 doubleFollow, 7 doubleFollow,
9 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
10 getVideosList, 9 getVideosList,
@@ -39,7 +38,7 @@ describe('Test users subscriptions', function () {
39 { 38 {
40 for (const server of servers) { 39 for (const server of servers) {
41 const user = { username: 'user' + server.serverNumber, password: 'password' } 40 const user = { username: 'user' + server.serverNumber, password: 'password' }
42 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 41 await server.usersCommand.create({ username: user.username, password: user.password })
43 42
44 const accessToken = await server.loginCommand.getAccessToken(user) 43 const accessToken = await server.loginCommand.getAccessToken(user)
45 users.push({ accessToken }) 44 users.push({ accessToken })
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 99fa08fe2..43e67ee60 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -7,17 +7,12 @@ import {
7 checkTmpIsEmpty, 7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 cleanupTests, 9 cleanupTests,
10 createUser,
11 doubleFollow, 10 doubleFollow,
12 flushAndRunMultipleServers, 11 flushAndRunMultipleServers,
13 getAccountVideos, 12 getAccountVideos,
14 getMyUserInformation,
15 removeUser,
16 ServerInfo, 13 ServerInfo,
17 setAccessTokensToServers, 14 setAccessTokensToServers,
18 testImage, 15 testImage,
19 updateMyAvatar,
20 updateMyUser,
21 uploadVideo, 16 uploadVideo,
22 waitJobs 17 waitJobs
23} from '@shared/extra-utils' 18} from '@shared/extra-utils'
@@ -56,13 +51,8 @@ describe('Test users with multiple servers', function () {
56 username: 'user1', 51 username: 'user1',
57 password: 'password' 52 password: 'password'
58 } 53 }
59 const res = await createUser({ 54 const created = await servers[0].usersCommand.create(user)
60 url: servers[0].url, 55 userId = created.id
61 accessToken: servers[0].accessToken,
62 username: user.username,
63 password: user.password
64 })
65 userId = res.body.user.id
66 userAccessToken = await servers[0].loginCommand.getAccessToken(user) 56 userAccessToken = await servers[0].loginCommand.getAccessToken(user)
67 } 57 }
68 58
@@ -77,15 +67,9 @@ describe('Test users with multiple servers', function () {
77 it('Should be able to update my display name', async function () { 67 it('Should be able to update my display name', async function () {
78 this.timeout(10000) 68 this.timeout(10000)
79 69
80 await updateMyUser({ 70 await servers[0].usersCommand.updateMe({ displayName: 'my super display name' })
81 url: servers[0].url,
82 accessToken: servers[0].accessToken,
83 displayName: 'my super display name'
84 })
85
86 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
87 user = res.body
88 71
72 user = await servers[0].usersCommand.getMyInfo()
89 expect(user.account.displayName).to.equal('my super display name') 73 expect(user.account.displayName).to.equal('my super display name')
90 74
91 await waitJobs(servers) 75 await waitJobs(servers)
@@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () {
94 it('Should be able to update my description', async function () { 78 it('Should be able to update my description', async function () {
95 this.timeout(10_000) 79 this.timeout(10_000)
96 80
97 await updateMyUser({ 81 await servers[0].usersCommand.updateMe({ description: 'my super description updated' })
98 url: servers[0].url,
99 accessToken: servers[0].accessToken,
100 description: 'my super description updated'
101 })
102 82
103 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 83 user = await servers[0].usersCommand.getMyInfo()
104 user = res.body
105 expect(user.account.displayName).to.equal('my super display name') 84 expect(user.account.displayName).to.equal('my super display name')
106 expect(user.account.description).to.equal('my super description updated') 85 expect(user.account.description).to.equal('my super description updated')
107 86
@@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () {
113 92
114 const fixture = 'avatar2.png' 93 const fixture = 'avatar2.png'
115 94
116 await updateMyAvatar({ 95 await servers[0].usersCommand.updateMyAvatar({ fixture })
117 url: servers[0].url,
118 accessToken: servers[0].accessToken,
119 fixture
120 })
121
122 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
123 user = res.body
124 96
97 user = await servers[0].usersCommand.getMyInfo()
125 userAvatarFilename = user.account.avatar.path 98 userAvatarFilename = user.account.avatar.path
126 99
127 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') 100 await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
@@ -202,7 +175,7 @@ describe('Test users with multiple servers', function () {
202 expect(videoChannelDeleted).not.to.be.undefined 175 expect(videoChannelDeleted).not.to.be.undefined
203 } 176 }
204 177
205 await removeUser(servers[0].url, userId, servers[0].accessToken) 178 await servers[0].usersCommand.remove({ userId })
206 179
207 await waitJobs(servers) 180 await waitJobs(servers)
208 181
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index ade730323..271aa3c7a 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -3,20 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 cleanupTests,
8 flushAndRunServer,
9 getMyUserInformation,
10 getUserInformation,
11 MockSmtpServer,
12 registerUser,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateMyUser,
16 verifyEmail,
17 waitJobs
18} from '@shared/extra-utils'
19import { User } from '@shared/models'
20 7
21const expect = chai.expect 8const expect = chai.expect
22 9
@@ -65,7 +52,7 @@ describe('Test users account verification', function () {
65 } 52 }
66 }) 53 })
67 54
68 await registerUser(server.url, user1.username, user1.password) 55 await server.usersCommand.register(user1)
69 56
70 await waitJobs(server) 57 await waitJobs(server)
71 expectedEmailsLength++ 58 expectedEmailsLength++
@@ -84,8 +71,8 @@ describe('Test users account verification', function () {
84 71
85 userId = parseInt(userIdMatches[1], 10) 72 userId = parseInt(userIdMatches[1], 10)
86 73
87 const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) 74 const body = await server.usersCommand.get({ userId })
88 expect(resUserInfo.body.emailVerified).to.be.false 75 expect(body.emailVerified).to.be.false
89 }) 76 })
90 77
91 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 () {
@@ -94,13 +81,13 @@ describe('Test users account verification', function () {
94 }) 81 })
95 82
96 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 () {
97 await verifyEmail(server.url, userId, verificationString) 84 await server.usersCommand.verifyEmail({ userId, verificationString })
98 85
99 const body = await server.loginCommand.login({ user: user1 }) 86 const body = await server.loginCommand.login({ user: user1 })
100 userAccessToken = body.access_token 87 userAccessToken = body.access_token
101 88
102 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 89 const user = await server.usersCommand.get({ userId })
103 expect(resUserVerified.body.emailVerified).to.be.true 90 expect(user.emailVerified).to.be.true
104 }) 91 })
105 92
106 it('Should be able to change the user email', async function () { 93 it('Should be able to change the user email', async function () {
@@ -109,9 +96,8 @@ describe('Test users account verification', function () {
109 let updateVerificationString: string 96 let updateVerificationString: string
110 97
111 { 98 {
112 await updateMyUser({ 99 await server.usersCommand.updateMe({
113 url: server.url, 100 token: userAccessToken,
114 accessToken: userAccessToken,
115 email: 'updated@example.com', 101 email: 'updated@example.com',
116 currentPassword: user1.password 102 currentPassword: user1.password
117 }) 103 })
@@ -127,19 +113,15 @@ describe('Test users account verification', function () {
127 } 113 }
128 114
129 { 115 {
130 const res = await getMyUserInformation(server.url, userAccessToken) 116 const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
131 const me: User = res.body
132
133 expect(me.email).to.equal('user_1@example.com') 117 expect(me.email).to.equal('user_1@example.com')
134 expect(me.pendingEmail).to.equal('updated@example.com') 118 expect(me.pendingEmail).to.equal('updated@example.com')
135 } 119 }
136 120
137 { 121 {
138 await verifyEmail(server.url, userId, updateVerificationString, true) 122 await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true })
139
140 const res = await getMyUserInformation(server.url, userAccessToken)
141 const me: User = res.body
142 123
124 const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
143 expect(me.email).to.equal('updated@example.com') 125 expect(me.email).to.equal('updated@example.com')
144 expect(me.pendingEmail).to.be.null 126 expect(me.pendingEmail).to.be.null
145 } 127 }
@@ -157,15 +139,15 @@ describe('Test users account verification', function () {
157 } 139 }
158 }) 140 })
159 141
160 await registerUser(server.url, user2.username, user2.password) 142 await server.usersCommand.register(user2)
161 143
162 await waitJobs(server) 144 await waitJobs(server)
163 expect(emails).to.have.lengthOf(expectedEmailsLength) 145 expect(emails).to.have.lengthOf(expectedEmailsLength)
164 146
165 const accessToken = await server.loginCommand.getAccessToken(user2) 147 const accessToken = await server.loginCommand.getAccessToken(user2)
166 148
167 const resMyUserInfo = await getMyUserInformation(server.url, accessToken) 149 const user = await server.usersCommand.getMyInfo({ token: accessToken })
168 expect(resMyUserInfo.body.emailVerified).to.be.null 150 expect(user.emailVerified).to.be.null
169 }) 151 })
170 152
171 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 () {
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 608bedb8b..30d7e850d 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -4,37 +4,22 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 blockUser,
8 cleanupTests, 7 cleanupTests,
9 createUser,
10 deleteMe,
11 flushAndRunServer, 8 flushAndRunServer,
12 getMyUserInformation,
13 getMyUserVideoQuotaUsed,
14 getMyUserVideoRating,
15 getMyVideos, 9 getMyVideos,
16 getUserInformation,
17 getUsersList,
18 getUsersListPaginationAndSort,
19 getVideosList, 10 getVideosList,
20 killallServers, 11 killallServers,
21 makePutBodyRequest, 12 makePutBodyRequest,
22 rateVideo, 13 rateVideo,
23 registerUserWithChannel,
24 removeUser,
25 removeVideo, 14 removeVideo,
26 reRunServer, 15 reRunServer,
27 ServerInfo, 16 ServerInfo,
28 setAccessTokensToServers, 17 setAccessTokensToServers,
29 testImage, 18 testImage,
30 unblockUser,
31 updateMyAvatar,
32 updateMyUser,
33 updateUser,
34 uploadVideo, 19 uploadVideo,
35 waitJobs 20 waitJobs
36} from '@shared/extra-utils' 21} from '@shared/extra-utils'
37import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' 22import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
38 23
39const expect = chai.expect 24const expect = chai.expect
40 25
@@ -174,8 +159,7 @@ describe('Test users', function () {
174 159
175 it('Should retrieve a video rating', async function () { 160 it('Should retrieve a video rating', async function () {
176 await rateVideo(server.url, accessToken, videoId, 'like') 161 await rateVideo(server.url, accessToken, videoId, 'like')
177 const res = await getMyUserVideoRating(server.url, accessToken, videoId) 162 const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId })
178 const rating = res.body
179 163
180 expect(rating.videoId).to.equal(videoId) 164 expect(rating.videoId).to.equal(videoId)
181 expect(rating.rating).to.equal('like') 165 expect(rating.rating).to.equal('like')
@@ -222,7 +206,7 @@ describe('Test users', function () {
222 }) 206 })
223 207
224 it('Should not be able to get the user information', async function () { 208 it('Should not be able to get the user information', async function () {
225 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) 209 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
226 }) 210 })
227 211
228 it('Should not be able to upload a video', async function () { 212 it('Should not be able to upload a video', async function () {
@@ -252,7 +236,7 @@ describe('Test users', function () {
252 }) 236 })
253 237
254 it('Should be able to get my user information again', async function () { 238 it('Should be able to get my user information again', async function () {
255 await getMyUserInformation(server.url, server.accessToken) 239 await server.usersCommand.getMyInfo()
256 }) 240 })
257 241
258 it('Should have an expired access token', async function () { 242 it('Should have an expired access token', async function () {
@@ -264,7 +248,7 @@ describe('Test users', function () {
264 await killallServers([ server ]) 248 await killallServers([ server ])
265 await reRunServer(server) 249 await reRunServer(server)
266 250
267 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) 251 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
268 }) 252 })
269 253
270 it('Should not be able to refresh an access token with an expired refresh token', async function () { 254 it('Should not be able to refresh an access token with an expired refresh token', async function () {
@@ -286,21 +270,14 @@ describe('Test users', function () {
286 }) 270 })
287 271
288 it('Should be able to get my user information again', async function () { 272 it('Should be able to get my user information again', async function () {
289 await getMyUserInformation(server.url, server.accessToken) 273 await server.usersCommand.getMyInfo()
290 }) 274 })
291 }) 275 })
292 276
293 describe('Creating a user', function () { 277 describe('Creating a user', function () {
294 278
295 it('Should be able to create a new user', async function () { 279 it('Should be able to create a new user', async function () {
296 await createUser({ 280 await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
297 url: server.url,
298 accessToken: accessToken,
299 username: user.username,
300 password: user.password,
301 videoQuota: 2 * 1024 * 1024,
302 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
303 })
304 }) 281 })
305 282
306 it('Should be able to login with this user', async function () { 283 it('Should be able to login with this user', async function () {
@@ -308,11 +285,9 @@ describe('Test users', function () {
308 }) 285 })
309 286
310 it('Should be able to get user information', async function () { 287 it('Should be able to get user information', async function () {
311 const res1 = await getMyUserInformation(server.url, accessTokenUser) 288 const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser })
312 const userMe: MyUser = res1.body
313 289
314 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) 290 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
315 const userGet: User = res2.body
316 291
317 for (const user of [ userMe, userGet ]) { 292 for (const user of [ userMe, userGet ]) {
318 expect(user.username).to.equal('user_1') 293 expect(user.username).to.equal('user_1')
@@ -356,15 +331,11 @@ describe('Test users', function () {
356 }) 331 })
357 332
358 it('Should have video quota updated', async function () { 333 it('Should have video quota updated', async function () {
359 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) 334 const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
360 const data = res.body 335 expect(quota.videoQuotaUsed).to.equal(218910)
361
362 expect(data.videoQuotaUsed).to.equal(218910)
363
364 const resUsers = await getUsersList(server.url, server.accessToken)
365 336
366 const users: User[] = resUsers.body.data 337 const { data } = await server.usersCommand.list()
367 const tmpUser = users.find(u => u.username === user.username) 338 const tmpUser = data.find(u => u.username === user.username)
368 expect(tmpUser.videoQuotaUsed).to.equal(218910) 339 expect(tmpUser.videoQuotaUsed).to.equal(218910)
369 }) 340 })
370 341
@@ -421,9 +392,7 @@ describe('Test users', function () {
421 } 392 }
422 393
423 { 394 {
424 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) 395 const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
425 const data = res.body
426
427 expect(data.videoQuotaUsed).to.be.greaterThan(220000) 396 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
428 } 397 }
429 }) 398 })
@@ -432,21 +401,18 @@ describe('Test users', function () {
432 describe('Users listing', function () { 401 describe('Users listing', function () {
433 402
434 it('Should list all the users', async function () { 403 it('Should list all the users', async function () {
435 const res = await getUsersList(server.url, server.accessToken) 404 const { data, total } = await server.usersCommand.list()
436 const result = res.body
437 const total = result.total
438 const users = result.data
439 405
440 expect(total).to.equal(2) 406 expect(total).to.equal(2)
441 expect(users).to.be.an('array') 407 expect(data).to.be.an('array')
442 expect(users.length).to.equal(2) 408 expect(data.length).to.equal(2)
443 409
444 const user = users[0] 410 const user = data[0]
445 expect(user.username).to.equal('user_1') 411 expect(user.username).to.equal('user_1')
446 expect(user.email).to.equal('user_1@example.com') 412 expect(user.email).to.equal('user_1@example.com')
447 expect(user.nsfwPolicy).to.equal('display') 413 expect(user.nsfwPolicy).to.equal('display')
448 414
449 const rootUser = users[1] 415 const rootUser = data[1]
450 expect(rootUser.username).to.equal('root') 416 expect(rootUser.username).to.equal('root')
451 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') 417 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
452 expect(user.nsfwPolicy).to.equal('display') 418 expect(user.nsfwPolicy).to.equal('display')
@@ -458,16 +424,12 @@ describe('Test users', function () {
458 }) 424 })
459 425
460 it('Should list only the first user by username asc', async function () { 426 it('Should list only the first user by username asc', async function () {
461 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') 427 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' })
462
463 const result = res.body
464 const total = result.total
465 const users = result.data
466 428
467 expect(total).to.equal(2) 429 expect(total).to.equal(2)
468 expect(users.length).to.equal(1) 430 expect(data.length).to.equal(1)
469 431
470 const user = users[0] 432 const user = data[0]
471 expect(user.username).to.equal('root') 433 expect(user.username).to.equal('root')
472 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') 434 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
473 expect(user.roleLabel).to.equal('Administrator') 435 expect(user.roleLabel).to.equal('Administrator')
@@ -475,84 +437,66 @@ describe('Test users', function () {
475 }) 437 })
476 438
477 it('Should list only the first user by username desc', async function () { 439 it('Should list only the first user by username desc', async function () {
478 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') 440 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' })
479 const result = res.body
480 const total = result.total
481 const users = result.data
482 441
483 expect(total).to.equal(2) 442 expect(total).to.equal(2)
484 expect(users.length).to.equal(1) 443 expect(data.length).to.equal(1)
485 444
486 const user = users[0] 445 const user = data[0]
487 expect(user.username).to.equal('user_1') 446 expect(user.username).to.equal('user_1')
488 expect(user.email).to.equal('user_1@example.com') 447 expect(user.email).to.equal('user_1@example.com')
489 expect(user.nsfwPolicy).to.equal('display') 448 expect(user.nsfwPolicy).to.equal('display')
490 }) 449 })
491 450
492 it('Should list only the second user by createdAt desc', async function () { 451 it('Should list only the second user by createdAt desc', async function () {
493 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') 452 const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' })
494 const result = res.body
495 const total = result.total
496 const users = result.data
497
498 expect(total).to.equal(2) 453 expect(total).to.equal(2)
499 expect(users.length).to.equal(1)
500 454
501 const user = users[0] 455 expect(data.length).to.equal(1)
456
457 const user = data[0]
502 expect(user.username).to.equal('user_1') 458 expect(user.username).to.equal('user_1')
503 expect(user.email).to.equal('user_1@example.com') 459 expect(user.email).to.equal('user_1@example.com')
504 expect(user.nsfwPolicy).to.equal('display') 460 expect(user.nsfwPolicy).to.equal('display')
505 }) 461 })
506 462
507 it('Should list all the users by createdAt asc', async function () { 463 it('Should list all the users by createdAt asc', async function () {
508 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') 464 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' })
509 const result = res.body
510 const total = result.total
511 const users = result.data
512 465
513 expect(total).to.equal(2) 466 expect(total).to.equal(2)
514 expect(users.length).to.equal(2) 467 expect(data.length).to.equal(2)
515 468
516 expect(users[0].username).to.equal('root') 469 expect(data[0].username).to.equal('root')
517 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') 470 expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
518 expect(users[0].nsfwPolicy).to.equal('display') 471 expect(data[0].nsfwPolicy).to.equal('display')
519 472
520 expect(users[1].username).to.equal('user_1') 473 expect(data[1].username).to.equal('user_1')
521 expect(users[1].email).to.equal('user_1@example.com') 474 expect(data[1].email).to.equal('user_1@example.com')
522 expect(users[1].nsfwPolicy).to.equal('display') 475 expect(data[1].nsfwPolicy).to.equal('display')
523 }) 476 })
524 477
525 it('Should search user by username', async function () { 478 it('Should search user by username', async function () {
526 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') 479 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
527 const users = res.body.data as User[] 480 expect(total).to.equal(1)
528 481 expect(data.length).to.equal(1)
529 expect(res.body.total).to.equal(1) 482 expect(data[0].username).to.equal('root')
530 expect(users.length).to.equal(1)
531
532 expect(users[0].username).to.equal('root')
533 }) 483 })
534 484
535 it('Should search user by email', async function () { 485 it('Should search user by email', async function () {
536 { 486 {
537 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') 487 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
538 const users = res.body.data as User[] 488 expect(total).to.equal(1)
539 489 expect(data.length).to.equal(1)
540 expect(res.body.total).to.equal(1) 490 expect(data[0].username).to.equal('user_1')
541 expect(users.length).to.equal(1) 491 expect(data[0].email).to.equal('user_1@example.com')
542
543 expect(users[0].username).to.equal('user_1')
544 expect(users[0].email).to.equal('user_1@example.com')
545 } 492 }
546 493
547 { 494 {
548 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') 495 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
549 const users = res.body.data as User[] 496 expect(total).to.equal(2)
550 497 expect(data.length).to.equal(2)
551 expect(res.body.total).to.equal(2) 498 expect(data[0].username).to.equal('root')
552 expect(users.length).to.equal(2) 499 expect(data[1].username).to.equal('user_1')
553
554 expect(users[0].username).to.equal('root')
555 expect(users[1].username).to.equal('user_1')
556 } 500 }
557 }) 501 })
558 }) 502 })
@@ -560,9 +504,8 @@ describe('Test users', function () {
560 describe('Update my account', function () { 504 describe('Update my account', function () {
561 505
562 it('Should update my password', async function () { 506 it('Should update my password', async function () {
563 await updateMyUser({ 507 await server.usersCommand.updateMe({
564 url: server.url, 508 token: accessTokenUser,
565 accessToken: accessTokenUser,
566 currentPassword: 'super password', 509 currentPassword: 'super password',
567 password: 'new password' 510 password: 'new password'
568 }) 511 })
@@ -572,15 +515,12 @@ describe('Test users', function () {
572 }) 515 })
573 516
574 it('Should be able to change the NSFW display attribute', async function () { 517 it('Should be able to change the NSFW display attribute', async function () {
575 await updateMyUser({ 518 await server.usersCommand.updateMe({
576 url: server.url, 519 token: accessTokenUser,
577 accessToken: accessTokenUser,
578 nsfwPolicy: 'do_not_list' 520 nsfwPolicy: 'do_not_list'
579 }) 521 })
580 522
581 const res = await getMyUserInformation(server.url, accessTokenUser) 523 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
582 const user = res.body
583
584 expect(user.username).to.equal('user_1') 524 expect(user.username).to.equal('user_1')
585 expect(user.email).to.equal('user_1@example.com') 525 expect(user.email).to.equal('user_1@example.com')
586 expect(user.nsfwPolicy).to.equal('do_not_list') 526 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -591,42 +531,33 @@ describe('Test users', function () {
591 }) 531 })
592 532
593 it('Should be able to change the autoPlayVideo attribute', async function () { 533 it('Should be able to change the autoPlayVideo attribute', async function () {
594 await updateMyUser({ 534 await server.usersCommand.updateMe({
595 url: server.url, 535 token: accessTokenUser,
596 accessToken: accessTokenUser,
597 autoPlayVideo: false 536 autoPlayVideo: false
598 }) 537 })
599 538
600 const res = await getMyUserInformation(server.url, accessTokenUser) 539 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
601 const user = res.body
602
603 expect(user.autoPlayVideo).to.be.false 540 expect(user.autoPlayVideo).to.be.false
604 }) 541 })
605 542
606 it('Should be able to change the autoPlayNextVideo attribute', async function () { 543 it('Should be able to change the autoPlayNextVideo attribute', async function () {
607 await updateMyUser({ 544 await server.usersCommand.updateMe({
608 url: server.url, 545 token: accessTokenUser,
609 accessToken: accessTokenUser,
610 autoPlayNextVideo: true 546 autoPlayNextVideo: true
611 }) 547 })
612 548
613 const res = await getMyUserInformation(server.url, accessTokenUser) 549 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
614 const user = res.body
615
616 expect(user.autoPlayNextVideo).to.be.true 550 expect(user.autoPlayNextVideo).to.be.true
617 }) 551 })
618 552
619 it('Should be able to change the email attribute', async function () { 553 it('Should be able to change the email attribute', async function () {
620 await updateMyUser({ 554 await server.usersCommand.updateMe({
621 url: server.url, 555 token: accessTokenUser,
622 accessToken: accessTokenUser,
623 currentPassword: 'new password', 556 currentPassword: 'new password',
624 email: 'updated@example.com' 557 email: 'updated@example.com'
625 }) 558 })
626 559
627 const res = await getMyUserInformation(server.url, accessTokenUser) 560 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
628 const user = res.body
629
630 expect(user.username).to.equal('user_1') 561 expect(user.username).to.equal('user_1')
631 expect(user.email).to.equal('updated@example.com') 562 expect(user.email).to.equal('updated@example.com')
632 expect(user.nsfwPolicy).to.equal('do_not_list') 563 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -639,15 +570,9 @@ describe('Test users', function () {
639 it('Should be able to update my avatar with a gif', async function () { 570 it('Should be able to update my avatar with a gif', async function () {
640 const fixture = 'avatar.gif' 571 const fixture = 'avatar.gif'
641 572
642 await updateMyAvatar({ 573 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
643 url: server.url,
644 accessToken: accessTokenUser,
645 fixture
646 })
647
648 const res = await getMyUserInformation(server.url, accessTokenUser)
649 const user = res.body
650 574
575 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
651 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') 576 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
652 }) 577 })
653 578
@@ -655,29 +580,17 @@ describe('Test users', function () {
655 for (const extension of [ '.png', '.gif' ]) { 580 for (const extension of [ '.png', '.gif' ]) {
656 const fixture = 'avatar' + extension 581 const fixture = 'avatar' + extension
657 582
658 await updateMyAvatar({ 583 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
659 url: server.url,
660 accessToken: accessTokenUser,
661 fixture
662 })
663
664 const res = await getMyUserInformation(server.url, accessTokenUser)
665 const user = res.body
666 584
585 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
667 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) 586 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
668 } 587 }
669 }) 588 })
670 589
671 it('Should be able to update my display name', async function () { 590 it('Should be able to update my display name', async function () {
672 await updateMyUser({ 591 await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' })
673 url: server.url,
674 accessToken: accessTokenUser,
675 displayName: 'new display name'
676 })
677
678 const res = await getMyUserInformation(server.url, accessTokenUser)
679 const user = res.body
680 592
593 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
681 expect(user.username).to.equal('user_1') 594 expect(user.username).to.equal('user_1')
682 expect(user.email).to.equal('updated@example.com') 595 expect(user.email).to.equal('updated@example.com')
683 expect(user.nsfwPolicy).to.equal('do_not_list') 596 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -688,15 +601,9 @@ describe('Test users', function () {
688 }) 601 })
689 602
690 it('Should be able to update my description', async function () { 603 it('Should be able to update my description', async function () {
691 await updateMyUser({ 604 await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' })
692 url: server.url,
693 accessToken: accessTokenUser,
694 description: 'my super description updated'
695 })
696
697 const res = await getMyUserInformation(server.url, accessTokenUser)
698 const user: User = res.body
699 605
606 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
700 expect(user.username).to.equal('user_1') 607 expect(user.username).to.equal('user_1')
701 expect(user.email).to.equal('updated@example.com') 608 expect(user.email).to.equal('updated@example.com')
702 expect(user.nsfwPolicy).to.equal('do_not_list') 609 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -710,30 +617,21 @@ describe('Test users', function () {
710 617
711 it('Should be able to update my theme', async function () { 618 it('Should be able to update my theme', async function () {
712 for (const theme of [ 'background-red', 'default', 'instance-default' ]) { 619 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
713 await updateMyUser({ 620 await server.usersCommand.updateMe({ token: accessTokenUser, theme })
714 url: server.url,
715 accessToken: accessTokenUser,
716 theme
717 })
718 621
719 const res = await getMyUserInformation(server.url, accessTokenUser) 622 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
720 const body: User = res.body 623 expect(user.theme).to.equal(theme)
721
722 expect(body.theme).to.equal(theme)
723 } 624 }
724 }) 625 })
725 626
726 it('Should be able to update my modal preferences', async function () { 627 it('Should be able to update my modal preferences', async function () {
727 await updateMyUser({ 628 await server.usersCommand.updateMe({
728 url: server.url, 629 token: accessTokenUser,
729 accessToken: accessTokenUser,
730 noInstanceConfigWarningModal: true, 630 noInstanceConfigWarningModal: true,
731 noWelcomeModal: true 631 noWelcomeModal: true
732 }) 632 })
733 633
734 const res = await getMyUserInformation(server.url, accessTokenUser) 634 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
735 const user: User = res.body
736
737 expect(user.noWelcomeModal).to.be.true 635 expect(user.noWelcomeModal).to.be.true
738 expect(user.noInstanceConfigWarningModal).to.be.true 636 expect(user.noInstanceConfigWarningModal).to.be.true
739 }) 637 })
@@ -741,10 +639,9 @@ describe('Test users', function () {
741 639
742 describe('Updating another user', function () { 640 describe('Updating another user', function () {
743 it('Should be able to update another user', async function () { 641 it('Should be able to update another user', async function () {
744 await updateUser({ 642 await server.usersCommand.update({
745 url: server.url,
746 userId, 643 userId,
747 accessToken, 644 token: accessToken,
748 email: 'updated2@example.com', 645 email: 'updated2@example.com',
749 emailVerified: true, 646 emailVerified: true,
750 videoQuota: 42, 647 videoQuota: 42,
@@ -753,8 +650,7 @@ describe('Test users', function () {
753 pluginAuth: 'toto' 650 pluginAuth: 'toto'
754 }) 651 })
755 652
756 const res = await getUserInformation(server.url, accessToken, userId) 653 const user = await server.usersCommand.get({ token: accessToken, userId })
757 const user = res.body as User
758 654
759 expect(user.username).to.equal('user_1') 655 expect(user.username).to.equal('user_1')
760 expect(user.email).to.equal('updated2@example.com') 656 expect(user.email).to.equal('updated2@example.com')
@@ -768,28 +664,22 @@ describe('Test users', function () {
768 }) 664 })
769 665
770 it('Should reset the auth plugin', async function () { 666 it('Should reset the auth plugin', async function () {
771 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) 667 await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null })
772 668
773 const res = await getUserInformation(server.url, accessToken, userId) 669 const user = await server.usersCommand.get({ token: accessToken, userId })
774 const user = res.body as User
775 expect(user.pluginAuth).to.be.null 670 expect(user.pluginAuth).to.be.null
776 }) 671 })
777 672
778 it('Should have removed the user token', async function () { 673 it('Should have removed the user token', async function () {
779 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 674 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
780 675
781 accessTokenUser = await server.loginCommand.getAccessToken(user) 676 accessTokenUser = await server.loginCommand.getAccessToken(user)
782 }) 677 })
783 678
784 it('Should be able to update another user password', async function () { 679 it('Should be able to update another user password', async function () {
785 await updateUser({ 680 await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' })
786 url: server.url,
787 userId,
788 accessToken,
789 password: 'password updated'
790 })
791 681
792 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 682 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
793 683
794 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 684 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
795 685
@@ -806,7 +696,7 @@ describe('Test users', function () {
806 696
807 describe('Remove a user', function () { 697 describe('Remove a user', function () {
808 it('Should be able to remove this user', async function () { 698 it('Should be able to remove this user', async function () {
809 await removeUser(server.url, userId, accessToken) 699 await server.usersCommand.remove({ userId, token: accessToken })
810 }) 700 })
811 701
812 it('Should not be able to login with this user', async function () { 702 it('Should not be able to login with this user', async function () {
@@ -830,7 +720,7 @@ describe('Test users', function () {
830 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } 720 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
831 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } 721 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
832 722
833 await registerUserWithChannel({ url: server.url, user, channel }) 723 await server.usersCommand.register({ ...user, channel })
834 }) 724 })
835 725
836 it('Should be able to login with this registered user', async function () { 726 it('Should be able to login with this registered user', async function () {
@@ -843,16 +733,12 @@ describe('Test users', function () {
843 }) 733 })
844 734
845 it('Should have the correct display name', async function () { 735 it('Should have the correct display name', async function () {
846 const res = await getMyUserInformation(server.url, user15AccessToken) 736 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
847 const user: User = res.body
848
849 expect(user.account.displayName).to.equal('super user 15') 737 expect(user.account.displayName).to.equal('super user 15')
850 }) 738 })
851 739
852 it('Should have the correct video quota', async function () { 740 it('Should have the correct video quota', async function () {
853 const res = await getMyUserInformation(server.url, user15AccessToken) 741 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
854 const user = res.body
855
856 expect(user.videoQuota).to.equal(5 * 1024 * 1024) 742 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
857 }) 743 })
858 744
@@ -864,15 +750,15 @@ describe('Test users', function () {
864 750
865 it('Should remove me', async function () { 751 it('Should remove me', async function () {
866 { 752 {
867 const res = await getUsersList(server.url, server.accessToken) 753 const { data } = await server.usersCommand.list()
868 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined 754 expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
869 } 755 }
870 756
871 await deleteMe(server.url, user15AccessToken) 757 await server.usersCommand.deleteMe({ token: user15AccessToken })
872 758
873 { 759 {
874 const res = await getUsersList(server.url, server.accessToken) 760 const { data } = await server.usersCommand.list()
875 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined 761 expect(data.find(u => u.username === 'user_15')).to.be.undefined
876 } 762 }
877 }) 763 })
878 }) 764 })
@@ -886,49 +772,40 @@ describe('Test users', function () {
886 } 772 }
887 773
888 it('Should block a user', async function () { 774 it('Should block a user', async function () {
889 const resUser = await createUser({ 775 const user = await server.usersCommand.create({ ...user16 })
890 url: server.url, 776 user16Id = user.id
891 accessToken: server.accessToken,
892 username: user16.username,
893 password: user16.password
894 })
895 user16Id = resUser.body.user.id
896 777
897 user16AccessToken = await server.loginCommand.getAccessToken(user16) 778 user16AccessToken = await server.loginCommand.getAccessToken(user16)
898 779
899 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 780 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
900 await blockUser(server.url, user16Id, server.accessToken) 781 await server.usersCommand.banUser({ userId: user16Id })
901 782
902 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) 783 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
903 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 784 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
904 }) 785 })
905 786
906 it('Should search user by banned status', async function () { 787 it('Should search user by banned status', async function () {
907 { 788 {
908 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) 789 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
909 const users = res.body.data as User[] 790 expect(total).to.equal(1)
791 expect(data.length).to.equal(1)
910 792
911 expect(res.body.total).to.equal(1) 793 expect(data[0].username).to.equal(user16.username)
912 expect(users.length).to.equal(1)
913
914 expect(users[0].username).to.equal(user16.username)
915 } 794 }
916 795
917 { 796 {
918 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) 797 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
919 const users = res.body.data as User[] 798 expect(total).to.equal(1)
920 799 expect(data.length).to.equal(1)
921 expect(res.body.total).to.equal(1)
922 expect(users.length).to.equal(1)
923 800
924 expect(users[0].username).to.not.equal(user16.username) 801 expect(data[0].username).to.not.equal(user16.username)
925 } 802 }
926 }) 803 })
927 804
928 it('Should unblock a user', async function () { 805 it('Should unblock a user', async function () {
929 await unblockUser(server.url, user16Id, server.accessToken) 806 await server.usersCommand.unbanUser({ userId: user16Id })
930 user16AccessToken = await server.loginCommand.getAccessToken(user16) 807 user16AccessToken = await server.loginCommand.getAccessToken(user16)
931 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 808 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
932 }) 809 })
933 }) 810 })
934 811
@@ -941,19 +818,12 @@ describe('Test users', function () {
941 username: 'user_17', 818 username: 'user_17',
942 password: 'my super password' 819 password: 'my super password'
943 } 820 }
944 const resUser = await createUser({ 821 const created = await server.usersCommand.create({ ...user17 })
945 url: server.url,
946 accessToken: server.accessToken,
947 username: user17.username,
948 password: user17.password
949 })
950 822
951 user17Id = resUser.body.user.id 823 user17Id = created.id
952 user17AccessToken = await server.loginCommand.getAccessToken(user17) 824 user17AccessToken = await server.loginCommand.getAccessToken(user17)
953 825
954 const res = await getUserInformation(server.url, server.accessToken, user17Id, true) 826 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
955 const user: User = res.body
956
957 expect(user.videosCount).to.equal(0) 827 expect(user.videosCount).to.equal(0)
958 expect(user.videoCommentsCount).to.equal(0) 828 expect(user.videoCommentsCount).to.equal(0)
959 expect(user.abusesCount).to.equal(0) 829 expect(user.abusesCount).to.equal(0)
@@ -969,9 +839,7 @@ describe('Test users', function () {
969 const res1 = await getVideosList(server.url) 839 const res1 = await getVideosList(server.url)
970 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id 840 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
971 841
972 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 842 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
973 const user: User = res2.body
974
975 expect(user.videosCount).to.equal(1) 843 expect(user.videosCount).to.equal(1)
976 }) 844 })
977 845
@@ -979,9 +847,7 @@ describe('Test users', function () {
979 const text = 'super comment' 847 const text = 'super comment'
980 await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) 848 await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text })
981 849
982 const res = await getUserInformation(server.url, server.accessToken, user17Id, true) 850 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
983 const user: User = res.body
984
985 expect(user.videoCommentsCount).to.equal(1) 851 expect(user.videoCommentsCount).to.equal(1)
986 }) 852 })
987 853
@@ -992,17 +858,13 @@ describe('Test users', function () {
992 const body1 = await server.abusesCommand.getAdminList() 858 const body1 = await server.abusesCommand.getAdminList()
993 const abuseId = body1.data[0].id 859 const abuseId = body1.data[0].id
994 860
995 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 861 const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true })
996 const user2: User = res2.body
997
998 expect(user2.abusesCount).to.equal(1) // number of incriminations 862 expect(user2.abusesCount).to.equal(1) // number of incriminations
999 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created 863 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1000 864
1001 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) 865 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1002 866
1003 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) 867 const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true })
1004 const user3: User = res3.body
1005
1006 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted 868 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1007 }) 869 })
1008 }) 870 })
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 740314bfd..169bb2e23 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -10,7 +10,6 @@ import {
10 checkVideoFilesWereRemoved, 10 checkVideoFilesWereRemoved,
11 cleanupTests, 11 cleanupTests,
12 completeVideoCheck, 12 completeVideoCheck,
13 createUser,
14 dateIsValid, 13 dateIsValid,
15 doubleFollow, 14 doubleFollow,
16 flushAndRunMultipleServers, 15 flushAndRunMultipleServers,
@@ -153,7 +152,7 @@ describe('Test multiple servers', function () {
153 username: 'user1', 152 username: 'user1',
154 password: 'super_password' 153 password: 'super_password'
155 } 154 }
156 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 155 await servers[1].usersCommand.create({ username: user.username, password: user.password })
157 const userAccessToken = await servers[1].loginCommand.getAccessToken(user) 156 const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
158 157
159 const videoAttributes = { 158 const videoAttributes = {
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 5845efc86..642c115d0 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -9,15 +9,13 @@ import {
9 buildAbsoluteFixturePath, 9 buildAbsoluteFixturePath,
10 cleanupTests, 10 cleanupTests,
11 flushAndRunServer, 11 flushAndRunServer,
12 getMyUserInformation,
13 prepareResumableUpload, 12 prepareResumableUpload,
14 sendResumableChunks, 13 sendResumableChunks,
15 ServerInfo, 14 ServerInfo,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 setDefaultVideoChannel, 16 setDefaultVideoChannel
18 updateUser
19} from '@shared/extra-utils' 17} from '@shared/extra-utils'
20import { MyUser, VideoPrivacy } from '@shared/models' 18import { VideoPrivacy } from '@shared/models'
21 19
22const expect = chai.expect 20const expect = chai.expect
23 21
@@ -109,15 +107,10 @@ describe('Test resumable upload', function () {
109 await setAccessTokensToServers([ server ]) 107 await setAccessTokensToServers([ server ])
110 await setDefaultVideoChannel([ server ]) 108 await setDefaultVideoChannel([ server ])
111 109
112 const res = await getMyUserInformation(server.url, server.accessToken) 110 const body = await server.usersCommand.getMyInfo()
113 rootId = (res.body as MyUser).id 111 rootId = body.id
114 112
115 await updateUser({ 113 await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 })
116 url: server.url,
117 userId: rootId,
118 accessToken: server.accessToken,
119 videoQuota: 10_000_000
120 })
121 }) 114 })
122 115
123 describe('Directory cleaning', function () { 116 describe('Directory cleaning', function () {
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 17c738e6f..b0bbd5a0d 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -6,11 +6,9 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c
6import { 6import {
7 ChangeOwnershipCommand, 7 ChangeOwnershipCommand,
8 cleanupTests, 8 cleanupTests,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 flushAndRunServer, 11 flushAndRunServer,
13 getMyUserInformation,
14 getVideo, 12 getVideo,
15 getVideosList, 13 getVideosList,
16 ServerInfo, 14 ServerInfo,
@@ -19,21 +17,15 @@ import {
19 uploadVideo 17 uploadVideo
20} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
21import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 19import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
22import { User } from '../../../../shared/models/users'
23import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos' 20import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
24 21
25const expect = chai.expect 22const expect = chai.expect
26 23
27describe('Test video change ownership - nominal', function () { 24describe('Test video change ownership - nominal', function () {
28 let servers: ServerInfo[] = [] 25 let servers: ServerInfo[] = []
29 const firstUser = { 26
30 username: 'first', 27 const firstUser = 'first'
31 password: 'My great password' 28 const secondUser = 'second'
32 }
33 const secondUser = {
34 username: 'second',
35 password: 'My other password'
36 }
37 29
38 let firstUserToken = '' 30 let firstUserToken = ''
39 let firstUserChannelId: number 31 let firstUserChannelId: number
@@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () {
65 } 57 }
66 }) 58 })
67 59
68 const videoQuota = 42000000 60 firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser)
69 await createUser({ 61 secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser)
70 url: servers[0].url,
71 accessToken: servers[0].accessToken,
72 username: firstUser.username,
73 password: firstUser.password,
74 videoQuota: videoQuota
75 })
76 await createUser({
77 url: servers[0].url,
78 accessToken: servers[0].accessToken,
79 username: secondUser.username,
80 password: secondUser.password,
81 videoQuota: videoQuota
82 })
83
84 firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser)
85 secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser)
86 62
87 { 63 {
88 const res = await getMyUserInformation(servers[0].url, firstUserToken) 64 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken })
89 const firstUserInformation: User = res.body 65 firstUserChannelId = videoChannels[0].id
90 firstUserChannelId = firstUserInformation.videoChannels[0].id
91 } 66 }
92 67
93 { 68 {
94 const res = await getMyUserInformation(servers[0].url, secondUserToken) 69 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken })
95 const secondUserInformation: User = res.body 70 secondUserChannelId = videoChannels[0].id
96 secondUserChannelId = secondUserInformation.videoChannels[0].id
97 } 71 }
98 72
99 { 73 {
@@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () {
140 it('Should send a request to change ownership of a video', async function () { 114 it('Should send a request to change ownership of a video', async function () {
141 this.timeout(15000) 115 this.timeout(15000)
142 116
143 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) 117 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
144 }) 118 })
145 119
146 it('Should only return a request to change ownership for the second user', async function () { 120 it('Should only return a request to change ownership for the second user', async function () {
@@ -166,7 +140,7 @@ describe('Test video change ownership - nominal', function () {
166 it('Should accept the same change ownership request without crashing', async function () { 140 it('Should accept the same change ownership request without crashing', async function () {
167 this.timeout(10000) 141 this.timeout(10000)
168 142
169 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) 143 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
170 }) 144 })
171 145
172 it('Should not create multiple change ownership requests while one is waiting', async function () { 146 it('Should not create multiple change ownership requests while one is waiting', async function () {
@@ -194,7 +168,7 @@ describe('Test video change ownership - nominal', function () {
194 it('Should send a new request to change ownership of a video', async function () { 168 it('Should send a new request to change ownership of a video', async function () {
195 this.timeout(15000) 169 this.timeout(15000)
196 170
197 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username }) 171 await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
198 }) 172 })
199 173
200 it('Should return two requests to change ownership for the second user', async function () { 174 it('Should return two requests to change ownership for the second user', async function () {
@@ -251,7 +225,7 @@ describe('Test video change ownership - nominal', function () {
251 it('Should send a request to change ownership of a live', async function () { 225 it('Should send a request to change ownership of a live', async function () {
252 this.timeout(15000) 226 this.timeout(15000)
253 227
254 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username }) 228 await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
255 229
256 const body = await command.list({ token: secondUserToken }) 230 const body = await command.list({ token: secondUserToken })
257 231
@@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () {
286 260
287describe('Test video change ownership - quota too small', function () { 261describe('Test video change ownership - quota too small', function () {
288 let server: ServerInfo 262 let server: ServerInfo
289 const firstUser = { 263 const firstUser = 'first'
290 username: 'first', 264 const secondUser = 'second'
291 password: 'My great password' 265
292 }
293 const secondUser = {
294 username: 'second',
295 password: 'My other password'
296 }
297 let firstUserToken = '' 266 let firstUserToken = ''
298 let secondUserToken = '' 267 let secondUserToken = ''
299 let lastRequestId: number 268 let lastRequestId: number
@@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () {
305 server = await flushAndRunServer(1) 274 server = await flushAndRunServer(1)
306 await setAccessTokensToServers([ server ]) 275 await setAccessTokensToServers([ server ])
307 276
308 const videoQuota = 42000000 277 await server.usersCommand.create({ username: secondUser, videoQuota: 10 })
309 const limitedVideoQuota = 10
310 await createUser({
311 url: server.url,
312 accessToken: server.accessToken,
313 username: firstUser.username,
314 password: firstUser.password,
315 videoQuota: videoQuota
316 })
317 await createUser({
318 url: server.url,
319 accessToken: server.accessToken,
320 username: secondUser.username,
321 password: secondUser.password,
322 videoQuota: limitedVideoQuota
323 })
324 278
325 firstUserToken = await server.loginCommand.getAccessToken(firstUser) 279 firstUserToken = await server.usersCommand.generateUserAndToken(firstUser)
326 secondUserToken = await server.loginCommand.getAccessToken(secondUser) 280 secondUserToken = await server.loginCommand.getAccessToken(secondUser)
327 281
328 // Upload some videos on the server 282 // Upload some videos on the server
@@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () {
345 it('Should send a request to change ownership of a video', async function () { 299 it('Should send a request to change ownership of a video', async function () {
346 this.timeout(15000) 300 this.timeout(15000)
347 301
348 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username }) 302 await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser })
349 }) 303 })
350 304
351 it('Should only return a request to change ownership for the second user', async function () { 305 it('Should only return a request to change ownership for the second user', async function () {
@@ -371,9 +325,8 @@ describe('Test video change ownership - quota too small', function () {
371 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { 325 it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
372 this.timeout(10000) 326 this.timeout(10000)
373 327
374 const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken) 328 const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken })
375 const secondUserInformation: User = secondUserInformationResponse.body 329 const channelId = videoChannels[0].id
376 const channelId = secondUserInformation.videoChannels[0].id
377 330
378 await server.changeOwnershipCommand.accept({ 331 await server.changeOwnershipCommand.accept({
379 token: secondUserToken, 332 token: secondUserToken,
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 83645640c..2e57cbbff 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -6,21 +6,22 @@ import { basename } from 'path'
6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' 6import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 getVideo, 11 getVideo,
13 getVideoChannelVideos, 12 getVideoChannelVideos,
13 ServerInfo,
14 setAccessTokensToServers,
14 setDefaultVideoChannel, 15 setDefaultVideoChannel,
15 testFileExistsOrNot, 16 testFileExistsOrNot,
16 testImage, 17 testImage,
17 updateVideo, 18 updateVideo,
18 uploadVideo, 19 uploadVideo,
19 wait 20 viewVideo,
20} from '../../../../shared/extra-utils' 21 wait,
21import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index' 22 waitJobs
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 23} from '@shared/extra-utils'
23import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' 24import { User, Video, VideoChannel, VideoDetails } from '@shared/models'
24 25
25const expect = chai.expect 26const expect = chai.expect
26 27
@@ -85,8 +86,7 @@ describe('Test video channels', function () {
85 }) 86 })
86 87
87 it('Should have two video channels when getting my information', async () => { 88 it('Should have two video channels when getting my information', async () => {
88 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 89 userInfo = await servers[0].usersCommand.getMyInfo()
89 userInfo = res.body
90 90
91 expect(userInfo.videoChannels).to.be.an('array') 91 expect(userInfo.videoChannels).to.be.an('array')
92 expect(userInfo.videoChannels).to.have.lengthOf(2) 92 expect(userInfo.videoChannels).to.have.lengthOf(2)
@@ -389,11 +389,11 @@ describe('Test video channels', function () {
389 } 389 }
390 390
391 { 391 {
392 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) 392 await servers[0].usersCommand.create({ username: 'toto', password: 'password' })
393 const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' }) 393 const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' })
394 394
395 const res = await getMyUserInformation(servers[0].url, accessToken) 395 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken })
396 const videoChannel = res.body.videoChannels[0] 396 const videoChannel = videoChannels[0]
397 expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) 397 expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
398 } 398 }
399 }) 399 })
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index f9bd23646..266824d58 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -5,13 +5,11 @@ import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 CommentsCommand, 7 CommentsCommand,
8 createUser,
9 dateIsValid, 8 dateIsValid,
10 flushAndRunServer, 9 flushAndRunServer,
11 ServerInfo, 10 ServerInfo,
12 setAccessTokensToServers, 11 setAccessTokensToServers,
13 testImage, 12 testImage,
14 updateMyAvatar,
15 uploadVideo 13 uploadVideo
16} from '@shared/extra-utils' 14} from '@shared/extra-utils'
17 15
@@ -39,19 +37,9 @@ describe('Test video comments', function () {
39 videoUUID = res.body.video.uuid 37 videoUUID = res.body.video.uuid
40 videoId = res.body.video.id 38 videoId = res.body.video.id
41 39
42 await updateMyAvatar({ 40 await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
43 url: server.url,
44 accessToken: server.accessToken,
45 fixture: 'avatar.png'
46 })
47 41
48 await createUser({ 42 userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1')
49 url: server.url,
50 accessToken: server.accessToken,
51 username: 'user1',
52 password: 'password'
53 })
54 userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password')
55 43
56 command = server.commentsCommand 44 command = server.commentsCommand
57 }) 45 })
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index f6ae8cab1..052c052b4 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -7,7 +7,6 @@ import {
7 cleanupTests, 7 cleanupTests,
8 doubleFollow, 8 doubleFollow,
9 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
10 getMyUserInformation,
11 getMyVideos, 10 getMyVideos,
12 getVideo, 11 getVideo,
13 getVideosList, 12 getVideosList,
@@ -97,13 +96,13 @@ describe('Test video imports', function () {
97 await setAccessTokensToServers(servers) 96 await setAccessTokensToServers(servers)
98 97
99 { 98 {
100 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 99 const { videoChannels } = await servers[0].usersCommand.getMyInfo()
101 channelIdServer1 = res.body.videoChannels[0].id 100 channelIdServer1 = videoChannels[0].id
102 } 101 }
103 102
104 { 103 {
105 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken) 104 const { videoChannels } = await servers[1].usersCommand.getMyInfo()
106 channelIdServer2 = res.body.videoChannels[0].id 105 channelIdServer2 = videoChannels[0].id
107 } 106 }
108 107
109 await doubleFollow(servers[0], servers[1]) 108 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index a30b11ace..9dc26fca6 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -4,20 +4,17 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 createUser,
8 flushAndRunServer, 7 flushAndRunServer,
9 getAccountVideos, 8 getAccountVideos,
10 getMyUserInformation,
11 getMyVideos, 9 getMyVideos,
12 getVideoChannelVideos, 10 getVideoChannelVideos,
13 getVideosList, 11 getVideosList,
14 getVideosListWithToken, 12 getVideosListWithToken,
15 ServerInfo, 13 ServerInfo,
16 setAccessTokensToServers, 14 setAccessTokensToServers,
17 updateMyUser,
18 uploadVideo 15 uploadVideo
19} from '@shared/extra-utils' 16} from '@shared/extra-utils'
20import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models' 17import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
21 18
22const expect = chai.expect 19const expect = chai.expect
23 20
@@ -32,8 +29,7 @@ describe('Test video NSFW policy', function () {
32 let customConfig: CustomConfig 29 let customConfig: CustomConfig
33 30
34 async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { 31 async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
35 const res = await getMyUserInformation(server.url, server.accessToken) 32 const user = await server.usersCommand.getMyInfo()
36 const user: User = res.body
37 const videoChannelName = user.videoChannels[0].name 33 const videoChannelName = user.videoChannels[0].name
38 const accountName = user.account.name + '@' + user.account.host 34 const accountName = user.account.name + '@' + user.account.host
39 const hasQuery = Object.keys(query).length !== 0 35 const hasQuery = Object.keys(query).length !== 0
@@ -148,13 +144,11 @@ describe('Test video NSFW policy', function () {
148 it('Should create a user having the default nsfw policy', async function () { 144 it('Should create a user having the default nsfw policy', async function () {
149 const username = 'user1' 145 const username = 'user1'
150 const password = 'my super password' 146 const password = 'my super password'
151 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 147 await server.usersCommand.create({ username: username, password: password })
152 148
153 userAccessToken = await server.loginCommand.getAccessToken({ username, password }) 149 userAccessToken = await server.loginCommand.getAccessToken({ username, password })
154 150
155 const res = await getMyUserInformation(server.url, userAccessToken) 151 const user = await server.usersCommand.getMyInfo({ token: userAccessToken })
156 const user = res.body
157
158 expect(user.nsfwPolicy).to.equal('blur') 152 expect(user.nsfwPolicy).to.equal('blur')
159 }) 153 })
160 154
@@ -173,11 +167,7 @@ describe('Test video NSFW policy', function () {
173 }) 167 })
174 168
175 it('Should display NSFW videos with display user NSFW policy', async function () { 169 it('Should display NSFW videos with display user NSFW policy', async function () {
176 await updateMyUser({ 170 await server.usersCommand.updateMe({ nsfwPolicy: 'display' })
177 url: server.url,
178 accessToken: server.accessToken,
179 nsfwPolicy: 'display'
180 })
181 171
182 for (const body of await getVideosFunctions(server.accessToken)) { 172 for (const body of await getVideosFunctions(server.accessToken)) {
183 expect(body.total).to.equal(2) 173 expect(body.total).to.equal(2)
@@ -190,11 +180,7 @@ describe('Test video NSFW policy', function () {
190 }) 180 })
191 181
192 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { 182 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
193 await updateMyUser({ 183 await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' })
194 url: server.url,
195 accessToken: server.accessToken,
196 nsfwPolicy: 'do_not_list'
197 })
198 184
199 for (const body of await getVideosFunctions(server.accessToken)) { 185 for (const body of await getVideosFunctions(server.accessToken)) {
200 expect(body.total).to.equal(1) 186 expect(body.total).to.equal(1)
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index 38133e2ce..e57d86c14 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -6,13 +6,9 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 checkPlaylistFilesWereRemoved, 7 checkPlaylistFilesWereRemoved,
8 cleanupTests, 8 cleanupTests,
9 createUser,
10 doubleFollow, 9 doubleFollow,
11 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
12 generateUserAccessToken,
13 getMyUserInformation,
14 PlaylistsCommand, 11 PlaylistsCommand,
15 removeUser,
16 ServerInfo, 12 ServerInfo,
17 setAccessTokensToServers, 13 setAccessTokensToServers,
18 setDefaultVideoChannel, 14 setDefaultVideoChannel,
@@ -24,7 +20,6 @@ import {
24 waitJobs 20 waitJobs
25} from '@shared/extra-utils' 21} from '@shared/extra-utils'
26import { 22import {
27 User,
28 VideoPlaylist, 23 VideoPlaylist,
29 VideoPlaylistCreateResult, 24 VideoPlaylistCreateResult,
30 VideoPlaylistElementType, 25 VideoPlaylistElementType,
@@ -113,15 +108,7 @@ describe('Test video playlists', function () {
113 108
114 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id 109 nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id
115 110
116 { 111 userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1')
117 await createUser({
118 url: servers[0].url,
119 accessToken: servers[0].accessToken,
120 username: 'user1',
121 password: 'password'
122 })
123 userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password')
124 }
125 112
126 await waitJobs(servers) 113 await waitJobs(servers)
127 }) 114 })
@@ -165,7 +152,7 @@ describe('Test video playlists', function () {
165 }) 152 })
166 153
167 it('Should get private playlist for a classic user', async function () { 154 it('Should get private playlist for a classic user', async function () {
168 const token = await generateUserAccessToken(servers[0], 'toto') 155 const token = await servers[0].usersCommand.generateUserAndToken('toto')
169 156
170 const body = await commands[0].listByAccount({ token, handle: 'toto' }) 157 const body = await commands[0].listByAccount({ token, handle: 'toto' })
171 158
@@ -1118,19 +1105,10 @@ describe('Test video playlists', function () {
1118 it('Should delete an account and delete its playlists', async function () { 1105 it('Should delete an account and delete its playlists', async function () {
1119 this.timeout(30000) 1106 this.timeout(30000)
1120 1107
1121 const user = { username: 'user_1', password: 'password' } 1108 const { userId, token } = await servers[0].usersCommand.generate('user_1')
1122 const res = await createUser({
1123 url: servers[0].url,
1124 accessToken: servers[0].accessToken,
1125 username: user.username,
1126 password: user.password
1127 })
1128
1129 const userId = res.body.user.id
1130 const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
1131 1109
1132 const resChannel = await getMyUserInformation(servers[0].url, userAccessToken) 1110 const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token })
1133 const userChannel = (resChannel.body as User).videoChannels[0] 1111 const userChannel = videoChannels[0]
1134 1112
1135 await commands[0].create({ 1113 await commands[0].create({
1136 attributes: { 1114 attributes: {
@@ -1152,7 +1130,7 @@ describe('Test video playlists', function () {
1152 } 1130 }
1153 } 1131 }
1154 1132
1155 await removeUser(servers[0].url, userId, servers[0].accessToken) 1133 await servers[0].usersCommand.remove({ userId })
1156 await waitJobs(servers) 1134 await waitJobs(servers)
1157 1135
1158 { 1136 {
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index f831dd8a9..4e349e350 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunServer, 9 flushAndRunServer,
11 getMyVideos, 10 getMyVideos,
@@ -125,7 +124,7 @@ describe('Test video privacy', function () {
125 username: 'hello', 124 username: 'hello',
126 password: 'super password' 125 password: 'super password'
127 } 126 }
128 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 127 await servers[0].usersCommand.create({ username: user.username, password: user.password })
129 128
130 anotherUserToken = await servers[0].loginCommand.getAccessToken(user) 129 anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
131 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) 130 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403)
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 519dad646..4aa00cfc4 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 doubleFollow, 8 doubleFollow,
10 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
11 makeGetRequest, 10 makeGetRequest,
@@ -60,17 +59,7 @@ describe('Test videos filter', function () {
60 59
61 for (const server of servers) { 60 for (const server of servers) {
62 const moderator = { username: 'moderator', password: 'my super password' } 61 const moderator = { username: 'moderator', password: 'my super password' }
63 await createUser( 62 await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
64 {
65 url: server.url,
66 accessToken: server.accessToken,
67 username: moderator.username,
68 password: moderator.password,
69 videoQuota: undefined,
70 videoQuotaDaily: undefined,
71 role: UserRole.MODERATOR
72 }
73 )
74 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator) 63 server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
75 64
76 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber }) 65 await uploadVideo(server.url, server.accessToken, { name: 'public ' + server.serverNumber })
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 256271bd0..aa0623f7d 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 flushAndRunServer, 8 flushAndRunServer,
10 getVideosListWithToken, 9 getVideosListWithToken,
11 getVideoWithToken, 10 getVideoWithToken,
@@ -14,7 +13,6 @@ import {
14 reRunServer, 13 reRunServer,
15 ServerInfo, 14 ServerInfo,
16 setAccessTokensToServers, 15 setAccessTokensToServers,
17 updateMyUser,
18 uploadVideo, 16 uploadVideo,
19 wait 17 wait
20} from '@shared/extra-utils' 18} from '@shared/extra-utils'
@@ -59,7 +57,7 @@ describe('Test videos history', function () {
59 username: 'user_1', 57 username: 'user_1',
60 password: 'super password' 58 password: 'super password'
61 } 59 }
62 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 60 await server.usersCommand.create({ username: user.username, password: user.password })
63 userAccessToken = await server.loginCommand.getAccessToken(user) 61 userAccessToken = await server.loginCommand.getAccessToken(user)
64 }) 62 })
65 63
@@ -174,9 +172,7 @@ describe('Test videos history', function () {
174 }) 172 })
175 173
176 it('Should disable videos history', async function () { 174 it('Should disable videos history', async function () {
177 await updateMyUser({ 175 await server.usersCommand.updateMe({
178 url: server.url,
179 accessToken: server.accessToken,
180 videosHistoryEnabled: false 176 videosHistoryEnabled: false
181 }) 177 })
182 178
@@ -184,9 +180,7 @@ describe('Test videos history', function () {
184 }) 180 })
185 181
186 it('Should re-enable videos history', async function () { 182 it('Should re-enable videos history', async function () {
187 await updateMyUser({ 183 await server.usersCommand.updateMe({
188 url: server.url,
189 accessToken: server.accessToken,
190 videosHistoryEnabled: true 184 videosHistoryEnabled: true
191 }) 185 })
192 186
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index ccbc6f4a4..a2da2eaef 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,15 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils'
6 cleanupTests,
7 flushAndRunServer,
8 generateUserAccessToken,
9 ServerInfo,
10 setAccessTokensToServers,
11 uploadVideo,
12 wait
13} from '@shared/extra-utils'
14import { VideosOverview } from '@shared/models' 6import { VideosOverview } from '@shared/models'
15 7
16const expect = chai.expect 8const expect = chai.expect
@@ -112,7 +104,7 @@ describe('Test a videos overview', function () {
112 }) 104 })
113 105
114 it('Should hide muted accounts', async function () { 106 it('Should hide muted accounts', async function () {
115 const token = await generateUserAccessToken(server, 'choco') 107 const token = await server.usersCommand.generateUserAndToken('choco')
116 108
117 await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host }) 109 await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })
118 110