X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Futils%2Fusers%2Fusers.ts;h=d77233d6289cee5e3e8e23fb891339b59a8e87be;hb=0b2f03d3712f438f67eccf86b67acd047284f9b4;hp=d31e57a25675e82e52e4e2eebd35e01b7d70d20a;hpb=ed56ad1193bb5bb0a81fb843a11eb90d3fed9861;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index d31e57a25..d77233d62 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' @@ -101,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) @@ -109,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) @@ -125,9 +137,33 @@ 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, + currentPassword?: string, newPassword?: string, nsfwPolicy?: NSFWPolicyType, email?: string, @@ -138,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 @@ -160,21 +197,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: { @@ -183,6 +207,7 @@ function updateUser (options: { accessToken: string, email?: string, videoQuota?: number, + videoQuotaDaily?: number, role?: UserRole }) { const path = '/api/v1/users/' + options.userId @@ -190,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({ @@ -223,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 { @@ -230,6 +278,7 @@ export { registerUser, getMyUserInformation, getMyUserVideoRating, + deleteMe, getMyUserVideoQuotaUsed, getUsersList, getUsersListPaginationAndSort, @@ -237,7 +286,11 @@ export { updateUser, updateMyUser, getUserInformation, + blockUser, + unblockUser, askResetPassword, resetPassword, - updateMyAvatar + updateMyAvatar, + askSendVerifyEmail, + verifyEmail }