]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/users.js
Server: add ability to register new user
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users.js
index 7817160b94e9b50c39230fc5d70f171aca244f1d..310dc0c6b14e8c262daaf8b081f496d4e35e2a27 100644 (file)
@@ -4,6 +4,7 @@ const request = require('supertest')
 
 const usersUtils = {
   createUser,
+  registerUser,
   getUserInformation,
   getUserVideoRating,
   getUsersList,
@@ -36,6 +37,27 @@ function createUser (url, accessToken, username, password, specialStatus, end) {
     .end(end)
 }
 
+function registerUser (url, username, password, specialStatus, end) {
+  if (!end) {
+    end = specialStatus
+    specialStatus = 204
+  }
+
+  const path = '/api/v1/users/register'
+  const body = {
+    username,
+    password,
+    email: username + '@example.com'
+  }
+
+  request(url)
+    .post(path)
+    .set('Accept', 'application/json')
+    .send(body)
+    .expect(specialStatus)
+    .end(end)
+}
+
 function getUserInformation (url, accessToken, end) {
   const path = '/api/v1/users/me'
 
@@ -101,14 +123,18 @@ function removeUser (url, userId, accessToken, expectedStatus, end) {
     .end(end)
 }
 
-function updateUser (url, userId, accessToken, newPassword, end) {
+function updateUser (url, userId, accessToken, newPassword, displayNSFW, end) {
   const path = '/api/v1/users/' + userId
 
+  const toSend = {}
+  if (newPassword !== undefined && newPassword !== null) toSend.password = newPassword
+  if (displayNSFW !== undefined && displayNSFW !== null) toSend.displayNSFW = displayNSFW
+
   request(url)
     .put(path)
     .set('Accept', 'application/json')
     .set('Authorization', 'Bearer ' + accessToken)
-    .send({ password: newPassword })
+    .send(toSend)
     .expect(204)
     .end(end)
 }