Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Introduce user command

Chocobozzz7926c5f9b3ff
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index d907b49bf1..b86fc94efd 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -4,7 +4,7 @@ import { tokensRouter } from '@server/controllers/api/users/token'
import { Hooks } from '@server/lib/plugins/hooks'
import { OAuthTokenModel } from '@server/models/oauth/oauth-token'
import { MUser, MUserAccountDefault } from '@server/types/models'
-import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared'
+import { UserCreate, UserCreateResult, UserRight, UserRole, UserUpdate } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { UserRegister } from '../../../../shared/models/users/user-register.model'
@@ -220,7 +220,7 @@ async function createUser (req: express.Request, res: express.Response) {
account: {
id: account.id
}
- }
+ } as UserCreateResult
})
}
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index c1af23016f..162f3ec834 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideosListSort,
@@ -32,7 +31,7 @@ describe('Test ActivityPub fetcher', function () {
const user = { username: 'user1', password: 'password' }
for (const server of servers) {
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
}
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 af919f2f35..5a37dbc40e 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -6,7 +6,6 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- generateUserAccessToken,
getVideo,
killallServers,
reRunServer,
@@ -44,10 +43,10 @@ describe('Test AP refresher', function () {
}
{
- const a1 = await generateUserAccessToken(servers[1], 'user1')
+ const a1 = await servers[1].usersCommand.generateUserAndToken('user1')
await uploadVideo(servers[1].url, a1, { name: 'video4' })
- const a2 = await generateUserAccessToken(servers[1], 'user2')
+ const a2 = await servers[1].usersCommand.generateUserAndToken('user2')
await uploadVideo(servers[1].url, a2, { name: 'video5' })
}
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 14949d3011..4cd10a6fd3 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -8,10 +8,8 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunServer,
- generateUserAccessToken,
getVideoIdFromUUID,
makeGetRequest,
makePostBodyRequest,
@@ -45,10 +43,10 @@ describe('Test abuses API validators', function () {
const username = 'user1'
const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
+ await server.usersCommand.create({ username: username, password: password })
userToken = await server.loginCommand.getAccessToken({ username, password })
- userToken2 = await generateUserAccessToken(server, 'user_2')
+ userToken2 = await server.usersCommand.generateUserAndToken('user_2')
const res = await uploadVideo(server.url, server.accessToken, {})
server.video = res.body.video
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 11a79387f5..18238bb04a 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -4,7 +4,6 @@ import 'mocha'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
makeDeleteRequest,
@@ -34,7 +33,7 @@ describe('Test blocklist API validators', function () {
server = servers[0]
const user = { username: 'user1', password: 'password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 85520b3bd5..3f80c79a8d 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -3,7 +3,6 @@
import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers
@@ -24,7 +23,7 @@ describe('Test bulk API validators', function () {
await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index e93523e4b1..c204d94152 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'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
flushAndRunServer,
makeDeleteRequest,
makeGetRequest,
@@ -206,7 +205,7 @@ describe('Test config API validators', function () {
username: 'user1',
password: 'password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts
index c1dd258aa6..58b0b8600d 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'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
cleanupTests,
- createUser,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers
@@ -26,7 +25,7 @@ describe('Test custom pages validators', function () {
await setAccessTokensToServers([ server ])
const user = { username: 'user1', password: 'password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index dc033a4414..2a7485cf33 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -4,7 +4,6 @@ import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers
@@ -30,7 +29,7 @@ describe('Test debug API validators', function () {
username: 'user1',
password: 'my super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 8cf5b130ed..24e483448b 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -4,7 +4,6 @@ import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
makeDeleteRequest, makeGetRequest,
makePostBodyRequest,
@@ -40,7 +39,7 @@ describe('Test server follows API validators', function () {
password: 'password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index cbe6a28b8c..29439bebfa 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -4,7 +4,6 @@ import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers
@@ -35,7 +34,7 @@ describe('Test jobs API validators', function () {
username: 'user1',
password: 'my super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 045f3a1b16..78863fd501 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -2,14 +2,11 @@
import 'mocha'
import { omit } from 'lodash'
-import { VideoCreateResult, VideoPrivacy } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
buildAbsoluteFixturePath,
cleanupTests,
- createUser,
flushAndRunServer,
- getMyUserInformation,
LiveCommand,
makePostBodyRequest,
makeUploadRequest,
@@ -18,7 +15,8 @@ import {
setAccessTokensToServers,
stopFfmpeg,
uploadVideoAndGetId
-} from '../../../../shared/extra-utils'
+} from '@shared/extra-utils'
+import { VideoCreateResult, VideoPrivacy } from '@shared/models'
describe('Test video lives API validator', function () {
const path = '/api/v1/videos/live'
@@ -51,12 +49,12 @@ describe('Test video lives API validator', function () {
const username = 'user1'
const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
+ await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{
- const res = await getMyUserInformation(server.url, server.accessToken)
- channelId = res.body.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo()
+ channelId = videoChannels[0].id
}
{
@@ -147,11 +145,11 @@ describe('Test video lives API validator', function () {
username: 'fake',
password: 'fake_password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user)
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const customChannelId = res.body.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId }
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 83ecfec932..69eaad69f8 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -4,7 +4,6 @@ import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers
@@ -30,7 +29,7 @@ describe('Test logs API validators', function () {
username: 'user1',
password: 'my super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 130cf68690..08fb2397f3 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -7,7 +7,6 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
flushAndRunServer,
makeGetRequest,
makePostBodyRequest,
@@ -43,7 +42,7 @@ describe('Test server plugins API validators', function () {
password: 'password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
{
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index 2e10e378af..d93022c32b 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -8,7 +8,6 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
@@ -43,7 +42,7 @@ describe('Test server redundancy API validators', function () {
password: 'password'
}
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
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 3dc6cf2b49..d94dec6241 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -3,17 +3,14 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode, randomInt } from '@shared/core-utils'
-import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models'
+import { VideoImportState, VideoPrivacy } from '@shared/models'
import {
cleanupTests,
flushAndRunServer,
- getMyUserInformation,
ImportsCommand,
- registerUser,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- updateUser,
uploadVideo,
waitJobs
} from '../../../../shared/extra-utils'
@@ -31,15 +28,10 @@ describe('Test upload quota', function () {
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
- const res = await getMyUserInformation(server.url, server.accessToken)
- rootId = (res.body as MyUser).id
+ const user = await server.usersCommand.getMyInfo()
+ rootId = user.id
- await updateUser({
- url: server.url,
- userId: rootId,
- accessToken: server.accessToken,
- videoQuota: 42
- })
+ await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
})
describe('When having a video quota', function () {
@@ -48,7 +40,7 @@ describe('Test upload quota', function () {
this.timeout(30000)
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
- await registerUser(server.url, user.username, user.password)
+ await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' }
@@ -63,7 +55,7 @@ describe('Test upload quota', function () {
this.timeout(30000)
const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
- await registerUser(server.url, user.username, user.password)
+ await server.usersCommand.register(user)
const userAccessToken = await server.loginCommand.getAccessToken(user)
const videoAttributes = { fixture: 'video_short2.webm' }
@@ -103,12 +95,7 @@ describe('Test upload quota', function () {
describe('When having a daily video quota', function () {
it('Should fail with a user having too many videos daily', async function () {
- await updateUser({
- url: server.url,
- userId: rootId,
- accessToken: server.accessToken,
- videoQuotaDaily: 42
- })
+ await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
@@ -117,10 +104,8 @@ describe('Test upload quota', function () {
describe('When having an absolute and daily video quota', function () {
it('Should fail if exceeding total quota', async function () {
- await updateUser({
- url: server.url,
+ await server.usersCommand.update({
userId: rootId,
- accessToken: server.accessToken,
videoQuota: 42,
videoQuotaDaily: 1024 * 1024 * 1024
})
@@ -130,10 +115,8 @@ describe('Test upload quota', function () {
})
it('Should fail if exceeding daily quota', async function () {
- await updateUser({
- url: server.url,
+ await server.usersCommand.update({
userId: rootId,
- accessToken: server.accessToken,
videoQuota: 1024 * 1024 * 1024,
videoQuotaDaily: 42
})
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 64e2703b91..8ce201d611 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'
import {
cleanupTests,
- createUser,
flushAndRunServer,
makeDeleteRequest,
makeGetRequest,
@@ -39,7 +38,7 @@ describe('Test user subscriptions API validators', function () {
username: 'user1',
password: 'my super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 54baeebe13..801131918b 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,32 +2,22 @@
import 'mocha'
import { omit } from 'lodash'
-import { User, UserRole, VideoCreateResult } from '../../../../shared'
+import { UserRole, VideoCreateResult } from '../../../../shared'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
- blockUser,
buildAbsoluteFixturePath,
cleanupTests,
- createUser,
- deleteMe,
flushAndRunServer,
- getMyUserInformation,
- getMyUserVideoRating,
- getUserScopedTokens,
- getUsersList,
killallServers,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
makeUploadRequest,
- registerUser,
- removeUser,
- renewUserScopedTokens,
reRunServer,
ServerInfo,
setAccessTokensToServers,
- unblockUser,
- uploadVideo
+ uploadVideo,
+ UsersCommand
} from '../../../../shared/extra-utils'
import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
import {
@@ -45,8 +35,8 @@ describe('Test users API validators', function () {
let video: VideoCreateResult
let server: ServerInfo
let serverWithRegistrationDisabled: ServerInfo
- let userAccessToken = ''
- let moderatorAccessToken = ''
+ let userToken = ''
+ let moderatorToken = ''
let emailPort: number
let overrideConfig: Object
@@ -73,52 +63,20 @@ describe('Test users API validators', function () {
}
{
- const user = {
- username: 'user1',
- password: 'my super password'
- }
-
- const videoQuota = 42000000
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: user.username,
- password: user.password,
- videoQuota: videoQuota
- })
- userAccessToken = await server.loginCommand.getAccessToken(user)
+ const user = { username: 'user1' }
+ await server.usersCommand.create({ ...user })
+ userToken = await server.loginCommand.getAccessToken(user)
}
{
- const moderator = {
- username: 'moderator1',
- password: 'super password'
- }
-
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: moderator.username,
- password: moderator.password,
- role: UserRole.MODERATOR
- })
-
- moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
+ const moderator = { username: 'moderator1' }
+ await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
+ moderatorToken = await server.loginCommand.getAccessToken(moderator)
}
{
- const moderator = {
- username: 'moderator2',
- password: 'super password'
- }
-
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: moderator.username,
- password: moderator.password,
- role: UserRole.MODERATOR
- })
+ const moderator = { username: 'moderator2' }
+ await server.usersCommand.create({ ...moderator, role: UserRole.MODERATOR })
}
{
@@ -127,12 +85,10 @@ describe('Test users API validators', function () {
}
{
- const res = await getUsersList(server.url, server.accessToken)
- const users: User[] = res.body.data
-
- userId = users.find(u => u.username === 'user1').id
- rootId = users.find(u => u.username === 'root').id
- moderatorId = users.find(u => u.username === 'moderator2').id
+ const { data } = await server.usersCommand.list()
+ userId = data.find(u => u.username === 'user1').id
+ rootId = data.find(u => u.username === 'root').id
+ moderatorId = data.find(u => u.username === 'moderator2').id
}
})
@@ -161,7 +117,7 @@ describe('Test users API validators', function () {
await makeGetRequest({
url: server.url,
path,
- token: userAccessToken,
+ token: userToken,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
})
@@ -359,7 +315,7 @@ describe('Test users API validators', function () {
await makePostBodyRequest({
url: server.url,
path,
- token: moderatorAccessToken,
+ token: moderatorToken,
fields,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
@@ -372,7 +328,7 @@ describe('Test users API validators', function () {
await makePostBodyRequest({
url: server.url,
path,
- token: moderatorAccessToken,
+ token: moderatorToken,
fields,
statusCodeExpected: HttpStatusCode.OK_200
})
@@ -389,11 +345,8 @@ describe('Test users API validators', function () {
})
it('Should fail with a non admin user', async function () {
- const user = {
- username: 'user1',
- password: 'my super password'
- }
- userAccessToken = await server.loginCommand.getAccessToken(user)
+ const user = { username: 'user1' }
+ userToken = await server.loginCommand.getAccessToken(user)
const fields = {
username: 'user3',
@@ -401,11 +354,12 @@ describe('Test users API validators', function () {
password: 'my super password',
videoQuota: 42000000
}
- await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
+ await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
})
})
describe('When updating my account', function () {
+
it('Should fail with an invalid email attribute', async function () {
const fields = {
email: 'blabla'
@@ -416,29 +370,29 @@ describe('Test users API validators', function () {
it('Should fail with a too small password', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'bla'
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with a too long password', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'super'.repeat(61)
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail without the current password', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'super'.repeat(61)
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid current password', async function () {
@@ -450,7 +404,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({
url: server.url,
path: path + 'me',
- token: userAccessToken,
+ token: userToken,
fields,
statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
})
@@ -461,7 +415,7 @@ describe('Test users API validators', function () {
nsfwPolicy: 'hello'
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid autoPlayVideo attribute', async function () {
@@ -469,7 +423,7 @@ describe('Test users API validators', function () {
autoPlayVideo: -1
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
@@ -477,7 +431,7 @@ describe('Test users API validators', function () {
autoPlayNextVideo: -1
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
@@ -485,12 +439,12 @@ describe('Test users API validators', function () {
videosHistoryEnabled: -1
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an non authenticated user', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'my super password'
}
@@ -508,7 +462,7 @@ describe('Test users API validators', function () {
description: 'super'.repeat(201)
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid videoLanguages attribute', async function () {
@@ -517,7 +471,7 @@ describe('Test users API validators', function () {
videoLanguages: 'toto'
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}
{
@@ -530,18 +484,18 @@ describe('Test users API validators', function () {
videoLanguages: languages
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
}
})
it('Should fail with an invalid theme', async function () {
const fields = { theme: 'invalid' }
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an unknown theme', async function () {
const fields = { theme: 'peertube-theme-unknown' }
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
@@ -549,7 +503,7 @@ describe('Test users API validators', function () {
noInstanceConfigWarningModal: -1
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should fail with an invalid noWelcomeModal attribute', async function () {
@@ -557,12 +511,12 @@ describe('Test users API validators', function () {
noWelcomeModal: -1
}
- await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
})
it('Should succeed to change password with the correct params', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'my super password',
nsfwPolicy: 'blur',
autoPlayVideo: false,
@@ -575,7 +529,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({
url: server.url,
path: path + 'me',
- token: userAccessToken,
+ token: userToken,
fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
@@ -590,7 +544,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({
url: server.url,
path: path + 'me',
- token: userAccessToken,
+ token: userToken,
fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
@@ -647,28 +601,28 @@ describe('Test users API validators', function () {
describe('When managing my scoped tokens', function () {
it('Should fail to get my scoped tokens with an non authenticated user', async function () {
- await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail to get my scoped tokens with a bad token', async function () {
- await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should succeed to get my scoped tokens', async function () {
- await getUserScopedTokens(server.url, server.accessToken)
+ await server.usersCommand.getMyScopedTokens()
})
it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
- await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail to renew my scoped tokens with a bad token', async function () {
- await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should succeed to renew my scoped tokens', async function () {
- await renewUserScopedTokens(server.url, server.accessToken)
+ await server.usersCommand.renewMyScopedTokens()
})
})
@@ -684,7 +638,7 @@ describe('Test users API validators', function () {
})
it('Should fail with a non admin user', async function () {
- await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
+ await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
})
it('Should succeed with the correct params', async function () {
@@ -728,7 +682,7 @@ describe('Test users API validators', function () {
it('Should fail with a too small password', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'bla'
}
@@ -737,7 +691,7 @@ describe('Test users API validators', function () {
it('Should fail with a too long password', async function () {
const fields = {
- currentPassword: 'my super password',
+ currentPassword: 'password',
password: 'super'.repeat(61)
}
@@ -780,7 +734,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({
url: server.url,
path: path + moderatorId,
- token: moderatorAccessToken,
+ token: moderatorToken,
fields,
statusCodeExpected: HttpStatusCode.FORBIDDEN_403
})
@@ -794,7 +748,7 @@ describe('Test users API validators', function () {
await makePutBodyRequest({
url: server.url,
path: path + userId,
- token: moderatorAccessToken,
+ token: moderatorToken,
fields,
statusCodeExpected: HttpStatusCode.NO_CONTENT_204
})
@@ -820,31 +774,37 @@ describe('Test users API validators', function () {
describe('When getting my information', function () {
it('Should fail with a non authenticated user', async function () {
- await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should success with the correct parameters', async function () {
- await getMyUserInformation(server.url, userAccessToken)
+ await server.usersCommand.getMyInfo({ token: userToken })
})
})
describe('When getting my video rating', function () {
+ let command: UsersCommand
+
+ before(function () {
+ command = server.usersCommand
+ })
+
it('Should fail with a non authenticated user', async function () {
- await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401)
+ await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail with an incorrect video uuid', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
+ await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with an unknown video', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
+ await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
})
it('Should succeed with the correct parameters', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, video.id)
- await getMyUserVideoRating(server.url, server.accessToken, video.uuid)
- await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID)
+ await command.getMyRating({ videoId: video.id })
+ await command.getMyRating({ videoId: video.uuid })
+ await command.getMyRating({ videoId: video.shortUUID })
})
})
@@ -852,15 +812,15 @@ describe('Test users API validators', function () {
const path = '/api/v1/accounts/user1/ratings'
it('Should fail with a bad start pagination', async function () {
- await checkBadStartPagination(server.url, path, userAccessToken)
+ await checkBadStartPagination(server.url, path, userToken)
})
it('Should fail with a bad count pagination', async function () {
- await checkBadCountPagination(server.url, path, userAccessToken)
+ await checkBadCountPagination(server.url, path, userToken)
})
it('Should fail with an incorrect sort', async function () {
- await checkBadSortPagination(server.url, path, userAccessToken)
+ await checkBadSortPagination(server.url, path, userToken)
})
it('Should fail with a unauthenticated user', async function () {
@@ -875,57 +835,70 @@ describe('Test users API validators', function () {
await makeGetRequest({
url: server.url,
path,
- token: userAccessToken,
+ token: userToken,
query: { rating: 'toto ' },
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
})
it('Should succeed with the correct params', async function () {
- await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
+ await makeGetRequest({ url: server.url, path, token: userToken, statusCodeExpected: HttpStatusCode.OK_200 })
})
})
describe('When blocking/unblocking/removing user', function () {
+
it('Should fail with an incorrect id', async function () {
- await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
- await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
- await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
+ const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
+
+ await server.usersCommand.remove(options)
+ await server.usersCommand.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
+ await server.usersCommand.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should fail with the root user', async function () {
- await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
- await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
- await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
+ const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
+
+ await server.usersCommand.remove(options)
+ await server.usersCommand.banUser(options)
+ await server.usersCommand.unbanUser(options)
})
it('Should return 404 with a non existing id', async function () {
- await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
- await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
- await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
+ const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
+
+ await server.usersCommand.remove(options)
+ await server.usersCommand.banUser(options)
+ await server.usersCommand.unbanUser(options)
})
it('Should fail with a non admin user', async function () {
- await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
- await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
- await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
+ const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
+
+ await server.usersCommand.remove(options)
+ await server.usersCommand.banUser(options)
+ await server.usersCommand.unbanUser(options)
})
it('Should fail on a moderator with a moderator', async function () {
- await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
- await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
- await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
+ const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
+
+ await server.usersCommand.remove(options)
+ await server.usersCommand.banUser(options)
+ await server.usersCommand.unbanUser(options)
})
it('Should succeed on a user with a moderator', async function () {
- await blockUser(server.url, userId, moderatorAccessToken)
- await unblockUser(server.url, userId, moderatorAccessToken)
+ const options = { userId, token: moderatorToken }
+
+ await server.usersCommand.banUser(options)
+ await server.usersCommand.unbanUser(options)
})
})
describe('When deleting our account', function () {
it('Should fail with with the root account', async function () {
- await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
+ await server.usersCommand.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
})
@@ -1087,7 +1060,7 @@ describe('Test users API validators', function () {
describe('When registering multiple users on a server with users limit', function () {
it('Should fail when after 3 registrations', async function () {
- await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
+ await server.usersCommand.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
})
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index c33bc196d7..5097f8069b 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -9,7 +9,6 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
@@ -44,14 +43,14 @@ describe('Test video blacklist API validators', function () {
{
const username = 'user1'
const password = 'my super password'
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
+ await servers[0].usersCommand.create({ username: username, password: password })
userAccessToken1 = await servers[0].loginCommand.getAccessToken({ username, password })
}
{
const username = 'user2'
const password = 'my super password'
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
+ await servers[0].usersCommand.create({ username: username, password: password })
userAccessToken2 = await servers[0].loginCommand.getAccessToken({ username, password })
}
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index f2fd61b911..631ef4dac3 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'
import {
buildAbsoluteFixturePath,
cleanupTests,
- createUser,
flushAndRunServer,
makeDeleteRequest,
makeGetRequest,
@@ -42,7 +41,7 @@ describe('Test video captions API validator', function () {
username: 'user1',
password: 'my super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
}
})
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 5361f69172..2b4c17ea11 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -11,7 +11,6 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
flushAndRunServer,
makeGetRequest,
makePostBodyRequest,
@@ -45,7 +44,7 @@ describe('Test video channels API validator', function () {
}
{
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
accessTokenUser = await server.loginCommand.getAccessToken(user)
}
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index c21aebaaea..b7656a1766 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -8,7 +8,6 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
flushAndRunServer,
makeDeleteRequest,
makeGetRequest,
@@ -53,13 +52,13 @@ describe('Test video comments API validator', function () {
{
const user = { username: 'user1', password: 'my super password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
}
{
const user = { username: 'user2', password: 'my super password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken2 = await server.loginCommand.getAccessToken(user)
}
})
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 51260affab..d09e473de0 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -9,9 +9,7 @@ import {
checkBadSortPagination,
checkBadStartPagination,
cleanupTests,
- createUser,
flushAndRunServer,
- getMyUserInformation,
ImportsCommand,
makeGetRequest,
makePostBodyRequest,
@@ -38,12 +36,12 @@ describe('Test video imports API validator', function () {
const username = 'user1'
const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
+ await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{
- const res = await getMyUserInformation(server.url, server.accessToken)
- channelId = res.body.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo()
+ channelId = videoChannels[0].id
}
})
@@ -164,11 +162,11 @@ describe('Test video imports API validator', function () {
username: 'fake',
password: 'fake_password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user)
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const customChannelId = res.body.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId }
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 3799e73b6d..46c09bb11c 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -17,7 +17,6 @@ import {
checkBadStartPagination,
cleanupTests,
flushAndRunServer,
- generateUserAccessToken,
makeGetRequest,
PlaylistsCommand,
ServerInfo,
@@ -49,7 +48,7 @@ describe('Test video playlists API validator', function () {
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
- userAccessToken = await generateUserAccessToken(server, 'user1')
+ userAccessToken = await server.usersCommand.generateUserAndToken('user1')
videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id
command = server.playlistsCommand
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index 095b946569..d7bf081d46 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -3,7 +3,6 @@
import 'mocha'
import {
cleanupTests,
- createUser,
flushAndRunServer,
makeGetRequest,
ServerInfo,
@@ -50,21 +49,12 @@ describe('Test video filters validators', function () {
await setDefaultVideoChannel([ server ])
const user = { username: 'user1', password: 'my super password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
const moderator = { username: 'moderator', password: 'my super password' }
- await createUser(
- {
- url: server.url,
- accessToken: server.accessToken,
- username: moderator.username,
- password: moderator.password,
- videoQuota: undefined,
- videoQuotaDaily: undefined,
- role: UserRole.MODERATOR
- }
- )
+ await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
+
moderatorAccessToken = await server.loginCommand.getAccessToken(moderator)
})
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 8e11232bd9..855b09f39a 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
import {
checkUploadVideoParam,
cleanupTests,
- createUser,
flushAndRunServer,
- getMyUserInformation,
getVideo,
getVideosList,
makeDeleteRequest,
@@ -53,14 +51,14 @@ describe('Test videos API validator', function () {
const username = 'user1'
const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
+ await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password })
{
- const res = await getMyUserInformation(server.url, server.accessToken)
- channelId = res.body.videoChannels[0].id
- channelName = res.body.videoChannels[0].name
- accountName = res.body.account.name + '@' + res.body.account.host
+ const body = await server.usersCommand.getMyInfo()
+ channelId = body.videoChannels[0].id
+ channelName = body.videoChannels[0].name
+ accountName = body.account.name + '@' + body.account.host
}
})
@@ -283,11 +281,11 @@ describe('Test videos API validator', function () {
username: 'fake' + randomInt(0, 1500),
password: 'fake_password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
const accessTokenUser = await server.loginCommand.getAccessToken(user)
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const customChannelId = res.body.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ const customChannelId = videoChannels[0].id
const fields = { ...baseCorrectParams, channelId: customChannelId }
const attaches = baseCorrectAttaches
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts
index 46153f7b1b..290d325d40 100644
--- a/server/tests/api/live/live-constraints.ts
+++ b/server/tests/api/live/live-constraints.ts
@@ -9,12 +9,10 @@ import {
ConfigCommand,
doubleFollow,
flushAndRunMultipleServers,
- generateUser,
getVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- updateUser,
wait,
waitJobs
} from '../../../../shared/extra-utils'
@@ -58,9 +56,7 @@ describe('Test live constraints', function () {
}
function updateQuota (options: { total: number, daily: number }) {
- return updateUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
+ return servers[0].usersCommand.update({
userId,
videoQuota: options.total,
videoQuotaDaily: options.daily
@@ -89,7 +85,7 @@ describe('Test live constraints', function () {
})
{
- const res = await generateUser(servers[0], 'user1')
+ const res = await servers[0].usersCommand.generate('user1')
userId = res.userId
userChannelId = res.userChannelId
userAccessToken = res.token
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index d7462f38f1..a7119263c5 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -5,13 +5,10 @@ import * as chai from 'chai'
import {
AbusesCommand,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
- generateUserAccessToken,
getVideoIdFromUUID,
getVideosList,
- removeUser,
removeVideo,
ServerInfo,
setAccessTokensToServers,
@@ -278,7 +275,7 @@ describe('Test abuses', function () {
// register a second user to have two reporters/reportees
const user = { username: 'user2', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
+ await servers[0].usersCommand.create({ ...user })
const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
// upload a third video via this user
@@ -604,9 +601,9 @@ describe('Test abuses', function () {
before(async function () {
this.timeout(50000)
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
+ await servers[0].usersCommand.create({ username: 'user_1', password: 'donald' })
- const token = await generateUserAccessToken(servers[1], 'user_2')
+ const token = await servers[1].usersCommand.generateUserAndToken('user_2')
await uploadVideo(servers[1].url, token, { name: 'super video' })
await waitJobs(servers)
@@ -708,7 +705,7 @@ describe('Test abuses', function () {
this.timeout(10000)
const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
- await removeUser(servers[1].url, account.userId, servers[1].accessToken)
+ await servers[1].usersCommand.remove({ userId: account.userId })
await waitJobs(servers)
@@ -765,7 +762,7 @@ describe('Test abuses', function () {
let userAccessToken: string
before(async function () {
- userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
+ userAccessToken = await servers[0].usersCommand.generateUserAndToken('user_42')
await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
@@ -836,7 +833,7 @@ describe('Test abuses', function () {
let abuseMessageModerationId: number
before(async function () {
- userToken = await generateUserAccessToken(servers[0], 'user_43')
+ userToken = await servers[0].usersCommand.generateUserAndToken('user_43')
const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
abuseId = body.abuse.id
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts
index 4f2be61984..b44bcb0124 100644
--- a/server/tests/api/moderation/blocklist-notification.ts
+++ b/server/tests/api/moderation/blocklist-notification.ts
@@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
@@ -76,9 +75,7 @@ describe('Test blocklist', function () {
{
const user = { username: 'user1', password: 'password' }
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
+ await servers[0].usersCommand.create({
username: user.username,
password: user.password,
videoQuota: -1,
@@ -91,14 +88,14 @@ describe('Test blocklist', function () {
{
const user = { username: 'user2', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[0].loginCommand.getAccessToken(user)
}
{
const user = { username: 'user3', password: 'password' }
- await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+ await servers[1].usersCommand.create({ username: user.username, password: user.password })
remoteUserToken = await servers[1].loginCommand.getAccessToken(user)
}
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index c38a7dad40..c253b5c11f 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -6,7 +6,6 @@ import {
BlocklistCommand,
cleanupTests,
CommentsCommand,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideosList,
@@ -91,7 +90,7 @@ describe('Test blocklist', function () {
{
const user = { username: 'user1', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
userToken1 = await servers[0].loginCommand.getAccessToken(user)
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@@ -99,14 +98,14 @@ describe('Test blocklist', function () {
{
const user = { username: 'moderator', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
userModeratorToken = await servers[0].loginCommand.getAccessToken(user)
}
{
const user = { username: 'user2', password: 'password' }
- await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+ await servers[1].usersCommand.create({ username: user.username, password: user.password })
userToken2 = await servers[1].loginCommand.getAccessToken(user)
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 b61effc575..ef25cfb8ee 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'
import {
BlacklistCommand,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
- getMyUserInformation,
getMyVideos,
getVideosList,
ImportsCommand,
@@ -21,7 +19,7 @@ import {
uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
+import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
const expect = chai.expect
@@ -356,9 +354,7 @@ describe('Test video blacklist', function () {
{
const user = { username: 'user_without_flag', password: 'password' }
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
+ await servers[0].usersCommand.create({
username: user.username,
adminFlags: UserAdminFlag.NONE,
password: user.password,
@@ -367,16 +363,13 @@ describe('Test video blacklist', function () {
userWithoutFlag = await servers[0].loginCommand.getAccessToken(user)
- const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
- const body: User = res.body
- channelOfUserWithoutFlag = body.videoChannels[0].id
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: userWithoutFlag })
+ channelOfUserWithoutFlag = videoChannels[0].id
}
{
const user = { username: 'user_with_flag', password: 'password' }
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
+ await servers[0].usersCommand.create({
username: user.username,
adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
password: user.password,
diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts
index ea6055386d..62569f8108 100644
--- a/server/tests/api/notifications/comments-notifications.ts
+++ b/server/tests/api/notifications/comments-notifications.ts
@@ -10,7 +10,6 @@ import {
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- updateMyUser,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
@@ -193,17 +192,8 @@ describe('Test comments notifications', function () {
token: userToken
}
- await updateMyUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- displayName: 'super root name'
- })
-
- await updateMyUser({
- url: servers[1].url,
- accessToken: servers[1].accessToken,
- displayName: 'super root 2 name'
- })
+ await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
+ await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
})
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 99b4346068..0269124c58 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -17,13 +17,10 @@ import {
checkVideoAutoBlacklistForModerators,
checkVideoIsPublished,
cleanupTests,
- createUser,
- generateUserAccessToken,
getVideoIdFromUUID,
MockInstancesIndex,
MockSmtpServer,
prepareNotificationsTest,
- registerUser,
ServerInfo,
uploadVideo,
wait,
@@ -139,8 +136,8 @@ describe('Test moderation notifications', function () {
this.timeout(20000)
const username = 'user' + new Date().getTime()
- const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' })
- const accountId = resUser.body.user.account.id
+ const { account } = await servers[0].usersCommand.create({ username, password: 'donald' })
+ const accountId = account.id
await servers[0].abusesCommand.report({ accountId, reason: 'super reason' })
@@ -152,7 +149,7 @@ describe('Test moderation notifications', function () {
this.timeout(20000)
const username = 'user' + new Date().getTime()
- const tmpToken = await generateUserAccessToken(servers[0], username)
+ const tmpToken = await servers[0].usersCommand.generateUserAndToken(username)
await uploadVideo(servers[0].url, tmpToken, { name: 'super video' })
await waitJobs(servers)
@@ -339,7 +336,7 @@ describe('Test moderation notifications', function () {
it('Should send a notification only to moderators when a user registers on the instance', async function () {
this.timeout(10000)
- await registerUser(servers[0].url, 'user_45', 'password')
+ await servers[0].usersCommand.register({ username: 'user_45' })
await waitJobs(servers)
diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts
index e5864f1c22..f33d8e64d5 100644
--- a/server/tests/api/notifications/notifications-api.ts
+++ b/server/tests/api/notifications/notifications-api.ts
@@ -7,14 +7,13 @@ import {
checkNewVideoFromSubscription,
cleanupTests,
getAllNotificationsSettings,
- getMyUserInformation,
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
uploadRandomVideo,
waitJobs
} from '@shared/extra-utils'
-import { User, UserNotification, UserNotificationSettingValue } from '@shared/models'
+import { UserNotification, UserNotificationSettingValue } from '@shared/models'
const expect = chai.expect
@@ -109,15 +108,14 @@ describe('Test notifications API', function () {
})
{
- const res = await getMyUserInformation(server.url, userToken)
- const info = res.body as User
+ const info = await server.usersCommand.getMyInfo({ token: userToken })
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.NONE)
}
const { name, uuid } = await uploadRandomVideo(server)
const check = { web: true, mail: true }
- await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence')
+ await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
})
it('Should only have web notifications', async function () {
@@ -129,8 +127,7 @@ describe('Test notifications API', function () {
})
{
- const res = await getMyUserInformation(server.url, userToken)
- const info = res.body as User
+ const info = await server.usersCommand.getMyInfo({ token: userToken })
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.WEB)
}
@@ -138,12 +135,12 @@ describe('Test notifications API', function () {
{
const check = { mail: true, web: false }
- await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence')
+ await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
}
{
const check = { mail: false, web: true }
- await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence')
+ await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
}
})
@@ -156,8 +153,7 @@ describe('Test notifications API', function () {
})
{
- const res = await getMyUserInformation(server.url, userToken)
- const info = res.body as User
+ const info = await server.usersCommand.getMyInfo({ token: userToken })
expect(info.notificationSettings.newVideoFromSubscription).to.equal(UserNotificationSettingValue.EMAIL)
}
@@ -165,12 +161,12 @@ describe('Test notifications API', function () {
{
const check = { mail: false, web: true }
- await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'absence')
+ await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'absence')
}
{
const check = { mail: true, web: false }
- await checkNewVideoFromSubscription({ ...baseParams, ...check }, name, uuid, 'presence')
+ await checkNewVideoFromSubscription({ ...baseParams, check }, name, uuid, 'presence')
}
})
@@ -186,8 +182,7 @@ describe('Test notifications API', function () {
})
{
- const res = await getMyUserInformation(server.url, userToken)
- const info = res.body as User
+ const info = await server.usersCommand.getMyInfo({ token: userToken })
expect(info.notificationSettings.newVideoFromSubscription).to.equal(
UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL
)
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts
index 4b31edf25a..465349fb91 100644
--- a/server/tests/api/notifications/user-notifications.ts
+++ b/server/tests/api/notifications/user-notifications.ts
@@ -14,7 +14,6 @@ import {
MockSmtpServer,
prepareNotificationsTest,
ServerInfo,
- updateMyUser,
updateVideo,
uploadRandomVideoOnServers,
wait,
@@ -384,23 +383,14 @@ describe('Test user notifications', function () {
token: userAccessToken
}
- await updateMyUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- displayName: 'super root name'
- })
+ await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
- await updateMyUser({
- url: servers[0].url,
- accessToken: userAccessToken,
+ await servers[0].usersCommand.updateMe({
+ token: userAccessToken,
displayName: myUserName
})
- await updateMyUser({
- url: servers[1].url,
- accessToken: servers[1].accessToken,
- displayName: 'super root 2 name'
- })
+ await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
await servers[0].channelsCommand.update({
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 3cba2b0191..bcc21381cf 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'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
flushAndRunMultipleServers,
getVideoChannelVideos,
SearchCommand,
ServerInfo,
setAccessTokensToServers,
- updateMyUser,
updateVideo,
uploadVideo,
wait,
@@ -35,7 +33,7 @@ describe('Test ActivityPub video channels search', function () {
await setAccessTokensToServers(servers)
{
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user1_server1', password: 'password' })
+ await servers[0].usersCommand.create({ username: 'user1_server1', password: 'password' })
const channel = {
name: 'channel1_server1',
displayName: 'Channel 1 server 1'
@@ -45,7 +43,7 @@ describe('Test ActivityPub video channels search', function () {
{
const user = { username: 'user1_server2', password: 'password' }
- await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+ await servers[1].usersCommand.create({ username: user.username, password: user.password })
userServer2Token = await servers[1].loginCommand.getAccessToken(user)
const channel = {
@@ -171,7 +169,7 @@ describe('Test ActivityPub video channels search', function () {
channelName: 'channel1_server2',
attributes: { displayName: 'channel updated' }
})
- await updateMyUser({ url: servers[1].url, accessToken: userServer2Token, displayName: 'user updated' })
+ await servers[1].usersCommand.updateMe({ token: userServer2Token, displayName: 'user updated' })
await waitJobs(servers)
// Expire video channel
diff --git a/server/tests/api/search/search-channels.ts b/server/tests/api/search/search-channels.ts
index 6c9ee73cee..4d2104708a 100644
--- a/server/tests/api/search/search-channels.ts
+++ b/server/tests/api/search/search-channels.ts
@@ -2,7 +2,7 @@
import 'mocha'
import * as chai from 'chai'
-import { cleanupTests, createUser, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, SearchCommand, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
import { VideoChannel } from '@shared/models'
const expect = chai.expect
@@ -19,7 +19,7 @@ describe('Test channels search', function () {
await setAccessTokensToServers([ server ])
{
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
+ await server.usersCommand.create({ username: 'user1', password: 'password' })
const channel = {
name: 'squall_channel',
displayName: 'Squall channel'
diff --git a/server/tests/api/server/bulk.ts b/server/tests/api/server/bulk.ts
index a09c212285..20a9a3dc7d 100644
--- a/server/tests/api/server/bulk.ts
+++ b/server/tests/api/server/bulk.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
import {
BulkCommand,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideosList,
@@ -38,21 +37,21 @@ describe('Test bulk actions', function () {
{
const user = { username: 'user1', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
user1Token = await servers[0].loginCommand.getAccessToken(user)
}
{
const user = { username: 'user2', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
user2Token = await servers[0].loginCommand.getAccessToken(user)
}
{
const user = { username: 'user3', password: 'password' }
- await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+ await servers[1].usersCommand.create({ username: user.username, password: user.password })
user3Token = await servers[1].loginCommand.getAccessToken(user)
}
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 55cf2a1b86..95dafd3784 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -9,7 +9,6 @@ import {
killallServers,
makeGetRequest,
parallelTests,
- registerUser,
reRunServer,
ServerInfo,
setAccessTokensToServers,
@@ -225,9 +224,9 @@ describe('Test config', function () {
this.timeout(5000)
await Promise.all([
- registerUser(server.url, 'user1', 'super password'),
- registerUser(server.url, 'user2', 'super password'),
- registerUser(server.url, 'user3', 'super password')
+ server.usersCommand.register({ username: 'user1' }),
+ server.usersCommand.register({ username: 'user2' }),
+ server.usersCommand.register({ username: 'user3' })
])
const data = await server.configCommand.getConfig()
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index c64c120e30..422db6cebf 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -2,23 +2,16 @@
import 'mocha'
import * as chai from 'chai'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from '@shared/core-utils'
import {
- askResetPassword,
- askSendVerifyEmail,
- blockUser,
cleanupTests,
- createUser,
flushAndRunServer,
- resetPassword,
+ MockSmtpServer,
ServerInfo,
setAccessTokensToServers,
- unblockUser,
uploadVideo,
- verifyEmail
-} from '../../../../shared/extra-utils'
-import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
+ waitJobs
+} from '@shared/extra-utils'
const expect = chai.expect
@@ -58,8 +51,8 @@ describe('Test emails', function () {
await setAccessTokensToServers([ server ])
{
- const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
- userId = res.body.user.id
+ const created = await server.usersCommand.create({ username: user.username, password: user.password })
+ userId = created.id
userAccessToken = await server.loginCommand.getAccessToken(user)
}
@@ -87,7 +80,7 @@ describe('Test emails', function () {
it('Should ask to reset the password', async function () {
this.timeout(10000)
- await askResetPassword(server.url, '[email protected]')
+ await server.usersCommand.askResetPassword({ email: '[email protected]' })
await waitJobs(server)
expect(emails).to.have.lengthOf(1)
@@ -113,15 +106,25 @@ describe('Test emails', function () {
})
it('Should not reset the password with an invalid verification string', async function () {
- await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', HttpStatusCode.FORBIDDEN_403)
+ await server.usersCommand.resetPassword({
+ userId,
+ verificationString: verificationString + 'b',
+ password: 'super_password2',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should reset the password', async function () {
- await resetPassword(server.url, userId, verificationString, 'super_password2')
+ await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' })
})
it('Should not reset the password with the same verification string', async function () {
- await resetPassword(server.url, userId, verificationString, 'super_password3', HttpStatusCode.FORBIDDEN_403)
+ await server.usersCommand.resetPassword({
+ userId,
+ verificationString,
+ password: 'super_password3',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should login with this new password', async function () {
@@ -132,15 +135,11 @@ describe('Test emails', function () {
})
describe('When creating a user without password', function () {
+
it('Should send a create password email', async function () {
this.timeout(10000)
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: 'create_password',
- password: ''
- })
+ await server.usersCommand.create({ username: 'create_password', password: '' })
await waitJobs(server)
expect(emails).to.have.lengthOf(2)
@@ -166,11 +165,20 @@ describe('Test emails', function () {
})
it('Should not reset the password with an invalid verification string', async function () {
- await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', HttpStatusCode.FORBIDDEN_403)
+ await server.usersCommand.resetPassword({
+ userId: userId2,
+ verificationString: verificationString2 + 'c',
+ password: 'newly_created_password',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should reset the password', async function () {
- await resetPassword(server.url, userId2, verificationString2, 'newly_created_password')
+ await server.usersCommand.resetPassword({
+ userId: userId2,
+ verificationString: verificationString2,
+ password: 'newly_created_password'
+ })
})
it('Should login with this new password', async function () {
@@ -207,7 +215,7 @@ describe('Test emails', function () {
this.timeout(10000)
const reason = 'my super bad reason'
- await blockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204, reason)
+ await server.usersCommand.banUser({ userId, reason })
await waitJobs(server)
expect(emails).to.have.lengthOf(4)
@@ -225,7 +233,7 @@ describe('Test emails', function () {
it('Should send the notification email when unblocking a user', async function () {
this.timeout(10000)
- await unblockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204)
+ await server.usersCommand.unbanUser({ userId })
await waitJobs(server)
expect(emails).to.have.lengthOf(5)
@@ -288,7 +296,7 @@ describe('Test emails', function () {
it('Should ask to send the verification email', async function () {
this.timeout(10000)
- await askSendVerifyEmail(server.url, '[email protected]')
+ await server.usersCommand.askSendVerifyEmail({ email: '[email protected]' })
await waitJobs(server)
expect(emails).to.have.lengthOf(8)
@@ -314,11 +322,16 @@ describe('Test emails', function () {
})
it('Should not verify the email with an invalid verification string', async function () {
- await verifyEmail(server.url, userId, verificationString + 'b', false, HttpStatusCode.FORBIDDEN_403)
+ await server.usersCommand.verifyEmail({
+ userId,
+ verificationString: verificationString + 'b',
+ isPendingEmail: false,
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
})
it('Should verify the email', async function () {
- await verifyEmail(server.url, userId, verificationString)
+ await server.usersCommand.verifyEmail({ userId, verificationString })
})
})
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 74cdf353b3..29ccb264d4 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'
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getAccountVideos,
@@ -47,7 +46,7 @@ describe('Test follow constraints', function () {
username: 'user1',
password: 'super_password'
}
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index c2a0620a58..02d25e67f3 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
import {
cleanupTests,
completeVideoCheck,
- createUser,
dateIsValid,
expectAccountFollows,
flushAndRunMultipleServers,
@@ -327,9 +326,7 @@ describe('Test follows', function () {
await uploadVideo(servers[2].url, servers[2].accessToken, { name: 'server3-6' })
{
- const user = { username: 'captain', password: 'password' }
- await createUser({ url: servers[2].url, accessToken: servers[2].accessToken, username: user.username, password: user.password })
- const userAccessToken = await servers[2].loginCommand.getAccessToken(user)
+ const userAccessToken = await servers[2].usersCommand.generateUserAndToken('captain')
const resVideos = await getVideosList(servers[2].url)
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 c0b9facfff..6854568d3c 100644
--- a/server/tests/api/server/jobs.ts
+++ b/server/tests/api/server/jobs.ts
@@ -30,7 +30,7 @@ describe('Test jobs', function () {
})
it('Should create some jobs', async function () {
- this.timeout(60000)
+ this.timeout(120000)
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
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 a81ac961a6..1fd5e613ba 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'
import {
cleanupTests,
flushAndRunServer,
- getMyUserInformation,
killallServers,
PluginsCommand,
reRunServer,
ServerInfo,
setAccessTokensToServers,
testHelloWorldRegisteredSettings,
- updateMyUser,
wait
} from '@shared/extra-utils'
-import { PluginType, User } from '@shared/models'
+import { PluginType } from '@shared/models'
const expect = chai.expect
@@ -120,14 +118,10 @@ describe('Test plugins', function () {
})
it('Should update my default theme', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: server.accessToken,
- theme: 'background-red'
- })
+ await server.usersCommand.updateMe({ theme: 'background-red' })
- const res = await getMyUserInformation(server.url, server.accessToken)
- expect((res.body as User).theme).to.equal('background-red')
+ const user = await server.usersCommand.getMyInfo()
+ expect(user.theme).to.equal('background-red')
})
it('Should list plugins and themes', async function () {
@@ -311,8 +305,8 @@ describe('Test plugins', function () {
})
it('Should have updated the user theme', async function () {
- const res = await getMyUserInformation(server.url, server.accessToken)
- expect((res.body as User).theme).to.equal('instance-default')
+ const user = await server.usersCommand.getMyInfo()
+ expect(user.theme).to.equal('instance-default')
})
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 d9c669571d..b8bae161a0 100644
--- a/server/tests/api/server/reverse-proxy.ts
+++ b/server/tests/api/server/reverse-proxy.ts
@@ -6,7 +6,7 @@ import {
cleanupTests,
flushAndRunServer,
getVideo,
- registerUser,
+ ServerInfo,
setAccessTokensToServers,
uploadVideo,
viewVideo,
@@ -14,8 +14,8 @@ import {
} from '@shared/extra-utils'
describe('Test application behind a reverse proxy', function () {
- let server = null
- let videoId
+ let server: ServerInfo
+ let videoId: number
before(async function () {
this.timeout(30000)
@@ -102,22 +102,22 @@ describe('Test application behind a reverse proxy', function () {
const user = { username: 'root', password: 'fail' }
for (let i = 0; i < 19; i++) {
- await server.loginCommand.getAccessToken(user, HttpStatusCode.BAD_REQUEST_400)
+ await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}
- await server.loginCommand.getAccessToken(user, HttpStatusCode.TOO_MANY_REQUESTS_429)
+ await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
})
it('Should rate limit signup', async function () {
for (let i = 0; i < 10; i++) {
try {
- await registerUser(server.url, 'test' + i, 'password')
+ await server.usersCommand.register({ username: 'test' + i })
} catch {
// empty
}
}
- await registerUser(server.url, 'test42', 'password', HttpStatusCode.TOO_MANY_REQUESTS_429)
+ await server.usersCommand.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
})
it('Should not rate limit failed signup', async function () {
@@ -126,10 +126,10 @@ describe('Test application behind a reverse proxy', function () {
await wait(7000)
for (let i = 0; i < 3; i++) {
- await registerUser(server.url, 'test' + i, 'password', HttpStatusCode.CONFLICT_409)
+ await server.usersCommand.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 })
}
- await registerUser(server.url, 'test43', 'password', HttpStatusCode.NO_CONTENT_204)
+ await server.usersCommand.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
})
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index aa26f978d7..a35709c268 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
@@ -35,7 +34,7 @@ describe('Test stats (excluding redundancy)', function () {
await doubleFollow(servers[0], servers[1])
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
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 1d0fc35f10..c09a85a323 100644
--- a/server/tests/api/users/user-subscriptions.ts
+++ b/server/tests/api/users/user-subscriptions.ts
@@ -4,7 +4,6 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideosList,
@@ -39,7 +38,7 @@ describe('Test users subscriptions', function () {
{
for (const server of servers) {
const user = { username: 'user' + server.serverNumber, password: 'password' }
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
const accessToken = await server.loginCommand.getAccessToken(user)
users.push({ accessToken })
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 99fa08fe20..43e67ee60c 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -7,17 +7,12 @@ import {
checkTmpIsEmpty,
checkVideoFilesWereRemoved,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getAccountVideos,
- getMyUserInformation,
- removeUser,
ServerInfo,
setAccessTokensToServers,
testImage,
- updateMyAvatar,
- updateMyUser,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
@@ -56,13 +51,8 @@ describe('Test users with multiple servers', function () {
username: 'user1',
password: 'password'
}
- const res = await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: user.username,
- password: user.password
- })
- userId = res.body.user.id
+ const created = await servers[0].usersCommand.create(user)
+ userId = created.id
userAccessToken = await servers[0].loginCommand.getAccessToken(user)
}
@@ -77,15 +67,9 @@ describe('Test users with multiple servers', function () {
it('Should be able to update my display name', async function () {
this.timeout(10000)
- await updateMyUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- displayName: 'my super display name'
- })
-
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- user = res.body
+ await servers[0].usersCommand.updateMe({ displayName: 'my super display name' })
+ user = await servers[0].usersCommand.getMyInfo()
expect(user.account.displayName).to.equal('my super display name')
await waitJobs(servers)
@@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () {
it('Should be able to update my description', async function () {
this.timeout(10_000)
- await updateMyUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- description: 'my super description updated'
- })
+ await servers[0].usersCommand.updateMe({ description: 'my super description updated' })
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- user = res.body
+ user = await servers[0].usersCommand.getMyInfo()
expect(user.account.displayName).to.equal('my super display name')
expect(user.account.description).to.equal('my super description updated')
@@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () {
const fixture = 'avatar2.png'
- await updateMyAvatar({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- fixture
- })
-
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- user = res.body
+ await servers[0].usersCommand.updateMyAvatar({ fixture })
+ user = await servers[0].usersCommand.getMyInfo()
userAvatarFilename = user.account.avatar.path
await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png')
@@ -202,7 +175,7 @@ describe('Test users with multiple servers', function () {
expect(videoChannelDeleted).not.to.be.undefined
}
- await removeUser(servers[0].url, userId, servers[0].accessToken)
+ await servers[0].usersCommand.remove({ userId })
await waitJobs(servers)
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index ade730323e..271aa3c7a1 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -3,20 +3,7 @@
import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- getMyUserInformation,
- getUserInformation,
- MockSmtpServer,
- registerUser,
- ServerInfo,
- setAccessTokensToServers,
- updateMyUser,
- verifyEmail,
- waitJobs
-} from '@shared/extra-utils'
-import { User } from '@shared/models'
+import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
const expect = chai.expect
@@ -65,7 +52,7 @@ describe('Test users account verification', function () {
}
})
- await registerUser(server.url, user1.username, user1.password)
+ await server.usersCommand.register(user1)
await waitJobs(server)
expectedEmailsLength++
@@ -84,8 +71,8 @@ describe('Test users account verification', function () {
userId = parseInt(userIdMatches[1], 10)
- const resUserInfo = await getUserInformation(server.url, server.accessToken, userId)
- expect(resUserInfo.body.emailVerified).to.be.false
+ const body = await server.usersCommand.get({ userId })
+ expect(body.emailVerified).to.be.false
})
it('Should not allow login for user with unverified email', async function () {
@@ -94,13 +81,13 @@ describe('Test users account verification', function () {
})
it('Should verify the user via email and allow login', async function () {
- await verifyEmail(server.url, userId, verificationString)
+ await server.usersCommand.verifyEmail({ userId, verificationString })
const body = await server.loginCommand.login({ user: user1 })
userAccessToken = body.access_token
- const resUserVerified = await getUserInformation(server.url, server.accessToken, userId)
- expect(resUserVerified.body.emailVerified).to.be.true
+ const user = await server.usersCommand.get({ userId })
+ expect(user.emailVerified).to.be.true
})
it('Should be able to change the user email', async function () {
@@ -109,9 +96,8 @@ describe('Test users account verification', function () {
let updateVerificationString: string
{
- await updateMyUser({
- url: server.url,
- accessToken: userAccessToken,
+ await server.usersCommand.updateMe({
+ token: userAccessToken,
currentPassword: user1.password
})
@@ -127,19 +113,15 @@ describe('Test users account verification', function () {
}
{
- const res = await getMyUserInformation(server.url, userAccessToken)
- const me: User = res.body
-
+ const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
expect(me.email).to.equal('[email protected]')
expect(me.pendingEmail).to.equal('[email protected]')
}
{
- await verifyEmail(server.url, userId, updateVerificationString, true)
-
- const res = await getMyUserInformation(server.url, userAccessToken)
- const me: User = res.body
+ await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true })
+ const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
expect(me.email).to.equal('[email protected]')
expect(me.pendingEmail).to.be.null
}
@@ -157,15 +139,15 @@ describe('Test users account verification', function () {
}
})
- await registerUser(server.url, user2.username, user2.password)
+ await server.usersCommand.register(user2)
await waitJobs(server)
expect(emails).to.have.lengthOf(expectedEmailsLength)
const accessToken = await server.loginCommand.getAccessToken(user2)
- const resMyUserInfo = await getMyUserInformation(server.url, accessToken)
- expect(resMyUserInfo.body.emailVerified).to.be.null
+ const user = await server.usersCommand.getMyInfo({ token: accessToken })
+ expect(user.emailVerified).to.be.null
})
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 608bedb8b8..30d7e850de 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -4,37 +4,22 @@ import 'mocha'
import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
- blockUser,
cleanupTests,
- createUser,
- deleteMe,
flushAndRunServer,
- getMyUserInformation,
- getMyUserVideoQuotaUsed,
- getMyUserVideoRating,
getMyVideos,
- getUserInformation,
- getUsersList,
- getUsersListPaginationAndSort,
getVideosList,
killallServers,
makePutBodyRequest,
rateVideo,
- registerUserWithChannel,
- removeUser,
removeVideo,
reRunServer,
ServerInfo,
setAccessTokensToServers,
testImage,
- unblockUser,
- updateMyAvatar,
- updateMyUser,
- updateUser,
uploadVideo,
waitJobs
} from '@shared/extra-utils'
-import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
+import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
const expect = chai.expect
@@ -174,8 +159,7 @@ describe('Test users', function () {
it('Should retrieve a video rating', async function () {
await rateVideo(server.url, accessToken, videoId, 'like')
- const res = await getMyUserVideoRating(server.url, accessToken, videoId)
- const rating = res.body
+ const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId })
expect(rating.videoId).to.equal(videoId)
expect(rating.rating).to.equal('like')
@@ -222,7 +206,7 @@ describe('Test users', function () {
})
it('Should not be able to get the user information', async function () {
- await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should not be able to upload a video', async function () {
@@ -252,7 +236,7 @@ describe('Test users', function () {
})
it('Should be able to get my user information again', async function () {
- await getMyUserInformation(server.url, server.accessToken)
+ await server.usersCommand.getMyInfo()
})
it('Should have an expired access token', async function () {
@@ -264,7 +248,7 @@ describe('Test users', function () {
await killallServers([ server ])
await reRunServer(server)
- await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
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 () {
})
it('Should be able to get my user information again', async function () {
- await getMyUserInformation(server.url, server.accessToken)
+ await server.usersCommand.getMyInfo()
})
})
describe('Creating a user', function () {
it('Should be able to create a new user', async function () {
- await createUser({
- url: server.url,
- accessToken: accessToken,
- username: user.username,
- password: user.password,
- videoQuota: 2 * 1024 * 1024,
- adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
- })
+ await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
})
it('Should be able to login with this user', async function () {
@@ -308,11 +285,9 @@ describe('Test users', function () {
})
it('Should be able to get user information', async function () {
- const res1 = await getMyUserInformation(server.url, accessTokenUser)
- const userMe: MyUser = res1.body
+ const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser })
- const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
- const userGet: User = res2.body
+ const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
for (const user of [ userMe, userGet ]) {
expect(user.username).to.equal('user_1')
@@ -356,15 +331,11 @@ describe('Test users', function () {
})
it('Should have video quota updated', async function () {
- const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
- const data = res.body
-
- expect(data.videoQuotaUsed).to.equal(218910)
-
- const resUsers = await getUsersList(server.url, server.accessToken)
+ const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
+ expect(quota.videoQuotaUsed).to.equal(218910)
- const users: User[] = resUsers.body.data
- const tmpUser = users.find(u => u.username === user.username)
+ const { data } = await server.usersCommand.list()
+ const tmpUser = data.find(u => u.username === user.username)
expect(tmpUser.videoQuotaUsed).to.equal(218910)
})
@@ -421,9 +392,7 @@ describe('Test users', function () {
}
{
- const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
- const data = res.body
-
+ const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
expect(data.videoQuotaUsed).to.be.greaterThan(220000)
}
})
@@ -432,21 +401,18 @@ describe('Test users', function () {
describe('Users listing', function () {
it('Should list all the users', async function () {
- const res = await getUsersList(server.url, server.accessToken)
- const result = res.body
- const total = result.total
- const users = result.data
+ const { data, total } = await server.usersCommand.list()
expect(total).to.equal(2)
- expect(users).to.be.an('array')
- expect(users.length).to.equal(2)
+ expect(data).to.be.an('array')
+ expect(data.length).to.equal(2)
- const user = users[0]
+ const user = data[0]
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('display')
- const rootUser = users[1]
+ const rootUser = data[1]
expect(rootUser.username).to.equal('root')
expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(user.nsfwPolicy).to.equal('display')
@@ -458,16 +424,12 @@ describe('Test users', function () {
})
it('Should list only the first user by username asc', async function () {
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
-
- const result = res.body
- const total = result.total
- const users = result.data
+ const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' })
expect(total).to.equal(2)
- expect(users.length).to.equal(1)
+ expect(data.length).to.equal(1)
- const user = users[0]
+ const user = data[0]
expect(user.username).to.equal('root')
expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(user.roleLabel).to.equal('Administrator')
@@ -475,84 +437,66 @@ describe('Test users', function () {
})
it('Should list only the first user by username desc', async function () {
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
- const result = res.body
- const total = result.total
- const users = result.data
+ const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' })
expect(total).to.equal(2)
- expect(users.length).to.equal(1)
+ expect(data.length).to.equal(1)
- const user = users[0]
+ const user = data[0]
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('display')
})
it('Should list only the second user by createdAt desc', async function () {
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
- const result = res.body
- const total = result.total
- const users = result.data
-
+ const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' })
expect(total).to.equal(2)
- expect(users.length).to.equal(1)
- const user = users[0]
+ expect(data.length).to.equal(1)
+
+ const user = data[0]
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('display')
})
it('Should list all the users by createdAt asc', async function () {
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
- const result = res.body
- const total = result.total
- const users = result.data
+ const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' })
expect(total).to.equal(2)
- expect(users.length).to.equal(2)
+ expect(data.length).to.equal(2)
- expect(users[0].username).to.equal('root')
- expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
- expect(users[0].nsfwPolicy).to.equal('display')
+ expect(data[0].username).to.equal('root')
+ expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
+ expect(data[0].nsfwPolicy).to.equal('display')
- expect(users[1].username).to.equal('user_1')
- expect(users[1].email).to.equal('[email protected]')
- expect(users[1].nsfwPolicy).to.equal('display')
+ expect(data[1].username).to.equal('user_1')
+ expect(data[1].email).to.equal('[email protected]')
+ expect(data[1].nsfwPolicy).to.equal('display')
})
it('Should search user by username', async function () {
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
- const users = res.body.data as User[]
-
- expect(res.body.total).to.equal(1)
- expect(users.length).to.equal(1)
-
- expect(users[0].username).to.equal('root')
+ const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
+ expect(total).to.equal(1)
+ expect(data.length).to.equal(1)
+ expect(data[0].username).to.equal('root')
})
it('Should search user by email', async function () {
{
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
- const users = res.body.data as User[]
-
- expect(res.body.total).to.equal(1)
- expect(users.length).to.equal(1)
-
- expect(users[0].username).to.equal('user_1')
- expect(users[0].email).to.equal('[email protected]')
+ const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
+ expect(total).to.equal(1)
+ expect(data.length).to.equal(1)
+ expect(data[0].username).to.equal('user_1')
+ expect(data[0].email).to.equal('[email protected]')
}
{
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
- const users = res.body.data as User[]
-
- expect(res.body.total).to.equal(2)
- expect(users.length).to.equal(2)
-
- expect(users[0].username).to.equal('root')
- expect(users[1].username).to.equal('user_1')
+ const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
+ expect(total).to.equal(2)
+ expect(data.length).to.equal(2)
+ expect(data[0].username).to.equal('root')
+ expect(data[1].username).to.equal('user_1')
}
})
})
@@ -560,9 +504,8 @@ describe('Test users', function () {
describe('Update my account', function () {
it('Should update my password', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
currentPassword: 'super password',
password: 'new password'
})
@@ -572,15 +515,12 @@ describe('Test users', function () {
})
it('Should be able to change the NSFW display attribute', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
nsfwPolicy: 'do_not_list'
})
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -591,42 +531,33 @@ describe('Test users', function () {
})
it('Should be able to change the autoPlayVideo attribute', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
autoPlayVideo: false
})
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.autoPlayVideo).to.be.false
})
it('Should be able to change the autoPlayNextVideo attribute', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
autoPlayNextVideo: true
})
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.autoPlayNextVideo).to.be.true
})
it('Should be able to change the email attribute', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
currentPassword: 'new password',
})
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -639,15 +570,9 @@ describe('Test users', function () {
it('Should be able to update my avatar with a gif', async function () {
const fixture = 'avatar.gif'
- await updateMyAvatar({
- url: server.url,
- accessToken: accessTokenUser,
- fixture
- })
-
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
+ await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
})
@@ -655,29 +580,17 @@ describe('Test users', function () {
for (const extension of [ '.png', '.gif' ]) {
const fixture = 'avatar' + extension
- await updateMyAvatar({
- url: server.url,
- accessToken: accessTokenUser,
- fixture
- })
-
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
+ await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
}
})
it('Should be able to update my display name', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
- displayName: 'new display name'
- })
-
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user = res.body
+ await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' })
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -688,15 +601,9 @@ describe('Test users', function () {
})
it('Should be able to update my description', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
- description: 'my super description updated'
- })
-
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user: User = res.body
+ await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' })
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -710,30 +617,21 @@ describe('Test users', function () {
it('Should be able to update my theme', async function () {
for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
- theme
- })
+ await server.usersCommand.updateMe({ token: accessTokenUser, theme })
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const body: User = res.body
-
- expect(body.theme).to.equal(theme)
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
+ expect(user.theme).to.equal(theme)
}
})
it('Should be able to update my modal preferences', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: accessTokenUser,
+ await server.usersCommand.updateMe({
+ token: accessTokenUser,
noInstanceConfigWarningModal: true,
noWelcomeModal: true
})
- const res = await getMyUserInformation(server.url, accessTokenUser)
- const user: User = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
expect(user.noWelcomeModal).to.be.true
expect(user.noInstanceConfigWarningModal).to.be.true
})
@@ -741,10 +639,9 @@ describe('Test users', function () {
describe('Updating another user', function () {
it('Should be able to update another user', async function () {
- await updateUser({
- url: server.url,
+ await server.usersCommand.update({
userId,
- accessToken,
+ token: accessToken,
emailVerified: true,
videoQuota: 42,
@@ -753,8 +650,7 @@ describe('Test users', function () {
pluginAuth: 'toto'
})
- const res = await getUserInformation(server.url, accessToken, userId)
- const user = res.body as User
+ const user = await server.usersCommand.get({ token: accessToken, userId })
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('[email protected]')
@@ -768,28 +664,22 @@ describe('Test users', function () {
})
it('Should reset the auth plugin', async function () {
- await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
+ await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null })
- const res = await getUserInformation(server.url, accessToken, userId)
- const user = res.body as User
+ const user = await server.usersCommand.get({ token: accessToken, userId })
expect(user.pluginAuth).to.be.null
})
it('Should have removed the user token', async function () {
- await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
accessTokenUser = await server.loginCommand.getAccessToken(user)
})
it('Should be able to update another user password', async function () {
- await updateUser({
- url: server.url,
- userId,
- accessToken,
- password: 'password updated'
- })
+ await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' })
- await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
@@ -806,7 +696,7 @@ describe('Test users', function () {
describe('Remove a user', function () {
it('Should be able to remove this user', async function () {
- await removeUser(server.url, userId, accessToken)
+ await server.usersCommand.remove({ userId, token: accessToken })
})
it('Should not be able to login with this user', async function () {
@@ -830,7 +720,7 @@ describe('Test users', function () {
const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
- await registerUserWithChannel({ url: server.url, user, channel })
+ await server.usersCommand.register({ ...user, channel })
})
it('Should be able to login with this registered user', async function () {
@@ -843,16 +733,12 @@ describe('Test users', function () {
})
it('Should have the correct display name', async function () {
- const res = await getMyUserInformation(server.url, user15AccessToken)
- const user: User = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
expect(user.account.displayName).to.equal('super user 15')
})
it('Should have the correct video quota', async function () {
- const res = await getMyUserInformation(server.url, user15AccessToken)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
expect(user.videoQuota).to.equal(5 * 1024 * 1024)
})
@@ -864,15 +750,15 @@ describe('Test users', function () {
it('Should remove me', async function () {
{
- const res = await getUsersList(server.url, server.accessToken)
- expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
+ const { data } = await server.usersCommand.list()
+ expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
}
- await deleteMe(server.url, user15AccessToken)
+ await server.usersCommand.deleteMe({ token: user15AccessToken })
{
- const res = await getUsersList(server.url, server.accessToken)
- expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
+ const { data } = await server.usersCommand.list()
+ expect(data.find(u => u.username === 'user_15')).to.be.undefined
}
})
})
@@ -886,49 +772,40 @@ describe('Test users', function () {
}
it('Should block a user', async function () {
- const resUser = await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: user16.username,
- password: user16.password
- })
- user16Id = resUser.body.user.id
+ const user = await server.usersCommand.create({ ...user16 })
+ user16Id = user.id
user16AccessToken = await server.loginCommand.getAccessToken(user16)
- await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
- await blockUser(server.url, user16Id, server.accessToken)
+ await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
+ await server.usersCommand.banUser({ userId: user16Id })
- await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should search user by banned status', async function () {
{
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
- const users = res.body.data as User[]
+ const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
+ expect(total).to.equal(1)
+ expect(data.length).to.equal(1)
- expect(res.body.total).to.equal(1)
- expect(users.length).to.equal(1)
-
- expect(users[0].username).to.equal(user16.username)
+ expect(data[0].username).to.equal(user16.username)
}
{
- const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
- const users = res.body.data as User[]
-
- expect(res.body.total).to.equal(1)
- expect(users.length).to.equal(1)
+ const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
+ expect(total).to.equal(1)
+ expect(data.length).to.equal(1)
- expect(users[0].username).to.not.equal(user16.username)
+ expect(data[0].username).to.not.equal(user16.username)
}
})
it('Should unblock a user', async function () {
- await unblockUser(server.url, user16Id, server.accessToken)
+ await server.usersCommand.unbanUser({ userId: user16Id })
user16AccessToken = await server.loginCommand.getAccessToken(user16)
- await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
+ await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
})
})
@@ -941,19 +818,12 @@ describe('Test users', function () {
username: 'user_17',
password: 'my super password'
}
- const resUser = await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: user17.username,
- password: user17.password
- })
+ const created = await server.usersCommand.create({ ...user17 })
- user17Id = resUser.body.user.id
+ user17Id = created.id
user17AccessToken = await server.loginCommand.getAccessToken(user17)
- const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
- const user: User = res.body
-
+ const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(0)
expect(user.videoCommentsCount).to.equal(0)
expect(user.abusesCount).to.equal(0)
@@ -969,9 +839,7 @@ describe('Test users', function () {
const res1 = await getVideosList(server.url)
videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
- const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
- const user: User = res2.body
-
+ const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(1)
})
@@ -979,9 +847,7 @@ describe('Test users', function () {
const text = 'super comment'
await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text })
- const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
- const user: User = res.body
-
+ const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user.videoCommentsCount).to.equal(1)
})
@@ -992,17 +858,13 @@ describe('Test users', function () {
const body1 = await server.abusesCommand.getAdminList()
const abuseId = body1.data[0].id
- const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
- const user2: User = res2.body
-
+ const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user2.abusesCount).to.equal(1) // number of incriminations
expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
- const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
- const user3: User = res3.body
-
+ const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true })
expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
})
})
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 740314bfdc..169bb2e232 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -10,7 +10,6 @@ import {
checkVideoFilesWereRemoved,
cleanupTests,
completeVideoCheck,
- createUser,
dateIsValid,
doubleFollow,
flushAndRunMultipleServers,
@@ -153,7 +152,7 @@ describe('Test multiple servers', function () {
username: 'user1',
password: 'super_password'
}
- await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password })
+ await servers[1].usersCommand.create({ username: user.username, password: user.password })
const userAccessToken = await servers[1].loginCommand.getAccessToken(user)
const videoAttributes = {
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 5845efc865..642c115d03 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -9,15 +9,13 @@ import {
buildAbsoluteFixturePath,
cleanupTests,
flushAndRunServer,
- getMyUserInformation,
prepareResumableUpload,
sendResumableChunks,
ServerInfo,
setAccessTokensToServers,
- setDefaultVideoChannel,
- updateUser
+ setDefaultVideoChannel
} from '@shared/extra-utils'
-import { MyUser, VideoPrivacy } from '@shared/models'
+import { VideoPrivacy } from '@shared/models'
const expect = chai.expect
@@ -109,15 +107,10 @@ describe('Test resumable upload', function () {
await setAccessTokensToServers([ server ])
await setDefaultVideoChannel([ server ])
- const res = await getMyUserInformation(server.url, server.accessToken)
- rootId = (res.body as MyUser).id
+ const body = await server.usersCommand.getMyInfo()
+ rootId = body.id
- await updateUser({
- url: server.url,
- userId: rootId,
- accessToken: server.accessToken,
- videoQuota: 10_000_000
- })
+ await server.usersCommand.update({ userId: rootId, videoQuota: 10_000_000 })
})
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 17c738e6fb..b0bbd5a0d1 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
import {
ChangeOwnershipCommand,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
flushAndRunServer,
- getMyUserInformation,
getVideo,
getVideosList,
ServerInfo,
@@ -19,21 +17,15 @@ import {
uploadVideo
} from '../../../../shared/extra-utils'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { User } from '../../../../shared/models/users'
import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
const expect = chai.expect
describe('Test video change ownership - nominal', function () {
let servers: ServerInfo[] = []
- const firstUser = {
- username: 'first',
- password: 'My great password'
- }
- const secondUser = {
- username: 'second',
- password: 'My other password'
- }
+
+ const firstUser = 'first'
+ const secondUser = 'second'
let firstUserToken = ''
let firstUserChannelId: number
@@ -65,35 +57,17 @@ describe('Test video change ownership - nominal', function () {
}
})
- const videoQuota = 42000000
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: firstUser.username,
- password: firstUser.password,
- videoQuota: videoQuota
- })
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: secondUser.username,
- password: secondUser.password,
- videoQuota: videoQuota
- })
-
- firstUserToken = await servers[0].loginCommand.getAccessToken(firstUser)
- secondUserToken = await servers[0].loginCommand.getAccessToken(secondUser)
+ firstUserToken = await servers[0].usersCommand.generateUserAndToken(firstUser)
+ secondUserToken = await servers[0].usersCommand.generateUserAndToken(secondUser)
{
- const res = await getMyUserInformation(servers[0].url, firstUserToken)
- const firstUserInformation: User = res.body
- firstUserChannelId = firstUserInformation.videoChannels[0].id
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: firstUserToken })
+ firstUserChannelId = videoChannels[0].id
}
{
- const res = await getMyUserInformation(servers[0].url, secondUserToken)
- const secondUserInformation: User = res.body
- secondUserChannelId = secondUserInformation.videoChannels[0].id
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: secondUserToken })
+ secondUserChannelId = videoChannels[0].id
}
{
@@ -140,7 +114,7 @@ describe('Test video change ownership - nominal', function () {
it('Should send a request to change ownership of a video', async function () {
this.timeout(15000)
- await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
+ await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
})
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 () {
it('Should accept the same change ownership request without crashing', async function () {
this.timeout(10000)
- await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
+ await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
})
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 () {
it('Should send a new request to change ownership of a video', async function () {
this.timeout(15000)
- await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser.username })
+ await command.create({ token: firstUserToken, videoId: servers[0].video.id, username: secondUser })
})
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 () {
it('Should send a request to change ownership of a live', async function () {
this.timeout(15000)
- await command.create({ token: firstUserToken, videoId: liveId, username: secondUser.username })
+ await command.create({ token: firstUserToken, videoId: liveId, username: secondUser })
const body = await command.list({ token: secondUserToken })
@@ -286,14 +260,9 @@ describe('Test video change ownership - nominal', function () {
describe('Test video change ownership - quota too small', function () {
let server: ServerInfo
- const firstUser = {
- username: 'first',
- password: 'My great password'
- }
- const secondUser = {
- username: 'second',
- password: 'My other password'
- }
+ const firstUser = 'first'
+ const secondUser = 'second'
+
let firstUserToken = ''
let secondUserToken = ''
let lastRequestId: number
@@ -305,24 +274,9 @@ describe('Test video change ownership - quota too small', function () {
server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ])
- const videoQuota = 42000000
- const limitedVideoQuota = 10
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: firstUser.username,
- password: firstUser.password,
- videoQuota: videoQuota
- })
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: secondUser.username,
- password: secondUser.password,
- videoQuota: limitedVideoQuota
- })
+ await server.usersCommand.create({ username: secondUser, videoQuota: 10 })
- firstUserToken = await server.loginCommand.getAccessToken(firstUser)
+ firstUserToken = await server.usersCommand.generateUserAndToken(firstUser)
secondUserToken = await server.loginCommand.getAccessToken(secondUser)
// Upload some videos on the server
@@ -345,7 +299,7 @@ describe('Test video change ownership - quota too small', function () {
it('Should send a request to change ownership of a video', async function () {
this.timeout(15000)
- await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser.username })
+ await server.changeOwnershipCommand.create({ token: firstUserToken, videoId: server.video.id, username: secondUser })
})
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 () {
it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () {
this.timeout(10000)
- const secondUserInformationResponse = await getMyUserInformation(server.url, secondUserToken)
- const secondUserInformation: User = secondUserInformationResponse.body
- const channelId = secondUserInformation.videoChannels[0].id
+ const { videoChannels } = await server.usersCommand.getMyInfo({ token: secondUserToken })
+ const channelId = videoChannels[0].id
await server.changeOwnershipCommand.accept({
token: secondUserToken,
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 83645640ce..2e57cbbff5 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'
import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
getVideo,
getVideoChannelVideos,
+ ServerInfo,
+ setAccessTokensToServers,
setDefaultVideoChannel,
testFileExistsOrNot,
testImage,
updateVideo,
uploadVideo,
- wait
-} from '../../../../shared/extra-utils'
-import { getMyUserInformation, ServerInfo, setAccessTokensToServers, viewVideo } from '../../../../shared/extra-utils/index'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
+ viewVideo,
+ wait,
+ waitJobs
+} from '@shared/extra-utils'
+import { User, Video, VideoChannel, VideoDetails } from '@shared/models'
const expect = chai.expect
@@ -85,8 +86,7 @@ describe('Test video channels', function () {
})
it('Should have two video channels when getting my information', async () => {
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- userInfo = res.body
+ userInfo = await servers[0].usersCommand.getMyInfo()
expect(userInfo.videoChannels).to.be.an('array')
expect(userInfo.videoChannels).to.have.lengthOf(2)
@@ -389,11 +389,11 @@ describe('Test video channels', function () {
}
{
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
+ await servers[0].usersCommand.create({ username: 'toto', password: 'password' })
const accessToken = await servers[0].loginCommand.getAccessToken({ username: 'toto', password: 'password' })
- const res = await getMyUserInformation(servers[0].url, accessToken)
- const videoChannel = res.body.videoChannels[0]
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token: accessToken })
+ const videoChannel = videoChannels[0]
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}/)
}
})
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index f9bd236462..266824d586 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'
import {
cleanupTests,
CommentsCommand,
- createUser,
dateIsValid,
flushAndRunServer,
ServerInfo,
setAccessTokensToServers,
testImage,
- updateMyAvatar,
uploadVideo
} from '@shared/extra-utils'
@@ -39,19 +37,9 @@ describe('Test video comments', function () {
videoUUID = res.body.video.uuid
videoId = res.body.video.id
- await updateMyAvatar({
- url: server.url,
- accessToken: server.accessToken,
- fixture: 'avatar.png'
- })
+ await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: 'user1',
- password: 'password'
- })
- userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password')
+ userAccessTokenServer1 = await server.usersCommand.generateUserAndToken('user1')
command = server.commentsCommand
})
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
index f6ae8cab14..052c052b40 100644
--- a/server/tests/api/videos/video-imports.ts
+++ b/server/tests/api/videos/video-imports.ts
@@ -7,7 +7,6 @@ import {
cleanupTests,
doubleFollow,
flushAndRunMultipleServers,
- getMyUserInformation,
getMyVideos,
getVideo,
getVideosList,
@@ -97,13 +96,13 @@ describe('Test video imports', function () {
await setAccessTokensToServers(servers)
{
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- channelIdServer1 = res.body.videoChannels[0].id
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo()
+ channelIdServer1 = videoChannels[0].id
}
{
- const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
- channelIdServer2 = res.body.videoChannels[0].id
+ const { videoChannels } = await servers[1].usersCommand.getMyInfo()
+ channelIdServer2 = videoChannels[0].id
}
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 a30b11ace4..9dc26fca6c 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -4,20 +4,17 @@ import 'mocha'
import * as chai from 'chai'
import {
cleanupTests,
- createUser,
flushAndRunServer,
getAccountVideos,
- getMyUserInformation,
getMyVideos,
getVideoChannelVideos,
getVideosList,
getVideosListWithToken,
ServerInfo,
setAccessTokensToServers,
- updateMyUser,
uploadVideo
} from '@shared/extra-utils'
-import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models'
+import { BooleanBothQuery, CustomConfig, ResultList, Video, VideosOverview } from '@shared/models'
const expect = chai.expect
@@ -32,8 +29,7 @@ describe('Test video NSFW policy', function () {
let customConfig: CustomConfig
async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
- const res = await getMyUserInformation(server.url, server.accessToken)
- const user: User = res.body
+ const user = await server.usersCommand.getMyInfo()
const videoChannelName = user.videoChannels[0].name
const accountName = user.account.name + '@' + user.account.host
const hasQuery = Object.keys(query).length !== 0
@@ -148,13 +144,11 @@ describe('Test video NSFW policy', function () {
it('Should create a user having the default nsfw policy', async function () {
const username = 'user1'
const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
+ await server.usersCommand.create({ username: username, password: password })
userAccessToken = await server.loginCommand.getAccessToken({ username, password })
- const res = await getMyUserInformation(server.url, userAccessToken)
- const user = res.body
-
+ const user = await server.usersCommand.getMyInfo({ token: userAccessToken })
expect(user.nsfwPolicy).to.equal('blur')
})
@@ -173,11 +167,7 @@ describe('Test video NSFW policy', function () {
})
it('Should display NSFW videos with display user NSFW policy', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: server.accessToken,
- nsfwPolicy: 'display'
- })
+ await server.usersCommand.updateMe({ nsfwPolicy: 'display' })
for (const body of await getVideosFunctions(server.accessToken)) {
expect(body.total).to.equal(2)
@@ -190,11 +180,7 @@ describe('Test video NSFW policy', function () {
})
it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: server.accessToken,
- nsfwPolicy: 'do_not_list'
- })
+ await server.usersCommand.updateMe({ nsfwPolicy: 'do_not_list' })
for (const body of await getVideosFunctions(server.accessToken)) {
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 38133e2ce4..e57d86c14d 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'
import {
checkPlaylistFilesWereRemoved,
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
- generateUserAccessToken,
- getMyUserInformation,
PlaylistsCommand,
- removeUser,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
@@ -24,7 +20,6 @@ import {
waitJobs
} from '@shared/extra-utils'
import {
- User,
VideoPlaylist,
VideoPlaylistCreateResult,
VideoPlaylistElementType,
@@ -113,15 +108,7 @@ describe('Test video playlists', function () {
nsfwVideoServer1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'NSFW video', nsfw: true })).id
- {
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: 'user1',
- password: 'password'
- })
- userTokenServer1 = await servers[0].loginCommand.getAccessToken('user1', 'password')
- }
+ userTokenServer1 = await servers[0].usersCommand.generateUserAndToken('user1')
await waitJobs(servers)
})
@@ -165,7 +152,7 @@ describe('Test video playlists', function () {
})
it('Should get private playlist for a classic user', async function () {
- const token = await generateUserAccessToken(servers[0], 'toto')
+ const token = await servers[0].usersCommand.generateUserAndToken('toto')
const body = await commands[0].listByAccount({ token, handle: 'toto' })
@@ -1118,19 +1105,10 @@ describe('Test video playlists', function () {
it('Should delete an account and delete its playlists', async function () {
this.timeout(30000)
- const user = { username: 'user_1', password: 'password' }
- const res = await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: user.username,
- password: user.password
- })
-
- const userId = res.body.user.id
- const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
+ const { userId, token } = await servers[0].usersCommand.generate('user_1')
- const resChannel = await getMyUserInformation(servers[0].url, userAccessToken)
- const userChannel = (resChannel.body as User).videoChannels[0]
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo({ token })
+ const userChannel = videoChannels[0]
await commands[0].create({
attributes: {
@@ -1152,7 +1130,7 @@ describe('Test video playlists', function () {
}
}
- await removeUser(servers[0].url, userId, servers[0].accessToken)
+ await servers[0].usersCommand.remove({ userId })
await waitJobs(servers)
{
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index f831dd8a9f..4e349e3502 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'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunServer,
getMyVideos,
@@ -125,7 +124,7 @@ describe('Test video privacy', function () {
username: 'hello',
password: 'super password'
}
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
+ await servers[0].usersCommand.create({ username: user.username, password: user.password })
anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
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 519dad646f..4aa00cfc49 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'
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
makeGetRequest,
@@ -60,17 +59,7 @@ describe('Test videos filter', function () {
for (const server of servers) {
const moderator = { username: 'moderator', password: 'my super password' }
- await createUser(
- {
- url: server.url,
- accessToken: server.accessToken,
- username: moderator.username,
- password: moderator.password,
- videoQuota: undefined,
- videoQuotaDaily: undefined,
- role: UserRole.MODERATOR
- }
- )
+ await server.usersCommand.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
server['moderatorAccessToken'] = await server.loginCommand.getAccessToken(moderator)
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 256271bd0e..aa0623f7dc 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'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
flushAndRunServer,
getVideosListWithToken,
getVideoWithToken,
@@ -14,7 +13,6 @@ import {
reRunServer,
ServerInfo,
setAccessTokensToServers,
- updateMyUser,
uploadVideo,
wait
} from '@shared/extra-utils'
@@ -59,7 +57,7 @@ describe('Test videos history', function () {
username: 'user_1',
password: 'super password'
}
- await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
+ await server.usersCommand.create({ username: user.username, password: user.password })
userAccessToken = await server.loginCommand.getAccessToken(user)
})
@@ -174,9 +172,7 @@ describe('Test videos history', function () {
})
it('Should disable videos history', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: server.accessToken,
+ await server.usersCommand.updateMe({
videosHistoryEnabled: false
})
@@ -184,9 +180,7 @@ describe('Test videos history', function () {
})
it('Should re-enable videos history', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: server.accessToken,
+ await server.usersCommand.updateMe({
videosHistoryEnabled: true
})
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts
index ccbc6f4a4f..a2da2eaef6 100644
--- a/server/tests/api/videos/videos-overview.ts
+++ b/server/tests/api/videos/videos-overview.ts
@@ -2,15 +2,7 @@
import 'mocha'
import * as chai from 'chai'
-import {
- cleanupTests,
- flushAndRunServer,
- generateUserAccessToken,
- ServerInfo,
- setAccessTokensToServers,
- uploadVideo,
- wait
-} from '@shared/extra-utils'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo, wait } from '@shared/extra-utils'
import { VideosOverview } from '@shared/models'
const expect = chai.expect
@@ -112,7 +104,7 @@ describe('Test a videos overview', function () {
})
it('Should hide muted accounts', async function () {
- const token = await generateUserAccessToken(server, 'choco')
+ const token = await server.usersCommand.generateUserAndToken('choco')
await server.blocklistCommand.addToMyBlocklist({ token, account: 'root@' + server.host })
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index e055b46840..a0c149ac0f 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -8,11 +8,9 @@ import {
buildAbsoluteFixturePath,
cleanupTests,
CLICommand,
- createUser,
doubleFollow,
flushAndRunServer,
getLocalIdByUUID,
- getMyUserInformation,
getVideo,
getVideosList,
ImportsCommand,
@@ -38,7 +36,7 @@ describe('Test CLI wrapper', function () {
server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ])
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
+ await server.usersCommand.create({ username: 'user_1', password: 'super_password' })
userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
@@ -56,8 +54,8 @@ describe('Test CLI wrapper', function () {
const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
const token = stdout.trim()
- const res = await getMyUserInformation(server.url, token)
- expect(res.body.username).to.equal('user_1')
+ const body = await server.usersCommand.getMyInfo({ token })
+ expect(body.username).to.equal('user_1')
})
it('Should display no selected instance', async function () {
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 68a59a41d0..b450499640 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -16,7 +16,6 @@ import {
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- updateMyAvatar,
uploadVideo,
wait,
waitJobs
@@ -73,7 +72,7 @@ describe('Test prune storage scripts', function () {
await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
- await updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' })
+ await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' })
await server.playlistsCommand.create({
attributes: {
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index a5f958bf7e..5e1e1c2af4 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -1,5 +1,5 @@
import 'mocha'
-import { cleanupTests, CLICommand, createUser, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils'
+import { cleanupTests, CLICommand, flushAndRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils'
describe('Test reset password scripts', function () {
let server: ServerInfo
@@ -9,7 +9,7 @@ describe('Test reset password scripts', function () {
server = await flushAndRunServer(1)
await setAccessTokensToServers([ server ])
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
+ await server.usersCommand.create({ username: 'user_1', password: 'super password' })
})
it('Should change the user password from CLI', async function () {
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index e986a04f2f..b857fcf28c 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -4,7 +4,6 @@ import 'mocha'
import { expect } from 'chai'
import {
cleanupTests,
- createUser,
flushAndRunServer,
getVideo,
getVideosList,
@@ -41,7 +40,7 @@ describe('Test update host scripts', function () {
await uploadVideo(server.url, server.accessToken, videoAttributes)
// Create a user
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
+ await server.usersCommand.create({ username: 'toto', password: 'coucou' })
// Create channel
const videoChannel = {
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 1bdb2eb641..96403da375 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -15,7 +15,6 @@ import {
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- updateMyUser,
uploadVideo,
waitJobs
} from '../../shared/extra-utils'
@@ -96,7 +95,7 @@ describe('Test a client controllers', function () {
// Account
- await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
+ await servers[0].usersCommand.updateMe({ description: 'my account description' })
account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
diff --git a/server/tests/external-plugins/auth-ldap.ts b/server/tests/external-plugins/auth-ldap.ts
index 8153e2b811..d99b3badc9 100644
--- a/server/tests/external-plugins/auth-ldap.ts
+++ b/server/tests/external-plugins/auth-ldap.ts
@@ -3,9 +3,7 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import { User } from '@shared/models/users/user.model'
-import { blockUser, getMyUserInformation, setAccessTokensToServers, unblockUser, uploadVideo } from '../../../shared/extra-utils'
-import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
+import { cleanupTests, flushAndRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '@shared/extra-utils'
describe('Official plugin auth-ldap', function () {
let server: ServerInfo
@@ -71,9 +69,7 @@ describe('Official plugin auth-ldap', function () {
})
it('Should login get my profile', async function () {
- const res = await getMyUserInformation(server.url, accessToken)
- const body: User = res.body
-
+ const body = await server.usersCommand.getMyInfo({ token: accessToken })
expect(body.username).to.equal('fry')
expect(body.email).to.equal('[email protected]')
@@ -85,7 +81,7 @@ describe('Official plugin auth-ldap', function () {
})
it('Should not be able to login if the user is banned', async function () {
- await blockUser(server.url, userId, server.accessToken)
+ await server.usersCommand.banUser({ userId })
await server.loginCommand.login({
user: { username: '[email protected]', password: 'fry' },
@@ -94,7 +90,7 @@ describe('Official plugin auth-ldap', function () {
})
it('Should be able to login if the user is unbanned', async function () {
- await unblockUser(server.url, userId, server.accessToken)
+ await server.usersCommand.unbanUser({ userId })
await server.loginCommand.login({ user: { username: '[email protected]', password: 'fry' } })
})
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 9c78ae0e8d..18ce8f7c53 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -6,21 +6,16 @@ import * as xmlParser from 'fast-xml-parser'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
doubleFollow,
flushAndRunMultipleServers,
flushAndRunServer,
- getMyUserInformation,
- getUserScopedTokens,
- renewUserScopedTokens,
ServerInfo,
setAccessTokensToServers,
uploadVideo,
uploadVideoAndGetId,
waitJobs
} from '@shared/extra-utils'
-import { User, VideoPrivacy } from '@shared/models'
-import { ScopedToken } from '@shared/models/users/user-scoped-token'
+import { VideoPrivacy } from '@shared/models'
chai.use(require('chai-xml'))
chai.use(require('chai-json-schema'))
@@ -54,24 +49,21 @@ describe('Test syndication feeds', () => {
await doubleFollow(servers[0], servers[1])
{
- const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- const user: User = res.body
+ const user = await servers[0].usersCommand.getMyInfo()
rootAccountId = user.account.id
rootChannelId = user.videoChannels[0].id
}
{
const attr = { username: 'john', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
+ await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
userAccessToken = await servers[0].loginCommand.getAccessToken(attr)
- const res = await getMyUserInformation(servers[0].url, userAccessToken)
- const user: User = res.body
+ const user = await servers[0].usersCommand.getMyInfo({ token: userAccessToken })
userAccountId = user.account.id
userChannelId = user.videoChannels[0].id
- const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
- const token: ScopedToken = res2.body
+ const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
userFeedToken = token.feedToken
}
@@ -299,18 +291,16 @@ describe('Test syndication feeds', () => {
it('Should list no videos for a user with no videos and no subscriptions', async function () {
const attr = { username: 'feeduser', password: 'password' }
- await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
+ await servers[0].usersCommand.create({ username: attr.username, password: attr.password })
const feeduserAccessToken = await servers[0].loginCommand.getAccessToken(attr)
{
- const res = await getMyUserInformation(servers[0].url, feeduserAccessToken)
- const user: User = res.body
+ const user = await servers[0].usersCommand.getMyInfo({ token: feeduserAccessToken })
feeduserAccountId = user.account.id
}
{
- const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken)
- const token: ScopedToken = res.body
+ const token = await servers[0].usersCommand.getMyScopedTokens({ token: feeduserAccessToken })
feeduserFeedToken = token.feedToken
}
@@ -381,15 +371,14 @@ describe('Test syndication feeds', () => {
})
it('Should renew the token, and so have an invalid old token', async function () {
- await renewUserScopedTokens(servers[0].url, userAccessToken)
+ await servers[0].usersCommand.renewMyScopedTokens({ token: userAccessToken })
const query = { accountId: userAccountId, token: userFeedToken, version: 3 }
await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
})
it('Should succeed with the new token', async function () {
- const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
- const token: ScopedToken = res2.body
+ const token = await servers[0].usersCommand.getMyScopedTokens({ token: userAccessToken })
userFeedToken = token.feedToken
const query = { accountId: userAccountId, token: userFeedToken, version: 4 }
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts
index 4b7b2163dd..84bdcaabf7 100644
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
flushAndRunServer,
makeGetRequest,
ServerInfo,
@@ -173,8 +172,8 @@ describe('Test misc endpoints', function () {
await server.channelsCommand.create({ attributes: { name: 'channel1', displayName: 'channel 1' } })
await server.channelsCommand.create({ attributes: { name: 'channel2', displayName: 'channel 2' } })
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
- await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
+ await server.usersCommand.create({ username: 'user1', password: 'password' })
+ await server.usersCommand.create({ username: 'user2', password: 'password' })
const res = await makeGetRequest({
url: server.url,
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 84f4e85010..b156f6b604 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -1,28 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
-import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
import {
- blockUser,
- createUser,
+ cleanupTests,
+ flushAndRunMultipleServers,
+ killallServers,
PluginsCommand,
- registerUser,
- removeUser,
+ reRunServer,
+ ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
- unblockUser,
- updateUser,
updateVideo,
uploadVideo,
viewVideo
-} from '../../../shared/extra-utils'
-import {
- cleanupTests,
- flushAndRunMultipleServers,
- killallServers,
- reRunServer,
- ServerInfo
-} from '../../../shared/extra-utils/server/servers'
+} from '@shared/extra-utils'
+import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
describe('Test plugin action hooks', function () {
let servers: ServerInfo[]
@@ -119,19 +111,14 @@ describe('Test plugin action hooks', function () {
let userId: number
it('Should run action:api.user.registered', async function () {
- await registerUser(servers[0].url, 'registered_user', 'super_password')
+ await servers[0].usersCommand.register({ username: 'registered_user' })
await checkHook('action:api.user.registered')
})
it('Should run action:api.user.created', async function () {
- const res = await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: 'created_user',
- password: 'super_password'
- })
- userId = res.body.user.id
+ const user = await servers[0].usersCommand.create({ username: 'created_user' })
+ userId = user.id
await checkHook('action:api.user.created')
})
@@ -143,25 +130,25 @@ describe('Test plugin action hooks', function () {
})
it('Should run action:api.user.blocked', async function () {
- await blockUser(servers[0].url, userId, servers[0].accessToken)
+ await servers[0].usersCommand.banUser({ userId })
await checkHook('action:api.user.blocked')
})
it('Should run action:api.user.unblocked', async function () {
- await unblockUser(servers[0].url, userId, servers[0].accessToken)
+ await servers[0].usersCommand.unbanUser({ userId })
await checkHook('action:api.user.unblocked')
})
it('Should run action:api.user.updated', async function () {
- await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 })
+ await servers[0].usersCommand.update({ userId, videoQuota: 50 })
await checkHook('action:api.user.updated')
})
it('Should run action:api.user.deleted', async function () {
- await removeUser(servers[0].url, userId, servers[0].accessToken)
+ await servers[0].usersCommand.remove({ userId })
await checkHook('action:api.user.deleted')
})
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index e421fd2245..3e83056111 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -5,17 +5,14 @@ import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
import {
cleanupTests,
- createUser,
decodeQueryString,
flushAndRunServer,
- getMyUserInformation,
PluginsCommand,
ServerInfo,
setAccessTokensToServers,
- updateMyUser,
wait
} from '@shared/extra-utils'
-import { User, UserRole } from '@shared/models'
+import { UserRole } from '@shared/models'
async function loginExternal (options: {
server: ServerInfo
@@ -149,9 +146,7 @@ describe('Test external auth plugins', function () {
}
{
- const res = await getMyUserInformation(server.url, cyanAccessToken)
-
- const body: User = res.body
+ const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
expect(body.username).to.equal('cyan')
expect(body.account.displayName).to.equal('cyan')
expect(body.email).to.equal('[email protected]')
@@ -173,9 +168,7 @@ describe('Test external auth plugins', function () {
}
{
- const res = await getMyUserInformation(server.url, kefkaAccessToken)
-
- const body: User = res.body
+ const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken })
expect(body.username).to.equal('kefka')
expect(body.account.displayName).to.equal('Kefka Palazzo')
expect(body.email).to.equal('[email protected]')
@@ -189,9 +182,8 @@ describe('Test external auth plugins', function () {
cyanAccessToken = resRefresh.body.access_token
cyanRefreshToken = resRefresh.body.refresh_token
- const res = await getMyUserInformation(server.url, cyanAccessToken)
- const user: User = res.body
- expect(user.username).to.equal('cyan')
+ const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
+ expect(body.username).to.equal('cyan')
}
{
@@ -200,16 +192,13 @@ describe('Test external auth plugins', function () {
})
it('Should update Cyan profile', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: cyanAccessToken,
+ await server.usersCommand.updateMe({
+ token: cyanAccessToken,
displayName: 'Cyan Garamonde',
description: 'Retainer to the king of Doma'
})
- const res = await getMyUserInformation(server.url, cyanAccessToken)
-
- const body: User = res.body
+ const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
expect(body.account.displayName).to.equal('Cyan Garamonde')
expect(body.account.description).to.equal('Retainer to the king of Doma')
})
@@ -221,7 +210,7 @@ describe('Test external auth plugins', function () {
it('Should have logged out Cyan', async function () {
await server.serversCommand.waitUntilLog('On logout cyan')
- await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should login Cyan and keep the old existing profile', async function () {
@@ -239,9 +228,7 @@ describe('Test external auth plugins', function () {
cyanAccessToken = res.access_token
}
- const res = await getMyUserInformation(server.url, cyanAccessToken)
-
- const body: User = res.body
+ const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
expect(body.username).to.equal('cyan')
expect(body.account.displayName).to.equal('Cyan Garamonde')
expect(body.account.description).to.equal('Retainer to the king of Doma')
@@ -249,12 +236,11 @@ describe('Test external auth plugins', function () {
})
it('Should not update an external auth email', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: cyanAccessToken,
+ await server.usersCommand.updateMe({
+ token: cyanAccessToken,
currentPassword: 'toto',
- statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
+ expectedStatus: HttpStatusCode.BAD_REQUEST_400
})
})
@@ -263,7 +249,7 @@ describe('Test external auth plugins', function () {
await wait(5000)
- await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401)
+ await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -334,12 +320,7 @@ describe('Test external auth plugins', function () {
})
it('Should not login an existing user', async function () {
- await createUser({
- url: server.url,
- accessToken: server.accessToken,
- username: 'existing_user',
- password: 'super_password'
- })
+ await server.usersCommand.create({ username: 'existing_user', password: 'super_password' })
await loginExternal({
server,
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index b5e29d2985..c82025f6ad 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -17,7 +17,6 @@ import {
ImportsCommand,
makeRawRequest,
PluginsCommand,
- registerUser,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
@@ -335,11 +334,15 @@ describe('Test plugin filter hooks', function () {
})
it('Should allow a signup', async function () {
- await registerUser(servers[0].url, 'john', 'password')
+ await servers[0].usersCommand.register({ username: 'john', password: 'password' })
})
it('Should not allow a signup', async function () {
- const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403)
+ const res = await servers[0].usersCommand.register({
+ username: 'jma',
+ password: 'password',
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
expect(res.body.error).to.equal('No jma')
})
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index e3da641105..787080e7c9 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -3,18 +3,8 @@
import 'mocha'
import { expect } from 'chai'
import { HttpStatusCode } from '@shared/core-utils'
-import {
- cleanupTests,
- flushAndRunServer,
- getMyUserInformation,
- getUsersList,
- PluginsCommand,
- ServerInfo,
- setAccessTokensToServers,
- updateMyUser,
- wait
-} from '@shared/extra-utils'
-import { User, UserRole } from '@shared/models'
+import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
+import { UserRole } from '@shared/models'
describe('Test id and pass auth plugins', function () {
let server: ServerInfo
@@ -55,9 +45,8 @@ describe('Test id and pass auth plugins', function () {
it('Should login Spyro, create the user and use the token', async function () {
const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' })
- const res = await getMyUserInformation(server.url, accessToken)
+ const body = await server.usersCommand.getMyInfo({ token: accessToken })
- const body: User = res.body
expect(body.username).to.equal('spyro')
expect(body.account.displayName).to.equal('Spyro the Dragon')
expect(body.role).to.equal(UserRole.USER)
@@ -71,9 +60,8 @@ describe('Test id and pass auth plugins', function () {
}
{
- const res = await getMyUserInformation(server.url, crashAccessToken)
+ const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
- const body: User = res.body
expect(body.username).to.equal('crash')
expect(body.account.displayName).to.equal('Crash Bandicoot')
expect(body.role).to.equal(UserRole.MODERATOR)
@@ -88,9 +76,8 @@ describe('Test id and pass auth plugins', function () {
}
{
- const res = await getMyUserInformation(server.url, lagunaAccessToken)
+ const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken })
- const body: User = res.body
expect(body.username).to.equal('laguna')
expect(body.account.displayName).to.equal('laguna')
expect(body.role).to.equal(UserRole.USER)
@@ -103,9 +90,8 @@ describe('Test id and pass auth plugins', function () {
crashAccessToken = resRefresh.body.access_token
crashRefreshToken = resRefresh.body.refresh_token
- const res = await getMyUserInformation(server.url, crashAccessToken)
- const user: User = res.body
- expect(user.username).to.equal('crash')
+ const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
+ expect(body.username).to.equal('crash')
}
{
@@ -114,16 +100,14 @@ describe('Test id and pass auth plugins', function () {
})
it('Should update Crash profile', async function () {
- await updateMyUser({
- url: server.url,
- accessToken: crashAccessToken,
+ await server.usersCommand.updateMe({
+ token: crashAccessToken,
displayName: 'Beautiful Crash',
description: 'Mutant eastern barred bandicoot'
})
- const res = await getMyUserInformation(server.url, crashAccessToken)
+ const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
- const body: User = res.body
expect(body.account.displayName).to.equal('Beautiful Crash')
expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
})
@@ -135,15 +119,14 @@ describe('Test id and pass auth plugins', function () {
it('Should have logged out Crash', async function () {
await server.serversCommand.waitUntilLog('On logout for auth 1 - 2')
- await getMyUserInformation(server.url, crashAccessToken, 401)
+ await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should login Crash and keep the old existing profile', async function () {
crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' })
- const res = await getMyUserInformation(server.url, crashAccessToken)
+ const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
- const body: User = res.body
expect(body.username).to.equal('crash')
expect(body.account.displayName).to.equal('Beautiful Crash')
expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
@@ -155,7 +138,7 @@ describe('Test id and pass auth plugins', function () {
await wait(5000)
- await getMyUserInformation(server.url, lagunaAccessToken, 401)
+ await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should reject an invalid username, email, role or display name', async function () {
@@ -215,13 +198,11 @@ describe('Test id and pass auth plugins', function () {
})
it('Should display plugin auth information in users list', async function () {
- const res = await getUsersList(server.url, server.accessToken)
-
- const users: User[] = res.body.data
+ const { data } = await server.usersCommand.list()
- const root = users.find(u => u.username === 'root')
- const crash = users.find(u => u.username === 'crash')
- const laguna = users.find(u => u.username === 'laguna')
+ const root = data.find(u => u.username === 'root')
+ const crash = data.find(u => u.username === 'crash')
+ const laguna = data.find(u => u.username === 'laguna')
expect(root.pluginAuth).to.be.null
expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one')
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index 3e0e03b972..17c2e8c747 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -3,8 +3,7 @@ import { Netrc } from 'netrc-parser'
import { join } from 'path'
import { createLogger, format, transports } from 'winston'
import { assignCommands, ServerInfo } from '@shared/extra-utils'
-import { getMyUserInformation } from '@shared/extra-utils/users/users'
-import { User, UserRole } from '@shared/models'
+import { UserRole } from '@shared/models'
import { VideoPrivacy } from '../../shared/models/videos'
import { getAppNumber, isTestInstance, root } from '../helpers/core-utils'
@@ -16,16 +15,15 @@ const config = require('application-config')(configName)
const version = require('../../../package.json').version
async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) {
- const accessToken = await server.loginCommand.getAccessToken(username, password)
- const resMe = await getMyUserInformation(server.url, accessToken)
- const me: User = resMe.body
+ const token = await server.loginCommand.getAccessToken(username, password)
+ const me = await server.usersCommand.getMyUserInformation({ token })
if (me.role !== UserRole.ADMINISTRATOR) {
console.error('You must be an administrator.')
process.exit(-1)
}
- return accessToken
+ return token
}
interface Settings {
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 4d95996800..b6d597c5d1 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -16,7 +16,7 @@ import { AbusesCommand } from '../moderation'
import { OverviewsCommand } from '../overviews'
import { SearchCommand } from '../search'
import { SocketIOCommand } from '../socket'
-import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand } from '../users'
+import { AccountsCommand, BlocklistCommand, LoginCommand, NotificationsCommand, SubscriptionsCommand, UsersCommand } from '../users'
import {
BlacklistCommand,
CaptionsCommand,
@@ -127,6 +127,7 @@ interface ServerInfo {
notificationsCommand?: NotificationsCommand
serversCommand?: ServersCommand
loginCommand?: LoginCommand
+ usersCommand?: UsersCommand
}
function flushAndRunMultipleServers (totalServers: number, configOverride?: Object) {
@@ -359,6 +360,7 @@ function assignCommands (server: ServerInfo) {
server.notificationsCommand = new NotificationsCommand(server)
server.serversCommand = new ServersCommand(server)
server.loginCommand = new LoginCommand(server)
+ server.usersCommand = new UsersCommand(server)
}
async function reRunServer (server: ServerInfo, configOverride?: any) {
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
index b200ae705e..e6107afa53 100644
--- a/shared/extra-utils/users/index.ts
+++ b/shared/extra-utils/users/index.ts
@@ -6,4 +6,5 @@ export * from './login-command'
export * from './notifications'
export * from './notifications-command'
export * from './subscriptions-command'
+export * from './users-command'
export * from './users'
diff --git a/shared/extra-utils/users/login-command.ts b/shared/extra-utils/users/login-command.ts
index 8af3531f97..b4e3bb602c 100644
--- a/shared/extra-utils/users/login-command.ts
+++ b/shared/extra-utils/users/login-command.ts
@@ -7,7 +7,7 @@ export class LoginCommand extends AbstractCommand {
login (options: OverrideCommandOptions & {
client?: { id?: string, secret?: string }
- user?: { username: string, password: string }
+ user?: { username: string, password?: string }
} = {}) {
const { client = this.server.client, user = this.server.user } = options
const path = '/api/v1/users/token'
@@ -16,7 +16,7 @@ export class LoginCommand extends AbstractCommand {
client_id: client.id,
client_secret: client.secret,
username: user.username,
- password: user.password,
+ password: user.password ?? 'password',
response_type: 'code',
grant_type: 'password',
scope: 'upload'
@@ -33,10 +33,10 @@ export class LoginCommand extends AbstractCommand {
}))
}
- getAccessToken (arg1?: { username: string, password: string }): Promise<string>
- getAccessToken (arg1: string, password: string): Promise<string>
- async getAccessToken (arg1?: { username: string, password: string } | string, password?: string) {
- let user: { username: string, password: string }
+ getAccessToken (arg1?: { username: string, password?: string }): Promise<string>
+ getAccessToken (arg1: string, password?: string): Promise<string>
+ async getAccessToken (arg1?: { username: string, password?: string } | string, password?: string) {
+ let user: { username: string, password?: string }
if (!arg1) user = this.server.user
else if (typeof arg1 === 'object') user = arg1
diff --git a/shared/extra-utils/users/notifications.ts b/shared/extra-utils/users/notifications.ts
index 79cb6f6170..0af7d8a18c 100644
--- a/shared/extra-utils/users/notifications.ts
+++ b/shared/extra-utils/users/notifications.ts
@@ -8,7 +8,6 @@ import { MockSmtpServer } from '../mock-servers/mock-email'
import { doubleFollow } from '../server/follows'
import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
import { setAccessTokensToServers } from './login'
-import { createUser, getMyUserInformation } from './users'
function getAllNotificationsSettings (): UserNotificationSetting {
return {
@@ -651,17 +650,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
await doubleFollow(servers[0], servers[1])
}
- const user = {
- username: 'user_1',
- password: 'super password'
- }
- await createUser({
- url: servers[0].url,
- accessToken: servers[0].accessToken,
- username: user.username,
- password: user.password,
- videoQuota: 10 * 1000 * 1000
- })
+ const user = { username: 'user_1', password: 'super password' }
+ await servers[0].usersCommand.create({ ...user, videoQuota: 10 * 1000 * 1000 })
const userAccessToken = await servers[0].loginCommand.getAccessToken(user)
await servers[0].notificationsCommand.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
@@ -685,8 +675,8 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
socket.on('new-notification', n => adminNotificationsServer2.push(n))
}
- const resChannel = await getMyUserInformation(servers[0].url, servers[0].accessToken)
- const channelId = resChannel.body.videoChannels[0].id
+ const { videoChannels } = await servers[0].usersCommand.getMyInfo()
+ const channelId = videoChannels[0].id
return {
userNotifications,
diff --git a/shared/extra-utils/users/users-command.ts b/shared/extra-utils/users/users-command.ts
new file mode 100644
index 0000000000..202528b8d3
--- /dev/null
+++ b/shared/extra-utils/users/users-command.ts
@@ -0,0 +1,414 @@
+import { omit, pick } from 'lodash'
+import { HttpStatusCode } from '@shared/core-utils'
+import {
+ MyUser,
+ ResultList,
+ User,
+ UserAdminFlag,
+ UserCreateResult,
+ UserRole,
+ UserUpdate,
+ UserUpdateMe,
+ UserVideoQuota,
+ UserVideoRate
+} from '@shared/models'
+import { ScopedToken } from '@shared/models/users/user-scoped-token'
+import { unwrapBody } from '../requests'
+import { AbstractCommand, OverrideCommandOptions } from '../shared'
+
+export class UsersCommand extends AbstractCommand {
+
+ askResetPassword (options: OverrideCommandOptions & {
+ email: string
+ }) {
+ const { email } = options
+ const path = '/api/v1/users/ask-reset-password'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: { email },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ resetPassword (options: OverrideCommandOptions & {
+ userId: number
+ verificationString: string
+ password: string
+ }) {
+ const { userId, verificationString, password } = options
+ const path = '/api/v1/users/' + userId + '/reset-password'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: { password, verificationString },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ askSendVerifyEmail (options: OverrideCommandOptions & {
+ email: string
+ }) {
+ const { email } = options
+ const path = '/api/v1/users/ask-send-verify-email'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: { email },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ verifyEmail (options: OverrideCommandOptions & {
+ userId: number
+ verificationString: string
+ isPendingEmail?: boolean // default false
+ }) {
+ const { userId, verificationString, isPendingEmail = false } = options
+ const path = '/api/v1/users/' + userId + '/verify-email'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: {
+ verificationString,
+ isPendingEmail
+ },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ banUser (options: OverrideCommandOptions & {
+ userId: number
+ reason?: string
+ }) {
+ const { userId, reason } = options
+ const path = '/api/v1/users' + '/' + userId + '/block'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: { reason },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ unbanUser (options: OverrideCommandOptions & {
+ userId: number
+ }) {
+ const { userId } = options
+ const path = '/api/v1/users' + '/' + userId + '/unblock'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ getMyScopedTokens (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/users/scoped-tokens'
+
+ return this.getRequestBody<ScopedToken>({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ renewMyScopedTokens (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/users/scoped-tokens'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ create (options: OverrideCommandOptions & {
+ username: string
+ password?: string
+ videoQuota?: number
+ videoQuotaDaily?: number
+ role?: UserRole
+ adminFlags?: UserAdminFlag
+ }) {
+ const {
+ username,
+ adminFlags,
+ password = 'password',
+ videoQuota = 42000000,
+ videoQuotaDaily = -1,
+ role = UserRole.USER
+ } = options
+
+ const path = '/api/v1/users'
+
+ return unwrapBody<{ user: UserCreateResult }>(this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: {
+ username,
+ password,
+ role,
+ adminFlags,
+ email: username + '@example.com',
+ videoQuota,
+ videoQuotaDaily
+ },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })).then(res => res.user)
+ }
+
+ async generate (username: string) {
+ const password = 'password'
+ const user = await this.create({ username, password })
+
+ const token = await this.server.loginCommand.getAccessToken({ username, password })
+
+ const me = await this.getMyInfo({ token })
+
+ return {
+ token,
+ userId: user.id,
+ userChannelId: me.videoChannels[0].id
+ }
+ }
+
+ async generateUserAndToken (username: string) {
+ const password = 'password'
+ await this.create({ username, password })
+
+ return this.server.loginCommand.getAccessToken({ username, password })
+ }
+
+ register (options: OverrideCommandOptions & {
+ username: string
+ password?: string
+ displayName?: string
+ channel?: {
+ name: string
+ displayName: string
+ }
+ }) {
+ const { username, password = 'password', displayName, channel } = options
+ const path = '/api/v1/users/register'
+
+ return this.postBodyRequest({
+ ...options,
+
+ path,
+ fields: {
+ username,
+ password,
+ email: username + '@example.com',
+ displayName,
+ channel
+ },
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ getMyInfo (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/users/me'
+
+ return this.getRequestBody<MyUser>({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getMyQuotaUsed (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/users/me/video-quota-used'
+
+ return this.getRequestBody<UserVideoQuota>({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getMyRating (options: OverrideCommandOptions & {
+ videoId: number | string
+ }) {
+ const { videoId } = options
+ const path = '/api/v1/users/me/videos/' + videoId + '/rating'
+
+ return this.getRequestBody<UserVideoRate>({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ deleteMe (options: OverrideCommandOptions = {}) {
+ const path = '/api/v1/users/me'
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ updateMe (options: OverrideCommandOptions & UserUpdateMe) {
+ const path = '/api/v1/users/me'
+
+ const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
+
+ return this.putBodyRequest({
+ ...options,
+
+ path,
+ fields: toSend,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ updateMyAvatar (options: OverrideCommandOptions & {
+ fixture: string
+ }) {
+ const { fixture } = options
+ const path = '/api/v1/users/me/avatar/pick'
+
+ return this.updateImageRequest({
+ ...options,
+
+ path,
+ fixture,
+ fieldname: 'avatarfile',
+
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ get (options: OverrideCommandOptions & {
+ userId: number
+ withStats?: boolean // default false
+ }) {
+ const { userId, withStats } = options
+ const path = '/api/v1/users/' + userId
+
+ return this.getRequestBody<User>({
+ ...options,
+
+ path,
+ query: { withStats },
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ list (options: OverrideCommandOptions & {
+ start?: number
+ count?: number
+ sort?: string
+ search?: string
+ blocked?: boolean
+ } = {}) {
+ const path = '/api/v1/users'
+
+ return this.getRequestBody<ResultList<User>>({
+ ...options,
+
+ path,
+ query: pick(options, [ 'start', 'count', 'sort', 'search', 'blocked' ]),
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ remove (options: OverrideCommandOptions & {
+ userId: number
+ }) {
+ const { userId } = options
+ const path = '/api/v1/users/' + userId
+
+ return this.deleteRequest({
+ ...options,
+
+ path,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+
+ update (options: OverrideCommandOptions & {
+ userId: number
+ email?: string
+ emailVerified?: boolean
+ videoQuota?: number
+ videoQuotaDaily?: number
+ password?: string
+ adminFlags?: UserAdminFlag
+ pluginAuth?: string
+ role?: UserRole
+ }) {
+ const path = '/api/v1/users/' + options.userId
+
+ const toSend: UserUpdate = {}
+ if (options.password !== undefined && options.password !== null) toSend.password = options.password
+ if (options.email !== undefined && options.email !== null) toSend.email = options.email
+ if (options.emailVerified !== undefined && options.emailVerified !== null) toSend.emailVerified = options.emailVerified
+ if (options.videoQuota !== undefined && options.videoQuota !== null) toSend.videoQuota = options.videoQuota
+ if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend.videoQuotaDaily = options.videoQuotaDaily
+ if (options.role !== undefined && options.role !== null) toSend.role = options.role
+ if (options.adminFlags !== undefined && options.adminFlags !== null) toSend.adminFlags = options.adminFlags
+ if (options.pluginAuth !== undefined) toSend.pluginAuth = options.pluginAuth
+
+ return this.putBodyRequest({
+ ...options,
+
+ path,
+ fields: toSend,
+ implicitToken: true,
+ defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ }
+}
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index 835ad08ba6..6cf61d60e0 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -1,118 +1,8 @@
-import { omit } from 'lodash'
import * as request from 'supertest'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
-import { UserUpdateMe } from '../../models/users'
-import { UserAdminFlag } from '../../models/users/user-flag.model'
-import { UserRegister } from '../../models/users/user-register.model'
-import { UserRole } from '../../models/users/user-role'
-import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests'
-import { ServerInfo } from '../server/servers'
-function createUser (parameters: {
- url: string
- accessToken: string
- username: string
- password: string
- videoQuota?: number
- videoQuotaDaily?: number
- role?: UserRole
- adminFlags?: UserAdminFlag
- specialStatus?: number
-}) {
- const {
- url,
- accessToken,
- username,
- adminFlags,
- password = 'password',
- videoQuota = 1000000,
- videoQuotaDaily = -1,
- role = UserRole.USER,
- specialStatus = HttpStatusCode.OK_200
- } = parameters
-
- const path = '/api/v1/users'
- const body = {
- username,
- password,
- role,
- adminFlags,
- email: username + '@example.com',
- videoQuota,
- videoQuotaDaily
- }
-
- return request(url)
- .post(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .send(body)
- .expect(specialStatus)
-}
-
-async function generateUser (server: ServerInfo, username: string) {
- const password = 'my super password'
- const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
-
- const token = await server.loginCommand.getAccessToken({ username, password })
-
- const resMe = await getMyUserInformation(server.url, token)
-
- return {
- token,
- userId: resCreate.body.user.id,
- userChannelId: resMe.body.videoChannels[0].id
- }
-}
-
-async function generateUserAccessToken (server: ServerInfo, username: string) {
- const password = 'my super password'
- await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
-
- return server.loginCommand.getAccessToken({ username, password })
-}
-
-function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/users/register'
- const body = {
- username,
- password,
- email: username + '@example.com'
- }
-
- return request(url)
- .post(path)
- .set('Accept', 'application/json')
- .send(body)
- .expect(specialStatus)
-}
-
-function registerUserWithChannel (options: {
- url: string
- user: { username: string, password: string, displayName?: string }
- channel: { name: string, displayName: string }
-}) {
- const path = '/api/v1/users/register'
- const body: UserRegister = {
- username: options.user.username,
- password: options.user.password,
- email: options.user.username + '@example.com',
- channel: options.channel
- }
-
- if (options.user.displayName) {
- Object.assign(body, { displayName: options.user.displayName })
- }
-
- return makePostBodyRequest({
- url: options.url,
- path,
- fields: body,
- statusCodeExpected: HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function getMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
+// FIXME: delete once videos does not use it anymore
+function xxxgetMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
const path = '/api/v1/users/me'
return request(url)
@@ -123,292 +13,8 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus =
.expect('Content-Type', /json/)
}
-function getUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
- const path = '/api/v1/users/scoped-tokens'
-
- return makeGetRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-function renewUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
- const path = '/api/v1/users/scoped-tokens'
-
- return makePostBodyRequest({
- url,
- path,
- token,
- statusCodeExpected
- })
-}
-
-function deleteMe (url: string, accessToken: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/users/me'
-
- return request(url)
- .delete(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(specialStatus)
-}
-
-function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
- const path = '/api/v1/users/me/video-quota-used'
-
- return request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(specialStatus)
- .expect('Content-Type', /json/)
-}
-
-function getUserInformation (url: string, accessToken: string, userId: number, withStats = false) {
- const path = '/api/v1/users/' + userId
-
- return request(url)
- .get(path)
- .query({ withStats })
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = HttpStatusCode.OK_200) {
- const path = '/api/v1/users/me/videos/' + videoId + '/rating'
-
- return request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(specialStatus)
- .expect('Content-Type', /json/)
-}
-
-function getUsersList (url: string, accessToken: string) {
- const path = '/api/v1/users'
-
- return request(url)
- .get(path)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function getUsersListPaginationAndSort (
- url: string,
- accessToken: string,
- start: number,
- count: number,
- sort: string,
- search?: string,
- blocked?: boolean
-) {
- const path = '/api/v1/users'
-
- const query = {
- start,
- count,
- sort,
- search,
- blocked
- }
-
- return request(url)
- .get(path)
- .query(query)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(HttpStatusCode.OK_200)
- .expect('Content-Type', /json/)
-}
-
-function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/users'
-
- return request(url)
- .delete(path + '/' + userId)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(expectedStatus)
-}
-
-function blockUser (
- url: string,
- userId: number | string,
- accessToken: string,
- expectedStatus = HttpStatusCode.NO_CONTENT_204,
- reason?: string
-) {
- const path = '/api/v1/users'
- let body: any
- if (reason) body = { reason }
-
- return request(url)
- .post(path + '/' + userId + '/block')
- .send(body)
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(expectedStatus)
-}
-
-function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
- const path = '/api/v1/users'
-
- return request(url)
- .post(path + '/' + userId + '/unblock')
- .set('Accept', 'application/json')
- .set('Authorization', 'Bearer ' + accessToken)
- .expect(expectedStatus)
-}
-
-function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: HttpStatusCode } & UserUpdateMe) {
- const path = '/api/v1/users/me'
-
- const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
-
- return makePutBodyRequest({
- url: options.url,
- path,
- token: options.accessToken,
- fields: toSend,
- statusCodeExpected: options.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function updateMyAvatar (options: {
- url: string
- accessToken: string
- fixture: string
-}) {
- const path = '/api/v1/users/me/avatar/pick'
-
- return updateImageRequest({ ...options, path, fieldname: 'avatarfile' })
-}
-
-function updateUser (options: {
- url: string
- userId: number
- accessToken: string
- email?: string
- emailVerified?: boolean
- videoQuota?: number
- videoQuotaDaily?: number
- password?: string
- adminFlags?: UserAdminFlag
- pluginAuth?: string
- role?: UserRole
-}) {
- const path = '/api/v1/users/' + options.userId
-
- const toSend = {}
- if (options.password !== undefined && options.password !== null) toSend['password'] = options.password
- if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
- if (options.emailVerified !== undefined && options.emailVerified !== null) toSend['emailVerified'] = options.emailVerified
- if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
- if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
- if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
- if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags
- if (options.pluginAuth !== undefined) toSend['pluginAuth'] = options.pluginAuth
-
- return makePutBodyRequest({
- url: options.url,
- path,
- token: options.accessToken,
- fields: toSend,
- statusCodeExpected: HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function askResetPassword (url: string, email: string) {
- const path = '/api/v1/users/ask-reset-password'
-
- return makePostBodyRequest({
- url,
- path,
- fields: { email },
- statusCodeExpected: HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function resetPassword (
- url: string,
- userId: number,
- verificationString: string,
- password: string,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/' + userId + '/reset-password'
-
- return makePostBodyRequest({
- url,
- path,
- fields: { password, verificationString },
- statusCodeExpected
- })
-}
-
-function askSendVerifyEmail (url: string, email: string) {
- const path = '/api/v1/users/ask-send-verify-email'
-
- return makePostBodyRequest({
- url,
- path,
- fields: { email },
- statusCodeExpected: HttpStatusCode.NO_CONTENT_204
- })
-}
-
-function verifyEmail (
- url: string,
- userId: number,
- verificationString: string,
- isPendingEmail = false,
- statusCodeExpected = HttpStatusCode.NO_CONTENT_204
-) {
- const path = '/api/v1/users/' + userId + '/verify-email'
-
- return makePostBodyRequest({
- url,
- path,
- fields: {
- verificationString,
- isPendingEmail
- },
- statusCodeExpected
- })
-}
-
// ---------------------------------------------------------------------------
export {
- createUser,
- registerUser,
- getMyUserInformation,
- getMyUserVideoRating,
- deleteMe,
- registerUserWithChannel,
- getMyUserVideoQuotaUsed,
- getUsersList,
- getUsersListPaginationAndSort,
- removeUser,
- updateUser,
- updateMyUser,
- getUserInformation,
- blockUser,
- unblockUser,
- askResetPassword,
- resetPassword,
- renewUserScopedTokens,
- updateMyAvatar,
- generateUser,
- askSendVerifyEmail,
- generateUserAccessToken,
- verifyEmail,
- getUserScopedTokens
+ xxxgetMyUserInformation
}
diff --git a/shared/extra-utils/videos/channels.ts b/shared/extra-utils/videos/channels.ts
index a77543c92e..9e7ec565d2 100644
--- a/shared/extra-utils/videos/channels.ts
+++ b/shared/extra-utils/videos/channels.ts
@@ -1,13 +1,11 @@
-import { User } from '../../models/users/user.model'
import { ServerInfo } from '../server/servers'
-import { getMyUserInformation } from '../users/users'
function setDefaultVideoChannel (servers: ServerInfo[]) {
const tasks: Promise<any>[] = []
for (const server of servers) {
- const p = getMyUserInformation(server.url, server.accessToken)
- .then(res => { server.videoChannel = (res.body as User).videoChannels[0] })
+ const p = server.usersCommand.getMyInfo()
+ .then(user => { server.videoChannel = user.videoChannels[0] })
tasks.push(p)
}
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 5dd71ce8bf..5e20f8010c 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -17,7 +17,7 @@ import { buildAbsoluteFixturePath, dateIsValid, testImage, wait, webtorrentAdd }
import { makeGetRequest, makePutBodyRequest, makeRawRequest, makeUploadRequest } from '../requests/requests'
import { waitJobs } from '../server/jobs'
import { ServerInfo } from '../server/servers'
-import { getMyUserInformation } from '../users/users'
+import { xxxgetMyUserInformation } from '../users'
loadLanguages()
@@ -339,7 +339,7 @@ async function uploadVideo (
let defaultChannelId = '1'
try {
- const res = await getMyUserInformation(url, accessToken)
+ const res = await xxxgetMyUserInformation(url, accessToken)
defaultChannelId = res.body.videoChannels[0].id
} catch (e) { /* empty */ }
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts
index a9d5780540..b61a8cd40a 100644
--- a/shared/models/users/index.ts
+++ b/shared/models/users/index.ts
@@ -1,3 +1,4 @@
+export * from './user-create-result.model'
export * from './user-create.model'
export * from './user-flag.model'
export * from './user-login.model'
diff --git a/shared/models/users/user-create-result.model.ts b/shared/models/users/user-create-result.model.ts
new file mode 100644
index 0000000000..835b241ed4
--- /dev/null
+++ b/shared/models/users/user-create-result.model.ts
@@ -0,0 +1,7 @@
+export interface UserCreateResult {
+ id: number
+
+ account: {
+ id: number
+ }
+}