PeerTube/server/tests/api/users/users.ts

542 lines
19 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2022-08-17 15:44:32 +02:00
import { expect } from 'chai'
import { testImage } from '@server/tests/shared'
import { AbuseState, HttpStatusCode, UserAdminFlag, UserRole, VideoPlaylistType } from '@shared/models'
import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
2017-09-04 21:21:47 +02:00
describe('Test users', function () {
2021-07-16 09:47:51 +02:00
let server: PeerTubeServer
2021-07-15 10:02:54 +02:00
let token: string
let userToken: string
2017-09-04 21:21:47 +02:00
let videoId: number
let userId: number
const user = {
username: 'user_1',
password: 'super password'
}
2017-09-04 21:21:47 +02:00
before(async function () {
2018-01-18 18:10:45 +01:00
this.timeout(30000)
2021-07-16 09:47:51 +02:00
server = await createSingleServer(1, {
rates_limit: {
login: {
max: 30
}
}
})
await setAccessTokensToServers([ server ])
2019-07-19 10:37:35 +02:00
2021-07-16 09:04:35 +02:00
await server.plugins.install({ npmName: 'peertube-theme-background-red' })
2017-09-04 21:21:47 +02:00
})
2019-04-15 10:49:46 +02:00
describe('Creating a user', function () {
2018-01-08 12:53:09 +01:00
2019-04-15 10:49:46 +02:00
it('Should be able to create a new user', async function () {
2021-07-16 09:04:35 +02:00
await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
2019-04-15 10:49:46 +02:00
})
2018-08-14 17:56:51 +02:00
2019-04-15 10:49:46 +02:00
it('Should be able to login with this user', async function () {
2021-07-16 09:04:35 +02:00
userToken = await server.login.getAccessToken(user)
2019-04-15 10:49:46 +02:00
})
2018-08-14 17:56:51 +02:00
2019-04-15 10:49:46 +02:00
it('Should be able to get user information', async function () {
2021-07-16 09:04:35 +02:00
const userMe = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
2021-07-16 09:04:35 +02:00
const userGet = await server.users.get({ userId: userMe.id, withStats: true })
2019-04-15 10:49:46 +02:00
for (const user of [ userMe, userGet ]) {
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display')
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.role.label).to.equal('User')
2019-04-15 10:49:46 +02:00
expect(user.id).to.be.a('number')
expect(user.account.displayName).to.equal('user_1')
expect(user.account.description).to.be.null
}
expect(userMe.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
expect(userMe.specialPlaylists).to.have.lengthOf(1)
expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
// Check stats are included with withStats
expect(userGet.videosCount).to.be.a('number')
expect(userGet.videosCount).to.equal(0)
expect(userGet.videoCommentsCount).to.be.a('number')
expect(userGet.videoCommentsCount).to.equal(0)
2020-07-07 14:34:16 +02:00
expect(userGet.abusesCount).to.be.a('number')
expect(userGet.abusesCount).to.equal(0)
expect(userGet.abusesAcceptedCount).to.be.a('number')
expect(userGet.abusesAcceptedCount).to.equal(0)
2019-04-15 10:49:46 +02:00
})
2018-01-08 12:53:09 +01:00
})
2019-04-15 10:49:46 +02:00
describe('Users listing', function () {
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should list all the users', async function () {
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list()
2017-11-17 11:35:10 +01:00
2019-04-15 10:49:46 +02:00
expect(total).to.equal(2)
2021-07-13 14:23:01 +02:00
expect(data).to.be.an('array')
expect(data.length).to.equal(2)
2017-09-04 21:21:47 +02:00
2021-07-13 14:23:01 +02:00
const user = data[0]
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display')
2017-09-04 21:21:47 +02:00
2021-07-13 14:23:01 +02:00
const rootUser = data[1]
2019-04-15 10:49:46 +02:00
expect(rootUser.username).to.equal('root')
2019-04-26 08:50:52 +02:00
expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
2019-04-15 10:49:46 +02:00
expect(user.nsfwPolicy).to.equal('display')
2017-11-17 11:35:10 +01:00
2020-05-07 10:39:09 +02:00
expect(rootUser.lastLoginDate).to.exist
expect(user.lastLoginDate).to.exist
2019-04-15 10:49:46 +02:00
userId = user.id
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should list only the first user by username asc', async function () {
2021-07-16 09:04:35 +02:00
const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' })
2017-12-29 10:04:15 +01:00
2019-04-15 10:49:46 +02:00
expect(total).to.equal(2)
2021-07-13 14:23:01 +02:00
expect(data.length).to.equal(1)
2017-11-17 11:35:10 +01:00
2021-07-13 14:23:01 +02:00
const user = data[0]
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('root')
2019-04-26 08:50:52 +02:00
expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
expect(user.role.label).to.equal('Administrator')
2019-04-15 10:49:46 +02:00
expect(user.nsfwPolicy).to.equal('display')
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should list only the first user by username desc', async function () {
2021-07-16 09:04:35 +02:00
const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' })
2018-10-08 15:51:38 +02:00
2019-04-15 10:49:46 +02:00
expect(total).to.equal(2)
2021-07-13 14:23:01 +02:00
expect(data.length).to.equal(1)
2018-10-08 15:51:38 +02:00
2021-07-13 14:23:01 +02:00
const user = data[0]
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display')
})
2018-10-08 15:51:38 +02:00
2019-04-15 10:49:46 +02:00
it('Should list only the second user by createdAt desc', async function () {
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' })
2019-04-15 10:49:46 +02:00
expect(total).to.equal(2)
2018-10-08 15:51:38 +02:00
2021-07-13 14:23:01 +02:00
expect(data.length).to.equal(1)
const user = data[0]
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('display')
})
2018-10-08 15:51:38 +02:00
2019-04-15 10:49:46 +02:00
it('Should list all the users by createdAt asc', async function () {
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' })
2018-10-08 15:51:38 +02:00
2019-04-15 10:49:46 +02:00
expect(total).to.equal(2)
2021-07-13 14:23:01 +02:00
expect(data.length).to.equal(2)
2018-10-08 15:51:38 +02:00
2021-07-13 14:23:01 +02:00
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')
2018-10-08 15:51:38 +02:00
2021-07-13 14:23:01 +02:00
expect(data[1].username).to.equal('user_1')
expect(data[1].email).to.equal('user_1@example.com')
expect(data[1].nsfwPolicy).to.equal('display')
2017-12-28 16:26:28 +01:00
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should search user by username', async function () {
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
2021-07-13 14:23:01 +02:00
expect(total).to.equal(1)
expect(data.length).to.equal(1)
expect(data[0].username).to.equal('root')
2017-12-28 16:26:28 +01:00
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should search user by email', async function () {
{
2021-07-16 09:04:35 +02:00
const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
2021-07-13 14:23:01 +02:00
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('user_1@example.com')
2019-04-15 10:49:46 +02:00
}
2019-04-15 10:49:46 +02:00
{
2021-07-16 09:04:35 +02:00
const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
2021-07-13 14:23:01 +02:00
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')
2019-04-15 10:49:46 +02:00
}
2017-12-28 16:26:28 +01:00
})
2017-09-05 22:09:16 +02:00
})
2019-04-15 10:49:46 +02:00
describe('Update my account', function () {
2021-07-13 11:05:15 +02:00
2019-04-15 10:49:46 +02:00
it('Should update my password', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
2019-04-15 10:49:46 +02:00
currentPassword: 'super password',
2019-08-28 14:40:06 +02:00
password: 'new password'
2019-04-15 10:49:46 +02:00
})
user.password = 'new password'
2017-12-29 19:10:13 +01:00
2021-07-16 09:04:35 +02:00
await server.login.login({ user })
2017-12-29 19:10:13 +01:00
})
2019-04-15 10:49:46 +02:00
it('Should be able to change the NSFW display attribute', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
2019-04-15 10:49:46 +02:00
nsfwPolicy: 'do_not_list'
})
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.id).to.be.a('number')
expect(user.account.displayName).to.equal('user_1')
expect(user.account.description).to.be.null
})
2017-12-29 19:10:13 +01:00
2019-04-15 10:49:46 +02:00
it('Should be able to change the autoPlayVideo attribute', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
2019-04-15 10:49:46 +02:00
autoPlayVideo: false
})
2017-12-29 19:10:13 +01:00
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
expect(user.autoPlayVideo).to.be.false
})
it('Should be able to change the autoPlayNextVideo attribute', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
autoPlayNextVideo: true
})
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
expect(user.autoPlayNextVideo).to.be.true
})
it('Should be able to change the p2p attribute', async function () {
{
await server.users.updateMe({
token: userToken,
webTorrentEnabled: false
})
const user = await server.users.getMyInfo({ token: userToken })
expect(user.p2pEnabled).to.be.false
}
{
await server.users.updateMe({
token: userToken,
p2pEnabled: true
})
const user = await server.users.getMyInfo({ token: userToken })
expect(user.p2pEnabled).to.be.true
}
})
2019-06-11 16:13:50 +02:00
it('Should be able to change the email attribute', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
2019-06-11 16:13:50 +02:00
currentPassword: 'new password',
2019-04-15 10:49:46 +02:00
email: 'updated@example.com'
})
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.id).to.be.a('number')
expect(user.account.displayName).to.equal('user_1')
expect(user.account.description).to.be.null
})
2020-11-25 09:50:12 +01:00
it('Should be able to update my avatar with a gif', async function () {
const fixture = 'avatar.gif'
2021-07-16 09:04:35 +02:00
await server.users.updateMyAvatar({ token: userToken, fixture })
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
for (const avatar of user.account.avatars) {
await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, '.gif')
}
2020-11-25 09:50:12 +01:00
})
it('Should be able to update my avatar with a gif, and then a png', async function () {
for (const extension of [ '.png', '.gif' ]) {
const fixture = 'avatar' + extension
2021-07-16 09:04:35 +02:00
await server.users.updateMyAvatar({ token: userToken, fixture })
2020-11-25 09:50:12 +01:00
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
for (const avatar of user.account.avatars) {
await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, extension)
}
2020-11-25 09:50:12 +01:00
}
2019-04-15 10:49:46 +02:00
})
it('Should be able to update my display name', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({ token: userToken, displayName: 'new display name' })
2019-04-15 10:49:46 +02:00
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.id).to.be.a('number')
expect(user.account.displayName).to.equal('new display name')
expect(user.account.description).to.be.null
})
2019-04-15 10:49:46 +02:00
it('Should be able to update my description', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({ token: userToken, description: 'my super description updated' })
2019-04-15 10:49:46 +02:00
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated@example.com')
expect(user.nsfwPolicy).to.equal('do_not_list')
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.id).to.be.a('number')
expect(user.account.displayName).to.equal('new display name')
expect(user.account.description).to.equal('my super description updated')
2019-08-28 14:40:06 +02:00
expect(user.noWelcomeModal).to.be.false
expect(user.noInstanceConfigWarningModal).to.be.false
expect(user.noAccountSetupWarningModal).to.be.false
2019-04-15 10:49:46 +02:00
})
2019-07-19 10:37:35 +02:00
it('Should be able to update my theme', async function () {
for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({ token: userToken, theme })
2019-07-19 10:37:35 +02:00
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2021-07-13 14:23:01 +02:00
expect(user.theme).to.equal(theme)
2019-07-19 10:37:35 +02:00
}
})
2019-08-28 14:40:06 +02:00
it('Should be able to update my modal preferences', async function () {
2021-07-16 09:04:35 +02:00
await server.users.updateMe({
2021-07-15 10:02:54 +02:00
token: userToken,
2019-08-28 14:40:06 +02:00
noInstanceConfigWarningModal: true,
noWelcomeModal: true,
noAccountSetupWarningModal: true
2019-08-28 14:40:06 +02:00
})
2021-07-16 09:04:35 +02:00
const user = await server.users.getMyInfo({ token: userToken })
2019-08-28 14:40:06 +02:00
expect(user.noWelcomeModal).to.be.true
expect(user.noInstanceConfigWarningModal).to.be.true
expect(user.noAccountSetupWarningModal).to.be.true
2019-08-28 14:40:06 +02:00
})
2017-09-04 21:21:47 +02:00
})
2019-04-15 10:49:46 +02:00
describe('Updating another user', function () {
2019-04-15 10:49:46 +02:00
it('Should be able to update another user', async function () {
2021-07-16 09:04:35 +02:00
await server.users.update({
2019-04-15 10:49:46 +02:00
userId,
2021-07-15 10:02:54 +02:00
token,
2019-04-15 10:49:46 +02:00
email: 'updated2@example.com',
emailVerified: true,
videoQuota: 42,
role: UserRole.MODERATOR,
2021-02-01 15:39:13 +01:00
adminFlags: UserAdminFlag.NONE,
pluginAuth: 'toto'
2019-04-15 10:49:46 +02:00
})
2021-07-16 09:04:35 +02:00
const user = await server.users.get({ token, userId })
2019-04-15 10:49:46 +02:00
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('updated2@example.com')
expect(user.emailVerified).to.be.true
expect(user.nsfwPolicy).to.equal('do_not_list')
expect(user.videoQuota).to.equal(42)
expect(user.role.label).to.equal('Moderator')
2019-04-15 10:49:46 +02:00
expect(user.id).to.be.a('number')
expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
2021-02-01 15:39:13 +01:00
expect(user.pluginAuth).to.equal('toto')
})
it('Should reset the auth plugin', async function () {
2021-07-16 09:04:35 +02:00
await server.users.update({ userId, token, pluginAuth: null })
2021-02-01 15:39:13 +01:00
2021-07-16 09:04:35 +02:00
const user = await server.users.get({ token, userId })
2021-02-01 15:39:13 +01:00
expect(user.pluginAuth).to.be.null
2019-04-15 10:49:46 +02:00
})
2019-04-15 10:49:46 +02:00
it('Should have removed the user token', async function () {
2021-07-16 09:04:35 +02:00
await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
2021-07-16 09:04:35 +02:00
userToken = await server.login.getAccessToken(user)
})
2019-04-15 10:49:46 +02:00
it('Should be able to update another user password', async function () {
2021-07-16 09:04:35 +02:00
await server.users.update({ userId, token, password: 'password updated' })
2021-07-16 09:04:35 +02:00
await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
2021-07-16 09:04:35 +02:00
await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
2019-04-15 10:49:46 +02:00
user.password = 'password updated'
2021-07-16 09:04:35 +02:00
userToken = await server.login.getAccessToken(user)
2019-04-15 10:49:46 +02:00
})
2017-10-27 17:27:06 +02:00
})
2019-04-15 10:49:46 +02:00
describe('Remove a user', function () {
2022-07-18 14:53:50 +02:00
before(async function () {
await server.users.update({
userId,
token,
videoQuota: 2 * 1024 * 1024
})
await server.videos.quickUpload({ name: 'user video', token: userToken, fixture: 'video_short.webm' })
await server.videos.quickUpload({ name: 'root video' })
const { total } = await server.videos.list()
expect(total).to.equal(2)
})
2019-04-15 10:49:46 +02:00
it('Should be able to remove this user', async function () {
2021-07-16 09:04:35 +02:00
await server.users.remove({ userId, token })
2019-04-15 10:49:46 +02:00
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should not be able to login with this user', async function () {
2021-07-16 09:04:35 +02:00
await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
2019-04-15 10:49:46 +02:00
})
2017-09-04 21:21:47 +02:00
2019-04-15 10:49:46 +02:00
it('Should not have videos of this user', async function () {
2021-07-16 09:04:35 +02:00
const { data, total } = await server.videos.list()
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
2017-09-04 21:21:47 +02:00
2021-07-15 10:02:54 +02:00
const video = data[0]
2019-04-15 10:49:46 +02:00
expect(video.account.name).to.equal('root')
})
2017-09-04 21:21:47 +02:00
})
2019-04-15 10:49:46 +02:00
describe('User blocking', function () {
let user16Id: number
let user16AccessToken: string
const user16 = {
username: 'user_16',
password: 'my super password'
}
it('Should block a user', async function () {
2021-07-16 09:04:35 +02:00
const user = await server.users.create({ ...user16 })
2021-07-13 14:23:01 +02:00
user16Id = user.id
2018-08-08 14:58:21 +02:00
2021-07-16 09:04:35 +02:00
user16AccessToken = await server.login.getAccessToken(user16)
2018-08-08 14:58:21 +02:00
2021-07-16 09:04:35 +02:00
await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
await server.users.banUser({ userId: user16Id })
2018-08-08 14:58:21 +02:00
2021-07-16 09:04:35 +02:00
await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
it('Should search user by banned status', async function () {
{
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
2021-07-13 14:23:01 +02:00
expect(total).to.equal(1)
expect(data.length).to.equal(1)
2021-07-13 14:23:01 +02:00
expect(data[0].username).to.equal(user16.username)
}
{
2021-07-16 09:04:35 +02:00
const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
2021-07-13 14:23:01 +02:00
expect(total).to.equal(1)
expect(data.length).to.equal(1)
2021-07-13 14:23:01 +02:00
expect(data[0].username).to.not.equal(user16.username)
}
})
2018-08-08 14:58:21 +02:00
it('Should unblock a user', async function () {
2021-07-16 09:04:35 +02:00
await server.users.unbanUser({ userId: user16Id })
user16AccessToken = await server.login.getAccessToken(user16)
await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
})
})
describe('User stats', function () {
2022-07-18 14:53:50 +02:00
let user17Id: number
let user17AccessToken: string
it('Should report correct initial statistics about a user', async function () {
const user17 = {
username: 'user_17',
password: 'my super password'
}
2021-07-16 09:04:35 +02:00
const created = await server.users.create({ ...user17 })
2021-07-13 14:23:01 +02:00
user17Id = created.id
2021-07-16 09:04:35 +02:00
user17AccessToken = await server.login.getAccessToken(user17)
2021-07-16 09:04:35 +02:00
const user = await server.users.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(0)
expect(user.videoCommentsCount).to.equal(0)
2020-07-07 14:34:16 +02:00
expect(user.abusesCount).to.equal(0)
expect(user.abusesCreatedCount).to.equal(0)
expect(user.abusesAcceptedCount).to.equal(0)
})
it('Should report correct videos count', async function () {
2021-07-15 10:02:54 +02:00
const attributes = { name: 'video to test user stats' }
2021-07-16 09:04:35 +02:00
await server.videos.upload({ token: user17AccessToken, attributes })
2021-07-15 10:02:54 +02:00
2021-07-16 09:04:35 +02:00
const { data } = await server.videos.list()
2021-07-15 10:02:54 +02:00
videoId = data.find(video => video.name === attributes.name).id
2021-07-16 09:04:35 +02:00
const user = await server.users.get({ userId: user17Id, withStats: true })
expect(user.videosCount).to.equal(1)
})
it('Should report correct video comments for user', async function () {
const text = 'super comment'
2021-07-16 09:04:35 +02:00
await server.comments.createThread({ token: user17AccessToken, videoId, text })
2021-07-16 09:04:35 +02:00
const user = await server.users.get({ userId: user17Id, withStats: true })
expect(user.videoCommentsCount).to.equal(1)
})
2020-07-07 14:34:16 +02:00
it('Should report correct abuses counts', async function () {
const reason = 'my super bad reason'
2021-07-16 09:04:35 +02:00
await server.abuses.report({ token: user17AccessToken, videoId, reason })
2021-07-16 09:04:35 +02:00
const body1 = await server.abuses.getAdminList()
2021-07-06 12:01:59 +02:00
const abuseId = body1.data[0].id
2021-07-16 09:04:35 +02:00
const user2 = await server.users.get({ userId: user17Id, withStats: true })
2020-07-07 14:34:16 +02:00
expect(user2.abusesCount).to.equal(1) // number of incriminations
expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
2021-07-16 09:04:35 +02:00
await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
2021-07-16 09:04:35 +02:00
const user3 = await server.users.get({ userId: user17Id, withStats: true })
2020-07-07 14:34:16 +02:00
expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
2019-04-15 10:49:46 +02:00
})
2018-08-08 14:58:21 +02:00
})
2019-04-24 15:10:37 +02:00
after(async function () {
await cleanupTests([ server ])
2017-09-04 21:21:47 +02:00
})
})