makePutBodyRequest,
createUser,
loginAndGetAccessToken,
- getUserInformation,
+ getMyUserInformation,
getUsersList,
getUsersListPaginationAndSort,
updateUser,
+ updateMyUser,
registerUser,
removeUser
} from '../utils'
import { killallServers } from '../utils/servers'
+import { getUserInformation } from '../utils/users'
describe('Test users', function () {
let server: ServerInfo
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 () {
})
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.id).to.be.a('number')
})
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, 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')
})
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 () {
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 body = {
username,
password,
- email: username + '@example.com'
+ email: username + '@example.com',
+ videoQuota
}
return request(url)
.expect(specialStatus)
}
-function getUserInformation (url: string, accessToken: string) {
+function getMyUserInformation (url: string, accessToken: string) {
const path = '/api/v1/users/me'
return request(url)
.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) {
const path = '/api/v1/users/me/videos/' + videoId + '/rating'
.expect(expectedStatus)
}
-function updateUser (url: string, userId: number, accessToken: string, newPassword: string, displayNSFW: boolean) {
- const path = '/api/v1/users/' + userId
+function updateMyUser (url: string, accessToken: string, newPassword: string, displayNSFW?: boolean, email?: string) {
+ const path = '/api/v1/users/me'
const toSend = {}
if (newPassword !== undefined && newPassword !== null) toSend['password'] = newPassword
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)
.put(path)
export {
createUser,
registerUser,
- getUserInformation,
+ getMyUserInformation,
getUserVideoRating,
getUsersList,
getUsersListPaginationAndSort,
removeUser,
- updateUser
+ updateUser,
+ updateMyUser,
+ getUserInformation
}