X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fusers%2Fusers.ts;h=cd1b0770149f43ca8b88844031354748b1f2e741;hb=d9eaee3939bf2e93e5d775d32bce77842201faba;hp=e24e721bdba5604f240c3abef2b10f62fb22b115;hpb=92b9d60c00432c58d6184f3683bdb14a0300a3c6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index e24e721bd..cd1b07701 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -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) @@ -134,6 +136,29 @@ 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, @@ -179,6 +204,7 @@ function updateUser (options: { accessToken: string, email?: string, videoQuota?: number, + videoQuotaDaily?: number, role?: UserRole }) { const path = '/api/v1/users/' + options.userId @@ -186,6 +212,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({ @@ -219,6 +246,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 { @@ -234,7 +283,11 @@ export { updateUser, updateMyUser, getUserInformation, + blockUser, + unblockUser, askResetPassword, resetPassword, - updateMyAvatar + updateMyAvatar, + askSendVerifyEmail, + verifyEmail }