]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users.js
Server: add tests to video transcoder
[github/Chocobozzz/PeerTube.git] / server / tests / api / users.js
index c6c892bf279c1a264197bfb1392d0c07db55e908..10c96baeb2eadad653275526ad111a0207c61384 100644 (file)
@@ -1,17 +1,17 @@
+/* eslint-disable no-unused-expressions */
+
 'use strict'
 
 const chai = require('chai')
 const expect = chai.expect
-const pathUtils = require('path')
 const series = require('async/series')
 
 const loginUtils = require('../utils/login')
 const podsUtils = require('../utils/pods')
 const serversUtils = require('../utils/servers')
 const usersUtils = require('../utils/users')
+const requestsUtils = require('../utils/requests')
 const videosUtils = require('../utils/videos')
-const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
-webtorrent.silent = true
 
 describe('Test users', function () {
   let server = null
@@ -85,11 +85,8 @@ describe('Test users', function () {
   it('Should not be able to upload a video', function (done) {
     accessToken = 'mysupertoken'
 
-    const name = 'my super name'
-    const description = 'my super description'
-    const tags = [ 'tag1', 'tag2' ]
-    const video = 'video_short.webm'
-    videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
+    const videoAttributes = {}
+    videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 401, done)
   })
 
   it('Should not be able to make friends', function (done) {
@@ -112,11 +109,8 @@ describe('Test users', function () {
   })
 
   it('Should upload the video with the correct token', function (done) {
-    const name = 'my super name'
-    const description = 'my super description'
-    const tags = [ 'tag1', 'tag2' ]
-    const video = 'video_short.webm'
-    videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
+    const videoAttributes = {}
+    videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, function (err, res) {
       if (err) throw err
 
       videosUtils.getVideosList(server.url, function (err, res) {
@@ -132,11 +126,25 @@ describe('Test users', function () {
   })
 
   it('Should upload the video again with the correct token', function (done) {
-    const name = 'my super name 2'
-    const description = 'my super description 2'
-    const tags = [ 'tag1' ]
-    const video = 'video_short.webm'
-    videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
+    const videoAttributes = {}
+    videosUtils.uploadVideo(server.url, accessToken, videoAttributes, 204, done)
+  })
+
+  it('Should retrieve a video rating', function (done) {
+    videosUtils.rateVideo(server.url, accessToken, videoId, 'like', function (err) {
+      if (err) throw err
+
+      usersUtils.getUserVideoRating(server.url, accessToken, videoId, function (err, res) {
+        if (err) throw err
+
+        const rating = res.body
+
+        expect(rating.videoId).to.equal(videoId)
+        expect(rating.rating).to.equal('like')
+
+        done()
+      })
+    })
   })
 
   it('Should not be able to remove the video with an incorrect token', function (done) {
@@ -151,10 +159,21 @@ describe('Test users', function () {
 
   it('Should logout (revoke token)')
 
+  it('Should not be able to get the user informations')
+
   it('Should not be able to upload a video')
 
   it('Should not be able to remove a video')
 
+  it('Should not be able to rate a video', function (done) {
+    const path = '/api/v1/videos/'
+    const data = {
+      rating: 'likes'
+    }
+
+    requestsUtils.makePutBodyRequest(server.url, path + videoId, 'wrong token', data, done, 401)
+  })
+
   it('Should be able to login again')
 
   it('Should have an expired access token')
@@ -189,6 +208,8 @@ describe('Test users', function () {
       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.falsy
       expect(user.id).to.exist
 
       done()
@@ -198,11 +219,8 @@ describe('Test users', function () {
   it('Should be able to upload a video with this user', function (done) {
     this.timeout(5000)
 
-    const name = 'my super name'
-    const description = 'my super description'
-    const tags = [ 'tag1', 'tag2', 'tag3' ]
-    const file = 'video_short.webm'
-    videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
+    const videoAttributes = {}
+    videosUtils.uploadVideo(server.url, accessTokenUser, videoAttributes, done)
   })
 
   it('Should list all the users', function (done) {
@@ -219,9 +237,14 @@ describe('Test users', function () {
 
       const user = users[0]
       expect(user.username).to.equal('user_1')
+      expect(user.email).to.equal('user_1@example.com')
+      expect(user.displayNSFW).to.be.falsy
 
       const rootUser = users[1]
       expect(rootUser.username).to.equal('root')
+      expect(rootUser.email).to.equal('admin1@example.com')
+      expect(rootUser.displayNSFW).to.be.falsy
+
       userId = user.id
 
       done()
@@ -241,6 +264,8 @@ describe('Test users', function () {
 
       const user = users[0]
       expect(user.username).to.equal('root')
+      expect(user.email).to.equal('admin1@example.com')
+      expect(user.displayNSFW).to.be.falsy
 
       done()
     })
@@ -259,13 +284,15 @@ describe('Test users', function () {
 
       const user = users[0]
       expect(user.username).to.equal('user_1')
+      expect(user.email).to.equal('user_1@example.com')
+      expect(user.displayNSFW).to.be.falsy
 
       done()
     })
   })
 
-  it('Should list only the second user by createdDate desc', function (done) {
-    usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdDate', function (err, res) {
+  it('Should list only the second user by createdAt desc', function (done) {
+    usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) {
       if (err) throw err
 
       const result = res.body
@@ -277,13 +304,15 @@ describe('Test users', function () {
 
       const user = users[0]
       expect(user.username).to.equal('user_1')
+      expect(user.email).to.equal('user_1@example.com')
+      expect(user.displayNSFW).to.be.falsy
 
       done()
     })
   })
 
-  it('Should list all the users by createdDate asc', function (done) {
-    usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdDate', function (err, res) {
+  it('Should list all the users by createdAt asc', function (done) {
+    usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) {
       if (err) throw err
 
       const result = res.body
@@ -294,14 +323,19 @@ describe('Test users', function () {
       expect(users.length).to.equal(2)
 
       expect(users[0].username).to.equal('root')
+      expect(users[0].email).to.equal('admin1@example.com')
+      expect(users[0].displayNSFW).to.be.falsy
+
       expect(users[1].username).to.equal('user_1')
+      expect(users[1].email).to.equal('user_1@example.com')
+      expect(users[1].displayNSFW).to.be.falsy
 
       done()
     })
   })
 
   it('Should update the user password', function (done) {
-    usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) {
+    usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', null, function (err, res) {
       if (err) throw err
 
       server.user.password = 'new password'
@@ -309,6 +343,25 @@ describe('Test users', function () {
     })
   })
 
+  it('Should be able to change the NSFW display attribute', function (done) {
+    usersUtils.updateUser(server.url, userId, accessTokenUser, null, true, function (err, res) {
+      if (err) throw err
+
+      usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) {
+        if (err) throw err
+
+        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.truthy
+        expect(user.id).to.exist
+
+        done()
+      })
+    })
+  })
+
   it('Should be able to remove this user', function (done) {
     usersUtils.removeUser(server.url, userId, accessToken, done)
   })
@@ -330,6 +383,19 @@ describe('Test users', function () {
     })
   })
 
+  it('Should register a new user', function (done) {
+    usersUtils.registerUser(server.url, 'user_15', 'my super password', done)
+  })
+
+  it('Should be able to login with this registered user', function (done) {
+    server.user = {
+      username: 'user_15',
+      password: 'my super password'
+    }
+
+    loginUtils.loginAndGetAccessToken(server, done)
+  })
+
   after(function (done) {
     process.kill(-server.app.pid)