]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/users/users.ts
Speedup peertube startup
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users / users.ts
index 7e15fc86ec012d46f092df132242f097a76f19c5..d77233d6289cee5e3e8e23fb891339b59a8e87be 100644 (file)
@@ -10,6 +10,7 @@ function createUser (
   username: string,
   password: string,
   videoQuota = 1000000,
+  videoQuotaDaily = -1,
   role: UserRole = UserRole.USER,
   specialStatus = 200
 ) {
@@ -19,7 +20,8 @@ function createUser (
     password,
     role,
     email: username + '@example.com',
-    videoQuota
+    videoQuota,
+    videoQuotaDaily
   }
 
   return request(url)
@@ -110,7 +112,7 @@ function getUsersList (url: string, accessToken: string) {
           .expect('Content-Type', /json/)
 }
 
-function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string) {
+function getUsersListPaginationAndSort (url: string, accessToken: string, start: number, count: number, sort: string, search?: string) {
   const path = '/api/v1/users'
 
   return request(url)
@@ -118,6 +120,7 @@ function getUsersListPaginationAndSort (url: string, accessToken: string, start:
           .query({ start })
           .query({ count })
           .query({ sort })
+          .query({ search })
           .set('Accept', 'application/json')
           .set('Authorization', 'Bearer ' + accessToken)
           .expect(200)
@@ -134,11 +137,14 @@ function removeUser (url: string, userId: number | string, accessToken: string,
           .expect(expectedStatus)
 }
 
-function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) {
+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)
@@ -157,6 +163,7 @@ function unblockUser (url: string, userId: number | string, accessToken: string,
 function updateMyUser (options: {
   url: string
   accessToken: string,
+  currentPassword?: string,
   newPassword?: string,
   nsfwPolicy?: NSFWPolicyType,
   email?: string,
@@ -167,6 +174,7 @@ function updateMyUser (options: {
   const path = '/api/v1/users/me'
 
   const toSend = {}
+  if (options.currentPassword !== undefined && options.currentPassword !== null) toSend['currentPassword'] = options.currentPassword
   if (options.newPassword !== undefined && options.newPassword !== null) toSend['password'] = options.newPassword
   if (options.nsfwPolicy !== undefined && options.nsfwPolicy !== null) toSend['nsfwPolicy'] = options.nsfwPolicy
   if (options.autoPlayVideo !== undefined && options.autoPlayVideo !== null) toSend['autoPlayVideo'] = options.autoPlayVideo
@@ -199,6 +207,7 @@ function updateUser (options: {
   accessToken: string,
   email?: string,
   videoQuota?: number,
+  videoQuotaDaily?: number,
   role?: UserRole
 }) {
   const path = '/api/v1/users/' + options.userId
@@ -206,6 +215,7 @@ function updateUser (options: {
   const toSend = {}
   if (options.email !== undefined && options.email !== null) toSend['email'] = options.email
   if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
+  if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
   if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
 
   return makePutBodyRequest({
@@ -239,6 +249,28 @@ function resetPassword (url: string, userId: number, verificationString: string,
   })
 }
 
+function askSendVerifyEmail (url: string, email: string) {
+  const path = '/api/v1/users/ask-send-verify-email'
+
+  return makePostBodyRequest({
+    url,
+    path,
+    fields: { email },
+    statusCodeExpected: 204
+  })
+}
+
+function verifyEmail (url: string, userId: number, verificationString: string, statusCodeExpected = 204) {
+  const path = '/api/v1/users/' + userId + '/verify-email'
+
+  return makePostBodyRequest({
+    url,
+    path,
+    fields: { verificationString },
+    statusCodeExpected
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
@@ -258,5 +290,7 @@ export {
   unblockUser,
   askResetPassword,
   resetPassword,
-  updateMyAvatar
+  updateMyAvatar,
+  askSendVerifyEmail,
+  verifyEmail
 }