Verified Commit 7926c5f9 authored by Chocobozzz's avatar Chocobozzz
Browse files

Introduce user command

parent d0a0fa42
......@@ -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
})
}
......
......@@ -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)
......
......@@ -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' })
}
......
......@@ -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
......
......@@ -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)
......
......@@ -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)
})
......
......@@ -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)
})
......
......@@ -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)
})
......
......@@ -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)
})
......
......@@ -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)
})
......
......@@ -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)
})
......
......@@ -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 }
......
......@@ -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)
})
......
......@@ -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)
{
......
......@@ -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
......
......@@ -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
})
......
......@@ -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)
})
......
This diff is collapsed.
......@@ -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 })
}
......
......@@ -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)
}
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment