makePostBodyRequest,
getUserAccessToken
} from '../../utils'
+import { UserRole } from '../../../../shared'
describe('Test users API validators', function () {
const path = '/api/v1/users/'
username: 'ji',
email: 'test@example.com',
password: 'my_super_password',
+ role: UserRole.USER,
videoQuota: 42000000
}
username: 'my_super_username_which_is_very_long',
email: 'test@example.com',
password: 'my_super_password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'my username',
email: 'test@example.com',
password: 'my_super_password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
const fields = {
username: 'ji',
password: 'my_super_password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'my_super_username_which_is_very_long',
email: 'test_example.com',
password: 'my_super_password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'my_username',
email: 'test@example.com',
password: 'bla',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
password: 'my super long password which is very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very veryv very very very very' +
'very very very very very very very very very very very very very very very very very very very very long',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'my_username',
email: 'test@example.com',
password: 'my super password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: 'super token', fields, statusCodeExpected: 401 })
username: 'user1',
email: 'test@example.com',
password: 'my super password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
username: 'my_username',
email: 'user1@example.com',
password: 'my super password',
- videoQuota: 42000000
+ videoQuota: 42000000,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
const fields = {
username: 'my_username',
email: 'user1@example.com',
- password: 'my super password'
+ password: 'my super password',
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'my_username',
email: 'user1@example.com',
password: 'my super password',
- videoQuota: -5
+ videoQuota: -5,
+ role: UserRole.USER
+ }
+
+ await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+ })
+
+ it('Should fail without a user role', async function () {
+ const fields = {
+ username: 'my_username',
+ email: 'user1@example.com',
+ password: 'my super password',
+ videoQuota: 0
+ }
+
+ await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+ })
+
+ it('Should fail with an invalid user role', async function () {
+ const fields = {
+ username: 'my_username',
+ email: 'user1@example.com',
+ password: 'my super password',
+ videoQuota: 0,
+ role: 88989
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
username: 'user2',
email: 'test@example.com',
password: 'my super password',
- videoQuota: -1
+ videoQuota: -1,
+ role: UserRole.USER
}
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 })
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
})
+ it('Should fail with an invalid user role attribute', async function () {
+ const fields = {
+ role: 54878
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
+ })
+
it('Should fail with an non authenticated user', async function () {
const fields = {
videoQuota: 42
it('Should succeed with the correct params', async function () {
const fields = {
email: 'email@example.com',
- videoQuota: 42
+ videoQuota: 42,
+ role: UserRole.MODERATOR
}
await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
updateUser,
updateMyUser,
registerUser,
- removeUser
+ removeUser,
+ killallServers,
+ getUserInformation,
+ getBlacklistedVideosList
} from '../utils'
-import { killallServers } from '../utils/servers'
-import { getUserInformation } from '../utils/users'
+import { UserRole } from '../../../shared'
describe('Test users', function () {
let server: ServerInfo
expect(user.email).to.equal('user_1@example.com')
expect(user.displayNSFW).to.be.false
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
+ expect(user.roleLabel).to.equal('User')
expect(user.id).to.be.a('number')
})
const user = users[0]
expect(user.username).to.equal('root')
expect(user.email).to.equal('admin1@example.com')
+ expect(user.roleLabel).to.equal('Administrator')
expect(user.displayNSFW).to.be.false
})
})
it('Should be able to update another user', async function () {
- await updateUser(server.url, userId, accessToken, 'updated2@example.com', 42)
+ await updateUser(server.url, userId, accessToken, 'updated2@example.com', 42, UserRole.MODERATOR)
const res = await getUserInformation(server.url, accessToken, userId)
const user = res.body
expect(user.email).to.equal('updated2@example.com')
expect(user.displayNSFW).to.be.ok
expect(user.videoQuota).to.equal(42)
+ expect(user.roleLabel).to.equal('Moderator')
expect(user.id).to.be.a('number')
})
+ it('Should not be able to delete a user by a moderator', async function () {
+ await removeUser(server.url, 2, accessTokenUser, 403)
+ })
+
+ it('Should be able to list video blacklist by a moderator', async function () {
+ await getBlacklistedVideosList(server.url, accessTokenUser)
+ })
+
it('Should be able to remove this user', async function () {
await removeUser(server.url, userId, accessToken)
})
import * as request from 'supertest'
-function createUser (url: string, accessToken: string, username: string, password: string, videoQuota = 1000000, specialStatus = 204) {
+import { UserRole } from '../../../shared'
+
+function createUser (
+ url: string,
+ accessToken: string,
+ username: string,
+ password: string,
+ videoQuota = 1000000,
+ role: UserRole = UserRole.USER,
+ specialStatus = 204
+) {
const path = '/api/v1/users'
const body = {
username,
password,
+ role,
email: username + '@example.com',
videoQuota
}
.expect(204)
}
-function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number) {
+function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number, role: UserRole) {
const path = '/api/v1/users/' + userId
const toSend = {}
if (email !== undefined && email !== null) toSend['email'] = email
if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota
+ if (role !== undefined && role !== null) toSend['role'] = role
return request(url)
.put(path)