]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/users/users.ts
Add reason when banning a user
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users / users.ts
index e0cca3f5107faeb5fbc3fe22949f0ad8ce17fdf7..f786de6e31726e9845435b984f757b721314a161 100644 (file)
@@ -1,7 +1,8 @@
 import * as request from 'supertest'
-import { makePutBodyRequest } from '../'
+import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../'
 
 import { UserRole } from '../../../../shared/index'
+import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type'
 
 function createUser (
   url: string,
@@ -10,7 +11,7 @@ function createUser (
   password: string,
   videoQuota = 1000000,
   role: UserRole = UserRole.USER,
-  specialStatus = 204
+  specialStatus = 200
 ) {
   const path = '/api/v1/users'
   const body = {
@@ -55,6 +56,27 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus =
           .expect('Content-Type', /json/)
 }
 
+function deleteMe (url: string, accessToken: string, specialStatus = 204) {
+  const path = '/api/v1/users/me'
+
+  return request(url)
+    .delete(path)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(specialStatus)
+}
+
+function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = 200) {
+  const path = '/api/v1/users/me/video-quota-used'
+
+  return request(url)
+          .get(path)
+          .set('Accept', 'application/json')
+          .set('Authorization', 'Bearer ' + accessToken)
+          .expect(specialStatus)
+          .expect('Content-Type', /json/)
+}
+
 function getUserInformation (url: string, accessToken: string, userId: number) {
   const path = '/api/v1/users/' + userId
 
@@ -112,21 +134,48 @@ function removeUser (url: string, userId: number | string, accessToken: string,
           .expect(expectedStatus)
 }
 
+function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204, reason?: string) {
+  const path = '/api/v1/users'
+  let body: any
+  if (reason) body = { reason }
+
+  return request(url)
+    .post(path + '/' + userId + '/block')
+    .send(body)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(expectedStatus)
+}
+
+function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
+  const path = '/api/v1/users'
+
+  return request(url)
+    .post(path + '/' + userId + '/unblock')
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(expectedStatus)
+}
+
 function updateMyUser (options: {
   url: string
   accessToken: string,
   newPassword?: string,
-  displayNSFW?: boolean,
+  nsfwPolicy?: NSFWPolicyType,
   email?: string,
   autoPlayVideo?: boolean
+  displayName?: string,
+  description?: string
 }) {
   const path = '/api/v1/users/me'
 
   const toSend = {}
   if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
-  if (options.displayNSFW !== undefined && options.displayNSFW !== null) toSend['displayNSFW'] = options.displayNSFW
+  if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend['nsfwPolicy'] = options.nsfwPolicy
   if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
   if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
+  if (options.description !== undefined && options.description !== null) toSend['description'] = options.description
+  if (options.displayName !== undefined && options.displayName !== null) toSend['displayName'] = options.displayName
 
   return makePutBodyRequest({
     url: options.url,
@@ -137,6 +186,16 @@ function updateMyUser (options: {
   })
 }
 
+function updateMyAvatar (options: {
+  url: string,
+  accessToken: string,
+  fixture: string
+}) {
+  const path = '/api/v1/users/me/avatar/pick'
+
+  return updateAvatarRequest(Object.assign(options, { path }))
+}
+
 function updateUser (options: {
   url: string
   userId: number,
@@ -161,6 +220,28 @@ function updateUser (options: {
   })
 }
 
+function askResetPassword (url: string, email: string) {
+  const path = '/api/v1/users/ask-reset-password'
+
+  return makePostBodyRequest({
+    url,
+    path,
+    fields: { email },
+    statusCodeExpected: 204
+  })
+}
+
+function resetPassword (url: string, userId: number, verificationString: string, password: string, statusCodeExpected = 204) {
+  const path = '/api/v1/users/' + userId + '/reset-password'
+
+  return makePostBodyRequest({
+    url,
+    path,
+    fields: { password, verificationString },
+    statusCodeExpected
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -168,10 +249,17 @@ export {
   registerUser,
   getMyUserInformation,
   getMyUserVideoRating,
+  deleteMe,
+  getMyUserVideoQuotaUsed,
   getUsersList,
   getUsersListPaginationAndSort,
   removeUser,
   updateUser,
   updateMyUser,
-  getUserInformation
+  getUserInformation,
+  blockUser,
+  unblockUser,
+  askResetPassword,
+  resetPassword,
+  updateMyAvatar
 }