2017-03-03 12:45:40 -05:00
|
|
|
/* eslint-disable no-unused-expressions */
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
2016-07-18 11:17:52 -04:00
|
|
|
const series = require('async/series')
|
2016-04-14 16:06:11 -04:00
|
|
|
|
2016-08-07 16:09:59 -04:00
|
|
|
const loginUtils = require('../utils/login')
|
|
|
|
const podsUtils = require('../utils/pods')
|
|
|
|
const serversUtils = require('../utils/servers')
|
|
|
|
const usersUtils = require('../utils/users')
|
2017-03-08 15:35:43 -05:00
|
|
|
const requestsUtils = require('../utils/requests')
|
2016-08-07 16:09:59 -04:00
|
|
|
const videosUtils = require('../utils/videos')
|
2016-04-14 16:06:11 -04:00
|
|
|
|
|
|
|
describe('Test users', function () {
|
|
|
|
let server = null
|
2016-05-11 15:19:34 -04:00
|
|
|
let accessToken = null
|
2016-08-04 16:32:36 -04:00
|
|
|
let accessTokenUser = null
|
|
|
|
let videoId = null
|
|
|
|
let userId = null
|
2016-04-14 16:06:11 -04:00
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
this.timeout(20000)
|
|
|
|
|
2016-07-18 11:17:52 -04:00
|
|
|
series([
|
2016-04-14 16:06:11 -04:00
|
|
|
function (next) {
|
2016-08-07 16:09:59 -04:00
|
|
|
serversUtils.flushTests(next)
|
2016-04-14 16:06:11 -04:00
|
|
|
},
|
|
|
|
function (next) {
|
2016-08-07 16:09:59 -04:00
|
|
|
serversUtils.runServer(1, function (server1) {
|
2016-04-14 16:06:11 -04:00
|
|
|
server = server1
|
|
|
|
next()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
], done)
|
|
|
|
})
|
|
|
|
|
2016-04-27 16:17:55 -04:00
|
|
|
it('Should create a new client')
|
|
|
|
|
|
|
|
it('Should return the first client')
|
|
|
|
|
|
|
|
it('Should remove the last client')
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
it('Should not login with an invalid client id', function (done) {
|
|
|
|
const client = { id: 'client', password: server.client.secret }
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, client, server.user, 400, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_client')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid client password', function (done) {
|
|
|
|
const client = { id: server.client.id, password: 'coucou' }
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, client, server.user, 400, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_client')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid username', function (done) {
|
|
|
|
const user = { username: 'captain crochet', password: server.user.password }
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, server.client, user, 400, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_grant')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not login with an invalid password', function (done) {
|
|
|
|
const user = { username: server.user.username, password: 'mewthree' }
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, server.client, user, 400, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.error).to.equal('invalid_grant')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to upload a video', function (done) {
|
2016-05-11 15:19:34 -04:00
|
|
|
accessToken = 'mysupertoken'
|
2016-06-06 08:15:03 -04:00
|
|
|
|
|
|
|
const name = 'my super name'
|
|
|
|
const description = 'my super description'
|
|
|
|
const tags = [ 'tag1', 'tag2' ]
|
|
|
|
const video = 'video_short.webm'
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
|
2016-04-14 16:06:11 -04:00
|
|
|
})
|
|
|
|
|
2016-05-13 10:31:14 -04:00
|
|
|
it('Should not be able to make friends', function (done) {
|
|
|
|
accessToken = 'mysupertoken'
|
2016-08-07 16:09:59 -04:00
|
|
|
podsUtils.makeFriends(server.url, accessToken, 401, done)
|
2016-05-13 10:31:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to quit friends', function (done) {
|
|
|
|
accessToken = 'mysupertoken'
|
2016-08-07 16:09:59 -04:00
|
|
|
podsUtils.quitFriends(server.url, accessToken, 401, done)
|
2016-05-13 10:31:14 -04:00
|
|
|
})
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
it('Should be able to login', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, server.client, server.user, 200, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
2016-05-11 15:19:34 -04:00
|
|
|
accessToken = res.body.access_token
|
2016-04-14 16:06:11 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video with the correct token', function (done) {
|
2016-06-06 08:15:03 -04:00
|
|
|
const name = 'my super name'
|
|
|
|
const description = 'my super description'
|
|
|
|
const tags = [ 'tag1', 'tag2' ]
|
|
|
|
const video = 'video_short.webm'
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.getVideosList(server.url, function (err, res) {
|
2016-04-14 16:06:11 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
2016-05-21 13:30:22 -04:00
|
|
|
const video = res.body.data[0]
|
2016-05-03 15:03:51 -04:00
|
|
|
expect(video.author).to.equal('root')
|
|
|
|
|
2016-05-11 15:19:34 -04:00
|
|
|
videoId = video.id
|
2016-04-14 16:06:11 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should upload the video again with the correct token', function (done) {
|
2016-06-06 08:15:03 -04:00
|
|
|
const name = 'my super name 2'
|
|
|
|
const description = 'my super description 2'
|
|
|
|
const tags = [ 'tag1' ]
|
|
|
|
const video = 'video_short.webm'
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
|
2016-04-14 16:06:11 -04:00
|
|
|
})
|
|
|
|
|
2017-03-08 15:35:43 -05:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
it('Should not be able to remove the video with an incorrect token', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done)
|
2016-04-14 16:06:11 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to remove the video with the token of another account')
|
|
|
|
|
|
|
|
it('Should be able to remove the video with the correct token', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.removeVideo(server.url, accessToken, videoId, done)
|
2016-04-14 16:06:11 -04:00
|
|
|
})
|
|
|
|
|
2016-07-20 10:23:58 -04:00
|
|
|
it('Should logout (revoke token)')
|
2016-04-14 16:06:11 -04:00
|
|
|
|
2017-03-08 15:35:43 -05:00
|
|
|
it('Should not be able to get the user informations')
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
it('Should not be able to upload a video')
|
|
|
|
|
|
|
|
it('Should not be able to remove a video')
|
|
|
|
|
2017-03-08 15:35:43 -05:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
it('Should be able to login again')
|
|
|
|
|
2016-07-20 10:23:58 -04:00
|
|
|
it('Should have an expired access token')
|
|
|
|
|
|
|
|
it('Should refresh the token')
|
|
|
|
|
|
|
|
it('Should be able to upload a video again')
|
|
|
|
|
2016-08-04 16:32:36 -04:00
|
|
|
it('Should be able to create a new user', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
usersUtils.createUser(server.url, accessToken, 'user_1', 'super password', done)
|
2016-08-04 16:32:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to login with this user', function (done) {
|
|
|
|
server.user = {
|
|
|
|
username: 'user_1',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
|
|
|
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.loginAndGetAccessToken(server, function (err, token) {
|
2016-08-04 16:32:36 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
accessTokenUser = token
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-05 11:19:08 -04:00
|
|
|
it('Should be able to get the user informations', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) {
|
2016-08-05 11:19:08 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
const user = res.body
|
|
|
|
|
|
|
|
expect(user.username).to.equal('user_1')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(user.email).to.equal('user_1@example.com')
|
2016-08-05 11:19:08 -04:00
|
|
|
expect(user.id).to.exist
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-04 16:32:36 -04:00
|
|
|
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'
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done)
|
2016-08-04 16:32:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list all the users', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
usersUtils.getUsersList(server.url, function (err, res) {
|
2016-08-04 16:32:36 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
2016-08-16 16:31:45 -04:00
|
|
|
const result = res.body
|
|
|
|
const total = result.total
|
|
|
|
const users = result.data
|
2016-08-04 16:32:36 -04:00
|
|
|
|
2016-08-16 16:31:45 -04:00
|
|
|
expect(total).to.equal(2)
|
2016-08-04 16:32:36 -04:00
|
|
|
expect(users).to.be.an('array')
|
|
|
|
expect(users.length).to.equal(2)
|
|
|
|
|
2016-08-16 16:31:45 -04:00
|
|
|
const user = users[0]
|
|
|
|
expect(user.username).to.equal('user_1')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(user.email).to.equal('user_1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
|
|
|
|
const rootUser = users[1]
|
2016-08-04 16:32:36 -04:00
|
|
|
expect(rootUser.username).to.equal('root')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(rootUser.email).to.equal('admin1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
userId = user.id
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list only the first user by username asc', function (done) {
|
|
|
|
usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, 'username', function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
const result = res.body
|
|
|
|
const total = result.total
|
|
|
|
const users = result.data
|
|
|
|
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(users.length).to.equal(1)
|
2016-08-04 16:32:36 -04:00
|
|
|
|
2016-08-16 16:31:45 -04:00
|
|
|
const user = users[0]
|
|
|
|
expect(user.username).to.equal('root')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(user.email).to.equal('admin1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list only the first user by username desc', function (done) {
|
|
|
|
usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-username', function (err, res) {
|
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
const result = res.body
|
|
|
|
const total = result.total
|
|
|
|
const users = result.data
|
|
|
|
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(users.length).to.equal(1)
|
|
|
|
|
|
|
|
const user = users[0]
|
2016-08-04 16:32:36 -04:00
|
|
|
expect(user.username).to.equal('user_1')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(user.email).to.equal('user_1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-12-11 15:50:51 -05:00
|
|
|
it('Should list only the second user by createdAt desc', function (done) {
|
|
|
|
usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) {
|
2016-08-16 16:31:45 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
const result = res.body
|
|
|
|
const total = result.total
|
|
|
|
const users = result.data
|
|
|
|
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(users.length).to.equal(1)
|
|
|
|
|
|
|
|
const user = users[0]
|
|
|
|
expect(user.username).to.equal('user_1')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(user.email).to.equal('user_1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-12-11 15:50:51 -05:00
|
|
|
it('Should list all the users by createdAt asc', function (done) {
|
|
|
|
usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) {
|
2016-08-16 16:31:45 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
const result = res.body
|
|
|
|
const total = result.total
|
|
|
|
const users = result.data
|
|
|
|
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(users.length).to.equal(2)
|
|
|
|
|
|
|
|
expect(users[0].username).to.equal('root')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(users[0].email).to.equal('admin1@example.com')
|
2016-08-16 16:31:45 -04:00
|
|
|
expect(users[1].username).to.equal('user_1')
|
2017-02-18 03:29:59 -05:00
|
|
|
expect(users[1].email).to.equal('user_1@example.com')
|
2016-08-04 16:32:36 -04:00
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should update the user password', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) {
|
2016-08-04 16:32:36 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
server.user.password = 'new password'
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, server.client, server.user, 200, done)
|
2016-08-04 16:32:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to remove this user', function (done) {
|
2016-08-09 15:44:45 -04:00
|
|
|
usersUtils.removeUser(server.url, userId, accessToken, done)
|
2016-08-04 16:32:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to login with this user', function (done) {
|
|
|
|
// server.user is already set to user 1
|
2016-08-07 16:09:59 -04:00
|
|
|
loginUtils.login(server.url, server.client, server.user, 400, done)
|
2016-08-04 16:32:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not have videos of this user', function (done) {
|
2016-08-07 16:09:59 -04:00
|
|
|
videosUtils.getVideosList(server.url, function (err, res) {
|
2016-08-04 16:32:36 -04:00
|
|
|
if (err) throw err
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
const video = res.body.data[0]
|
|
|
|
expect(video.author).to.equal('root')
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-04-14 16:06:11 -04:00
|
|
|
after(function (done) {
|
|
|
|
process.kill(-server.app.pid)
|
|
|
|
|
|
|
|
// Keep the logs if the test failed
|
|
|
|
if (this.ok) {
|
2016-08-07 16:09:59 -04:00
|
|
|
serversUtils.flushTests(done)
|
2016-04-14 16:06:11 -04:00
|
|
|
} else {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|