-import { isAbsolute, join } from 'path'
import * as request from 'supertest'
-import { makePostUploadRequest, 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,
username: string,
password: string,
videoQuota = 1000000,
+ videoQuotaDaily = -1,
role: UserRole = UserRole.USER,
specialStatus = 200
) {
password,
role,
email: username + '@example.com',
- videoQuota
+ videoQuota,
+ videoQuotaDaily
}
return request(url)
.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'
.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,
- displayNSFW?: boolean,
+ nsfwPolicy?: NSFWPolicyType,
email?: string,
autoPlayVideo?: boolean
+ displayName?: string,
+ description?: string
}) {
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.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,
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 makePostUploadRequest({
- url: options.url,
- path,
- token: options.accessToken,
- fields: {},
- attaches: { avatarfile: filePath },
- statusCodeExpected: 200
- })
+ return updateAvatarRequest(Object.assign(options, { path }))
}
function updateUser (options: {
accessToken: string,
email?: string,
videoQuota?: number,
+ videoQuotaDaily?: number,
role?: UserRole
}) {
const path = '/api/v1/users/' + options.userId
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({
})
}
+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
+ })
+}
+
+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 {
registerUser,
getMyUserInformation,
getMyUserVideoRating,
+ deleteMe,
getMyUserVideoQuotaUsed,
getUsersList,
getUsersListPaginationAndSort,
updateUser,
updateMyUser,
getUserInformation,
- updateMyAvatar
+ blockUser,
+ unblockUser,
+ askResetPassword,
+ resetPassword,
+ updateMyAvatar,
+ askSendVerifyEmail,
+ verifyEmail
}