aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-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
23 files changed, 163 insertions, 241 deletions
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