]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users.ts
Make it compile at least
[github/Chocobozzz/PeerTube.git] / server / tests / api / users.ts
index 04c68d4ea91dce6a2140bba1668cf6334d1695e2..6f40ca3c98028f791feef2fa1de2cef3c7157043 100644 (file)
@@ -25,10 +25,13 @@ import {
   updateUser,
   updateMyUser,
   registerUser,
-  removeUser
+  removeUser,
+  killallServers,
+  getUserInformation,
+  getBlacklistedVideosList
 } from '../utils'
-import { killallServers } from '../utils/servers'
-import { getUserInformation } from '../utils/users'
+import { UserRole } from '../../../shared'
+import { getMyVideos } from '../utils/videos'
 
 describe('Test users', function () {
   let server: ServerInfo
@@ -72,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')
@@ -188,16 +191,29 @@ describe('Test users', function () {
     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
@@ -234,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
   })
 
@@ -319,7 +336,7 @@ describe('Test users', function () {
   })
 
   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
@@ -328,9 +345,18 @@ describe('Test users', function () {
     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)
   })