X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fusers%2Fusers.ts;h=cd1b0770149f43ca8b88844031354748b1f2e741;hb=d9eaee3939bf2e93e5d775d32bce77842201faba;hp=fc6b26c50af4462ba9688eb77857497a6db488d6;hpb=0883b3245bf0deb9106c4041e9afbd3521b79280;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index fc6b26c50..cd1b07701 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -1,6 +1,5 @@ -import { isAbsolute, join } from 'path' import * as request from 'supertest' -import { makePostBodyRequest, makeUploadRequest, makePutBodyRequest } from '../' +import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../' import { UserRole } from '../../../../shared/index' import { NSFWPolicyType } from '../../../../shared/models/videos/nsfw-policy.type' @@ -11,6 +10,7 @@ function createUser ( username: string, password: string, videoQuota = 1000000, + videoQuotaDaily = -1, role: UserRole = UserRole.USER, specialStatus = 200 ) { @@ -20,7 +20,8 @@ function createUser ( password, role, email: username + '@example.com', - videoQuota + videoQuota, + videoQuotaDaily } return request(url) @@ -57,6 +58,16 @@ 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' @@ -125,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, @@ -132,6 +166,7 @@ function updateMyUser (options: { nsfwPolicy?: NSFWPolicyType, email?: string, autoPlayVideo?: boolean + displayName?: string, description?: string }) { const path = '/api/v1/users/me' @@ -142,6 +177,7 @@ function updateMyUser (options: { 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, @@ -158,21 +194,8 @@ function updateMyAvatar (options: { fixture: string }) { const path = '/api/v1/users/me/avatar/pick' - let filePath = '' - if (isAbsolute(options.fixture)) { - filePath = options.fixture - } else { - filePath = join(__dirname, '..', '..', 'api', 'fixtures', options.fixture) - } - return makeUploadRequest({ - url: options.url, - path, - token: options.accessToken, - fields: {}, - attaches: { avatarfile: filePath }, - statusCodeExpected: 200 - }) + return updateAvatarRequest(Object.assign(options, { path })) } function updateUser (options: { @@ -181,6 +204,7 @@ function updateUser (options: { accessToken: string, email?: string, videoQuota?: number, + videoQuotaDaily?: number, role?: UserRole }) { const path = '/api/v1/users/' + options.userId @@ -188,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({ @@ -221,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 { @@ -228,6 +275,7 @@ export { registerUser, getMyUserInformation, getMyUserVideoRating, + deleteMe, getMyUserVideoQuotaUsed, getUsersList, getUsersListPaginationAndSort, @@ -235,7 +283,11 @@ export { updateUser, updateMyUser, getUserInformation, + blockUser, + unblockUser, askResetPassword, resetPassword, - updateMyAvatar + updateMyAvatar, + askSendVerifyEmail, + verifyEmail }