1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Implement user API (create, update, remove, list)

This commit is contained in:
Chocobozzz 2016-08-04 22:32:36 +02:00
parent e4c556196d
commit 9bd2662976
16 changed files with 688 additions and 47 deletions

View file

@ -8,11 +8,13 @@ const pathUtils = require('path')
const request = require('supertest')
const testUtils = {
createUser: createUser,
dateIsValid: dateIsValid,
flushTests: flushTests,
getAllVideosListBy: getAllVideosListBy,
getClient: getClient,
getFriendsList: getFriendsList,
getUsersList: getUsersList,
getVideo: getVideo,
getVideosList: getVideosList,
getVideosListPagination: getVideosListPagination,
@ -21,6 +23,7 @@ const testUtils = {
loginAndGetAccessToken: loginAndGetAccessToken,
makeFriends: makeFriends,
quitFriends: quitFriends,
removeUser: removeUser,
removeVideo: removeVideo,
flushAndRunMultipleServers: flushAndRunMultipleServers,
runServer: runServer,
@ -28,11 +31,29 @@ const testUtils = {
searchVideoWithPagination: searchVideoWithPagination,
searchVideoWithSort: searchVideoWithSort,
testImage: testImage,
uploadVideo: uploadVideo
uploadVideo: uploadVideo,
updateUser: updateUser
}
// ---------------------- Export functions --------------------
function createUser (url, accessToken, username, password, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
}
const path = '/api/v1/users'
request(url)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.send({ username: username, password: password })
.expect(specialStatus)
.end(end)
}
function dateIsValid (dateString) {
const dateToCheck = new Date(dateString)
const now = new Date()
@ -72,6 +93,17 @@ function getClient (url, end) {
.end(end)
}
function getUsersList (url, end) {
const path = '/api/v1/users'
request(url)
.get(path)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.end(end)
}
function getFriendsList (url, end) {
const path = '/api/v1/pods/'
@ -209,6 +241,22 @@ function quitFriends (url, accessToken, expectedStatus, callback) {
})
}
function removeUser (url, token, username, expectedStatus, end) {
if (!end) {
end = expectedStatus
expectedStatus = 204
}
const path = '/api/v1/users'
request(url)
.delete(path + '/' + username)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(expectedStatus)
.end(end)
}
function removeVideo (url, token, id, expectedStatus, end) {
if (!end) {
end = expectedStatus
@ -414,6 +462,18 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
.end(end)
}
function updateUser (url, userId, accessToken, newPassword, end) {
const path = '/api/v1/users/' + userId
request(url)
.put(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken)
.send({ password: newPassword })
.expect(200)
.end(end)
}
// ---------------------------------------------------------------------------
module.exports = testUtils