makePutBodyRequest,
createUser,
loginAndGetAccessToken,
- getUserInformation,
+ getMyUserInformation,
getUsersList,
getUsersListPaginationAndSort,
updateUser,
+ updateMyUser,
registerUser,
- removeUser
+ removeUser,
+ killallServers,
+ getUserInformation,
+ getBlacklistedVideosList
} from '../utils'
-import { killallServers } from '../utils/servers'
+import { UserRole } from '../../../shared'
+import { getMyVideos } from '../utils/videos'
describe('Test users', function () {
let server: ServerInfo
})
it('Should not login with an invalid password', async function () {
- const user = { username: server.user.username, password: 'mewthree' }
+ const user = { username: server.user.username, password: 'mew_three' }
const res = await login(server.url, server.client, user, 400)
expect(res.body.error).to.equal('invalid_grant')
it('Should be able to upload a video again')
it('Should be able to create a new user', async function () {
- await createUser(server.url, accessToken, 'user_1', 'super password')
+ await createUser(server.url, accessToken, 'user_1', 'super password', 2 * 1024 * 1024)
})
it('Should be able to login with this user', async function () {
})
it('Should be able to get the user information', async function () {
- const res = await getUserInformation(server.url, accessTokenUser)
+ const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body
expect(user.username).to.equal('user_1')
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')
})
it('Should be able to upload a video with this user', async function () {
this.timeout(5000)
- const videoAttributes = {}
+ const videoAttributes = {
+ name: 'super user video'
+ }
await uploadVideo(server.url, accessTokenUser, videoAttributes)
})
+ it('Should be able to list my videos', async function () {
+ const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
+ expect(res.body.total).to.equal(1)
+
+ const videos = res.body.data
+ expect(videos).to.have.lengthOf(1)
+
+ expect(videos[0].name).to.equal('super user video')
+ })
+
it('Should list all the users', async function () {
const res = await getUsersList(server.url)
const result = res.body
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
})
expect(users[1].displayNSFW).to.be.false
})
- it('Should update the user password', async function () {
- await updateUser(server.url, userId, accessTokenUser, 'new password', null)
+ it('Should update my password', async function () {
+ await updateMyUser(server.url, accessTokenUser, 'new password')
server.user.password = 'new password'
await login(server.url, server.client, server.user, 200)
})
it('Should be able to change the NSFW display attribute', async function () {
- await updateUser(server.url, userId, accessTokenUser, null, true)
+ await updateMyUser(server.url, accessTokenUser, undefined, true)
- const res = await getUserInformation(server.url, accessTokenUser)
+ const res = await getMyUserInformation(server.url, accessTokenUser)
const user = res.body
expect(user.username).to.equal('user_1')
expect(user.email).to.equal('user_1@example.com')
expect(user.displayNSFW).to.be.ok
+ expect(user.videoQuota).to.equal(2 * 1024 * 1024)
+ expect(user.id).to.be.a('number')
+ })
+
+ it('Should be able to change the email display attribute', async function () {
+ await updateMyUser(server.url, accessTokenUser, undefined, undefined, 'updated@example.com')
+
+ const res = await getMyUserInformation(server.url, accessTokenUser)
+ const user = res.body
+
+ expect(user.username).to.equal('user_1')
+ expect(user.email).to.equal('updated@example.com')
+ expect(user.displayNSFW).to.be.ok
+ expect(user.videoQuota).to.equal(2 * 1024 * 1024)
expect(user.id).to.be.a('number')
})
+ it('Should be able to update another user', async function () {
+ 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.username).to.equal('user_1')
+ 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)
})
password: 'my super password'
}
- await loginAndGetAccessToken(server)
+ accessToken = await loginAndGetAccessToken(server)
+ })
+
+ it('Should have the correct video quota', async function () {
+ const res = await getMyUserInformation(server.url, accessToken)
+ const user = res.body
+
+ expect(user.videoQuota).to.equal(5 * 1024 * 1024)
})
after(async function () {