Begin tests for user quota
This commit is contained in:
parent
8094a89802
commit
5c98d3bf07
|
@ -28,7 +28,7 @@
|
||||||
"component-class-suffix": true,
|
"component-class-suffix": true,
|
||||||
"directive-class-suffix": true,
|
"directive-class-suffix": true,
|
||||||
"templates-use-public": true,
|
"templates-use-public": true,
|
||||||
"no-access-missing-member": true,
|
"no-access-missing-member": false,
|
||||||
"invoke-injectable": true
|
"invoke-injectable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,5 +21,8 @@ storage:
|
||||||
admin:
|
admin:
|
||||||
email: 'admin1@example.com'
|
email: 'admin1@example.com'
|
||||||
|
|
||||||
|
user:
|
||||||
|
video_quota: 1024 * 1024 * 5
|
||||||
|
|
||||||
signup:
|
signup:
|
||||||
limit: 4
|
limit: 4
|
||||||
|
|
|
@ -49,8 +49,8 @@ function videosAddValidator (req: express.Request, res: express.Response, next:
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error('Error in getting duration from file.', err)
|
logger.error('Error in video add validator', err)
|
||||||
res.status(400).send('Cannot retrieve metadata of the file.')
|
res.sendStatus(500)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,7 +244,7 @@ loadByUsernameOrEmail = function (username: string, email: string) {
|
||||||
function getOriginalVideoFileTotalFromUser (user: UserInstance) {
|
function getOriginalVideoFileTotalFromUser (user: UserInstance) {
|
||||||
const query = {
|
const query = {
|
||||||
attributes: [
|
attributes: [
|
||||||
Sequelize.fn('COUNT', Sequelize.col('VideoFile.size'), 'totalVideoBytes')
|
Sequelize.fn('COUNT', Sequelize.col('User.Author.Video.VideoFile.size'), 'totalVideoBytes')
|
||||||
],
|
],
|
||||||
where: {
|
where: {
|
||||||
id: user.id
|
id: user.id
|
||||||
|
@ -252,12 +252,15 @@ function getOriginalVideoFileTotalFromUser (user: UserInstance) {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: User['sequelize'].models.Author,
|
model: User['sequelize'].models.Author,
|
||||||
|
required: true,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: User['sequelize'].models.Video,
|
model: User['sequelize'].models.Video,
|
||||||
|
required: true,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: User['sequelize'].models.VideoFile
|
model: User['sequelize'].models.VideoFile,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,14 @@ function associate (models) {
|
||||||
},
|
},
|
||||||
onDelete: 'cascade'
|
onDelete: 'cascade'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Author.hasMany(models.Video, {
|
||||||
|
foreignKey: {
|
||||||
|
name: 'authorId',
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
onDelete: 'cascade'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) {
|
findOrCreateAuthor = function (name: string, podId: number, userId: number, transaction: Sequelize.Transaction) {
|
||||||
|
|
|
@ -19,14 +19,16 @@ import {
|
||||||
makePutBodyRequest,
|
makePutBodyRequest,
|
||||||
createUser,
|
createUser,
|
||||||
loginAndGetAccessToken,
|
loginAndGetAccessToken,
|
||||||
getUserInformation,
|
getMyUserInformation,
|
||||||
getUsersList,
|
getUsersList,
|
||||||
getUsersListPaginationAndSort,
|
getUsersListPaginationAndSort,
|
||||||
updateUser,
|
updateUser,
|
||||||
|
updateMyUser,
|
||||||
registerUser,
|
registerUser,
|
||||||
removeUser
|
removeUser
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { killallServers } from '../utils/servers'
|
import { killallServers } from '../utils/servers'
|
||||||
|
import { getUserInformation } from '../utils/users'
|
||||||
|
|
||||||
describe('Test users', function () {
|
describe('Test users', function () {
|
||||||
let server: ServerInfo
|
let server: ServerInfo
|
||||||
|
@ -166,7 +168,7 @@ describe('Test users', function () {
|
||||||
it('Should be able to upload a video again')
|
it('Should be able to upload a video again')
|
||||||
|
|
||||||
it('Should be able to create a new user', async function () {
|
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 login with this user', async function () {
|
||||||
|
@ -179,12 +181,13 @@ describe('Test users', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should be able to get the user information', 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
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username).to.equal('user_1')
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
expect(user.email).to.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
|
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
||||||
expect(user.id).to.be.a('number')
|
expect(user.id).to.be.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -282,22 +285,49 @@ describe('Test users', function () {
|
||||||
expect(users[1].displayNSFW).to.be.false
|
expect(users[1].displayNSFW).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should update the user password', async function () {
|
it('Should update my password', async function () {
|
||||||
await updateUser(server.url, userId, accessTokenUser, 'new password', null)
|
await updateMyUser(server.url, accessTokenUser, 'new password')
|
||||||
server.user.password = 'new password'
|
server.user.password = 'new password'
|
||||||
|
|
||||||
await login(server.url, server.client, server.user, 200)
|
await login(server.url, server.client, server.user, 200)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should be able to change the NSFW display attribute', async function () {
|
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
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username).to.equal('user_1')
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
expect(user.email).to.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.ok
|
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, server.accessToken, 'updated2@example.com', 42 )
|
||||||
|
|
||||||
|
const res = await getUserInformation(server.url, server.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.id).to.be.a('number')
|
expect(user.id).to.be.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -329,7 +359,14 @@ describe('Test users', function () {
|
||||||
password: 'my super password'
|
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 () {
|
after(async function () {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
|
|
||||||
function createUser (url: string, accessToken: string, username: string, password: string, specialStatus = 204) {
|
function createUser (url: string, accessToken: string, username: string, password: string, videoQuota = 1000000, specialStatus = 204) {
|
||||||
const path = '/api/v1/users'
|
const path = '/api/v1/users'
|
||||||
const body = {
|
const body = {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
email: username + '@example.com'
|
email: username + '@example.com',
|
||||||
|
videoQuota
|
||||||
}
|
}
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
|
@ -31,7 +32,7 @@ function registerUser (url: string, username: string, password: string, specialS
|
||||||
.expect(specialStatus)
|
.expect(specialStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserInformation (url: string, accessToken: string) {
|
function getMyUserInformation (url: string, accessToken: string) {
|
||||||
const path = '/api/v1/users/me'
|
const path = '/api/v1/users/me'
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
|
@ -42,6 +43,17 @@ function getUserInformation (url: string, accessToken: string) {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUserInformation (url: string, accessToken: string, userId: number) {
|
||||||
|
const path = '/api/v1/users/' + userId
|
||||||
|
|
||||||
|
return request(url)
|
||||||
|
.get(path)
|
||||||
|
.set('Accept', 'application/json')
|
||||||
|
.set('Authorization', 'Bearer ' + accessToken)
|
||||||
|
.expect(200)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
}
|
||||||
|
|
||||||
function getUserVideoRating (url: string, accessToken: string, videoId: number) {
|
function getUserVideoRating (url: string, accessToken: string, videoId: number) {
|
||||||
const path = '/api/v1/users/me/videos/' + videoId + '/rating'
|
const path = '/api/v1/users/me/videos/' + videoId + '/rating'
|
||||||
|
|
||||||
|
@ -86,12 +98,28 @@ function removeUser (url: string, userId: number, accessToken: string, expectedS
|
||||||
.expect(expectedStatus)
|
.expect(expectedStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUser (url: string, userId: number, accessToken: string, newPassword: string, displayNSFW: boolean) {
|
function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, email?: string) {
|
||||||
const path = '/api/v1/users/' + userId
|
const path = '/api/v1/users/me'
|
||||||
|
|
||||||
const toSend = {}
|
const toSend = {}
|
||||||
if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
|
if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
|
||||||
if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
|
if (displayNSFW !== undefined && displayNSFW !== null) toSend['displayNSFW'] = displayNSFW
|
||||||
|
if (email !== undefined && email !== null) toSend['email'] = email
|
||||||
|
|
||||||
|
return request(url)
|
||||||
|
.put(path)
|
||||||
|
.set('Accept', 'application/json')
|
||||||
|
.set('Authorization', 'Bearer ' + accessToken)
|
||||||
|
.send(toSend)
|
||||||
|
.expect(204)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUser (url: string, userId: number, accessToken: string, email: string, videoQuota: number) {
|
||||||
|
const path = '/api/v1/users/' + userId
|
||||||
|
|
||||||
|
const toSend = {}
|
||||||
|
if (email !== undefined && email !== null) toSend['password'] = email
|
||||||
|
if (videoQuota !== undefined && videoQuota !== null) toSend['videoQuota'] = videoQuota
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
.put(path)
|
.put(path)
|
||||||
|
@ -106,10 +134,12 @@ function updateUser (url: string, userId: number, accessToken: string, newPasswo
|
||||||
export {
|
export {
|
||||||
createUser,
|
createUser,
|
||||||
registerUser,
|
registerUser,
|
||||||
getUserInformation,
|
getMyUserInformation,
|
||||||
getUserVideoRating,
|
getUserVideoRating,
|
||||||
getUsersList,
|
getUsersList,
|
||||||
getUsersListPaginationAndSort,
|
getUsersListPaginationAndSort,
|
||||||
removeUser,
|
removeUser,
|
||||||
updateUser
|
updateUser,
|
||||||
|
updateMyUser,
|
||||||
|
getUserInformation
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue