X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fusers.ts;h=6f40ca3c98028f791feef2fa1de2cef3c7157043;hb=571389d43b8fc8aaf27e77c06f19b320b08dbbc9;hp=fd3b511233aafb96e82f960afcc1d39e27d5e9f3;hpb=0e1dc3e7c69995c691e1dd82e3c2bc68748661ca;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/users.ts b/server/tests/api/users.ts index fd3b51123..6f40ca3c9 100644 --- a/server/tests/api/users.ts +++ b/server/tests/api/users.ts @@ -19,14 +19,19 @@ import { 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 @@ -70,7 +75,7 @@ describe('Test users', function () { }) 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') @@ -166,7 +171,7 @@ describe('Test users', function () { 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 () { @@ -179,22 +184,36 @@ describe('Test users', 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 @@ -231,6 +250,7 @@ describe('Test users', function () { 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 }) @@ -282,25 +302,61 @@ describe('Test users', function () { 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) }) @@ -329,7 +385,14 @@ describe('Test users', function () { 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 () {