aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/users
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /shared/extra-utils/users
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'shared/extra-utils/users')
-rw-r--r--shared/extra-utils/users/accounts.ts13
-rw-r--r--shared/extra-utils/users/blocklist.ts65
-rw-r--r--shared/extra-utils/users/user-notifications.ts14
-rw-r--r--shared/extra-utils/users/user-subscriptions.ts13
-rw-r--r--shared/extra-utils/users/users.ts63
5 files changed, 121 insertions, 47 deletions
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts
index f87706f6a..4ea7f1402 100644
--- a/shared/extra-utils/users/accounts.ts
+++ b/shared/extra-utils/users/accounts.ts
@@ -8,8 +8,9 @@ import { Account } from '../../models/actors'
8import { root } from '../miscs/miscs' 8import { root } from '../miscs/miscs'
9import { makeGetRequest } from '../requests/requests' 9import { makeGetRequest } from '../requests/requests'
10import { VideoRateType } from '../../models/videos' 10import { VideoRateType } from '../../models/videos'
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
11 12
12function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { 13function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
13 const path = '/api/v1/accounts' 14 const path = '/api/v1/accounts'
14 15
15 return makeGetRequest({ 16 return makeGetRequest({
@@ -20,7 +21,7 @@ function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected =
20 }) 21 })
21} 22}
22 23
23function getAccount (url: string, accountName: string, statusCodeExpected = 200) { 24function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) {
24 const path = '/api/v1/accounts/' + accountName 25 const path = '/api/v1/accounts/' + accountName
25 26
26 return makeGetRequest({ 27 return makeGetRequest({
@@ -55,7 +56,13 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
55 } 56 }
56} 57}
57 58
58function getAccountRatings (url: string, accountName: string, accessToken: string, rating?: VideoRateType, statusCodeExpected = 200) { 59function getAccountRatings (
60 url: string,
61 accountName: string,
62 accessToken: string,
63 rating?: VideoRateType,
64 statusCodeExpected = HttpStatusCode.OK_200
65) {
59 const path = '/api/v1/accounts/' + accountName + '/ratings' 66 const path = '/api/v1/accounts/' + accountName + '/ratings'
60 67
61 const query = rating ? { rating } : {} 68 const query = rating ? { rating } : {}
diff --git a/shared/extra-utils/users/blocklist.ts b/shared/extra-utils/users/blocklist.ts
index 39e720b42..bdf7ee58a 100644
--- a/shared/extra-utils/users/blocklist.ts
+++ b/shared/extra-utils/users/blocklist.ts
@@ -1,6 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests' 3import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5function getAccountBlocklistByAccount ( 6function getAccountBlocklistByAccount (
6 url: string, 7 url: string,
@@ -8,7 +9,7 @@ function getAccountBlocklistByAccount (
8 start: number, 9 start: number,
9 count: number, 10 count: number,
10 sort = '-createdAt', 11 sort = '-createdAt',
11 statusCodeExpected = 200 12 statusCodeExpected = HttpStatusCode.OK_200
12) { 13) {
13 const path = '/api/v1/users/me/blocklist/accounts' 14 const path = '/api/v1/users/me/blocklist/accounts'
14 15
@@ -21,7 +22,12 @@ function getAccountBlocklistByAccount (
21 }) 22 })
22} 23}
23 24
24function addAccountToAccountBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { 25function addAccountToAccountBlocklist (
26 url: string,
27 token: string,
28 accountToBlock: string,
29 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
30) {
25 const path = '/api/v1/users/me/blocklist/accounts' 31 const path = '/api/v1/users/me/blocklist/accounts'
26 32
27 return makePostBodyRequest({ 33 return makePostBodyRequest({
@@ -35,7 +41,12 @@ function addAccountToAccountBlocklist (url: string, token: string, accountToBloc
35 }) 41 })
36} 42}
37 43
38function removeAccountFromAccountBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { 44function removeAccountFromAccountBlocklist (
45 url: string,
46 token: string,
47 accountToUnblock: string,
48 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
49) {
39 const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock 50 const path = '/api/v1/users/me/blocklist/accounts/' + accountToUnblock
40 51
41 return makeDeleteRequest({ 52 return makeDeleteRequest({
@@ -52,7 +63,7 @@ function getServerBlocklistByAccount (
52 start: number, 63 start: number,
53 count: number, 64 count: number,
54 sort = '-createdAt', 65 sort = '-createdAt',
55 statusCodeExpected = 200 66 statusCodeExpected = HttpStatusCode.OK_200
56) { 67) {
57 const path = '/api/v1/users/me/blocklist/servers' 68 const path = '/api/v1/users/me/blocklist/servers'
58 69
@@ -65,7 +76,12 @@ function getServerBlocklistByAccount (
65 }) 76 })
66} 77}
67 78
68function addServerToAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { 79function addServerToAccountBlocklist (
80 url: string,
81 token: string,
82 serverToBlock: string,
83 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
84) {
69 const path = '/api/v1/users/me/blocklist/servers' 85 const path = '/api/v1/users/me/blocklist/servers'
70 86
71 return makePostBodyRequest({ 87 return makePostBodyRequest({
@@ -79,7 +95,12 @@ function addServerToAccountBlocklist (url: string, token: string, serverToBlock:
79 }) 95 })
80} 96}
81 97
82function removeServerFromAccountBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { 98function removeServerFromAccountBlocklist (
99 url: string,
100 token: string,
101 serverToBlock: string,
102 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
103) {
83 const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock 104 const path = '/api/v1/users/me/blocklist/servers/' + serverToBlock
84 105
85 return makeDeleteRequest({ 106 return makeDeleteRequest({
@@ -96,7 +117,7 @@ function getAccountBlocklistByServer (
96 start: number, 117 start: number,
97 count: number, 118 count: number,
98 sort = '-createdAt', 119 sort = '-createdAt',
99 statusCodeExpected = 200 120 statusCodeExpected = HttpStatusCode.OK_200
100) { 121) {
101 const path = '/api/v1/server/blocklist/accounts' 122 const path = '/api/v1/server/blocklist/accounts'
102 123
@@ -109,7 +130,12 @@ function getAccountBlocklistByServer (
109 }) 130 })
110} 131}
111 132
112function addAccountToServerBlocklist (url: string, token: string, accountToBlock: string, statusCodeExpected = 204) { 133function addAccountToServerBlocklist (
134 url: string,
135 token: string,
136 accountToBlock: string,
137 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
138) {
113 const path = '/api/v1/server/blocklist/accounts' 139 const path = '/api/v1/server/blocklist/accounts'
114 140
115 return makePostBodyRequest({ 141 return makePostBodyRequest({
@@ -123,7 +149,12 @@ function addAccountToServerBlocklist (url: string, token: string, accountToBlock
123 }) 149 })
124} 150}
125 151
126function removeAccountFromServerBlocklist (url: string, token: string, accountToUnblock: string, statusCodeExpected = 204) { 152function removeAccountFromServerBlocklist (
153 url: string,
154 token: string,
155 accountToUnblock: string,
156 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
157) {
127 const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock 158 const path = '/api/v1/server/blocklist/accounts/' + accountToUnblock
128 159
129 return makeDeleteRequest({ 160 return makeDeleteRequest({
@@ -140,7 +171,7 @@ function getServerBlocklistByServer (
140 start: number, 171 start: number,
141 count: number, 172 count: number,
142 sort = '-createdAt', 173 sort = '-createdAt',
143 statusCodeExpected = 200 174 statusCodeExpected = HttpStatusCode.OK_200
144) { 175) {
145 const path = '/api/v1/server/blocklist/servers' 176 const path = '/api/v1/server/blocklist/servers'
146 177
@@ -153,7 +184,12 @@ function getServerBlocklistByServer (
153 }) 184 })
154} 185}
155 186
156function addServerToServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { 187function addServerToServerBlocklist (
188 url: string,
189 token: string,
190 serverToBlock: string,
191 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
192) {
157 const path = '/api/v1/server/blocklist/servers' 193 const path = '/api/v1/server/blocklist/servers'
158 194
159 return makePostBodyRequest({ 195 return makePostBodyRequest({
@@ -167,7 +203,12 @@ function addServerToServerBlocklist (url: string, token: string, serverToBlock:
167 }) 203 })
168} 204}
169 205
170function removeServerFromServerBlocklist (url: string, token: string, serverToBlock: string, statusCodeExpected = 204) { 206function removeServerFromServerBlocklist (
207 url: string,
208 token: string,
209 serverToBlock: string,
210 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
211) {
171 const path = '/api/v1/server/blocklist/servers/' + serverToBlock 212 const path = '/api/v1/server/blocklist/servers/' + serverToBlock
172 213
173 return makeDeleteRequest({ 214 return makeDeleteRequest({
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index 98d222e1d..467a3d959 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -11,8 +11,14 @@ import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
11import { getUserNotificationSocket } from '../socket/socket-io' 11import { getUserNotificationSocket } from '../socket/socket-io'
12import { setAccessTokensToServers, userLogin } from './login' 12import { setAccessTokensToServers, userLogin } from './login'
13import { createUser, getMyUserInformation } from './users' 13import { createUser, getMyUserInformation } from './users'
14import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
14 15
15function updateMyNotificationSettings (url: string, token: string, settings: UserNotificationSetting, statusCodeExpected = 204) { 16function updateMyNotificationSettings (
17 url: string,
18 token: string,
19 settings: UserNotificationSetting,
20 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
21) {
16 const path = '/api/v1/users/me/notification-settings' 22 const path = '/api/v1/users/me/notification-settings'
17 23
18 return makePutBodyRequest({ 24 return makePutBodyRequest({
@@ -31,7 +37,7 @@ async function getUserNotifications (
31 count: number, 37 count: number,
32 unread?: boolean, 38 unread?: boolean,
33 sort = '-createdAt', 39 sort = '-createdAt',
34 statusCodeExpected = 200 40 statusCodeExpected = HttpStatusCode.OK_200
35) { 41) {
36 const path = '/api/v1/users/me/notifications' 42 const path = '/api/v1/users/me/notifications'
37 43
@@ -49,7 +55,7 @@ async function getUserNotifications (
49 }) 55 })
50} 56}
51 57
52function markAsReadNotifications (url: string, token: string, ids: number[], statusCodeExpected = 204) { 58function markAsReadNotifications (url: string, token: string, ids: number[], statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
53 const path = '/api/v1/users/me/notifications/read' 59 const path = '/api/v1/users/me/notifications/read'
54 60
55 return makePostBodyRequest({ 61 return makePostBodyRequest({
@@ -61,7 +67,7 @@ function markAsReadNotifications (url: string, token: string, ids: number[], sta
61 }) 67 })
62} 68}
63 69
64function markAsReadAllNotifications (url: string, token: string, statusCodeExpected = 204) { 70function markAsReadAllNotifications (url: string, token: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
65 const path = '/api/v1/users/me/notifications/read-all' 71 const path = '/api/v1/users/me/notifications/read-all'
66 72
67 return makePostBodyRequest({ 73 return makePostBodyRequest({
diff --git a/shared/extra-utils/users/user-subscriptions.ts b/shared/extra-utils/users/user-subscriptions.ts
index 6d402c073..edc7a3562 100644
--- a/shared/extra-utils/users/user-subscriptions.ts
+++ b/shared/extra-utils/users/user-subscriptions.ts
@@ -1,6 +1,7 @@
1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest } from '../requests/requests'
2import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2 3
3function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = 204) { 4function addUserSubscription (url: string, token: string, targetUri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
4 const path = '/api/v1/users/me/subscriptions' 5 const path = '/api/v1/users/me/subscriptions'
5 6
6 return makePostBodyRequest({ 7 return makePostBodyRequest({
@@ -19,7 +20,7 @@ function listUserSubscriptions (parameters: {
19 search?: string 20 search?: string
20 statusCodeExpected?: number 21 statusCodeExpected?: number
21}) { 22}) {
22 const { url, token, sort = '-createdAt', search, statusCodeExpected = 200 } = parameters 23 const { url, token, sort = '-createdAt', search, statusCodeExpected = HttpStatusCode.OK_200 } = parameters
23 const path = '/api/v1/users/me/subscriptions' 24 const path = '/api/v1/users/me/subscriptions'
24 25
25 return makeGetRequest({ 26 return makeGetRequest({
@@ -34,7 +35,7 @@ function listUserSubscriptions (parameters: {
34 }) 35 })
35} 36}
36 37
37function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = 200) { 38function listUserSubscriptionVideos (url: string, token: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {
38 const path = '/api/v1/users/me/subscriptions/videos' 39 const path = '/api/v1/users/me/subscriptions/videos'
39 40
40 return makeGetRequest({ 41 return makeGetRequest({
@@ -46,7 +47,7 @@ function listUserSubscriptionVideos (url: string, token: string, sort = '-create
46 }) 47 })
47} 48}
48 49
49function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 200) { 50function getUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.OK_200) {
50 const path = '/api/v1/users/me/subscriptions/' + uri 51 const path = '/api/v1/users/me/subscriptions/' + uri
51 52
52 return makeGetRequest({ 53 return makeGetRequest({
@@ -57,7 +58,7 @@ function getUserSubscription (url: string, token: string, uri: string, statusCod
57 }) 58 })
58} 59}
59 60
60function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = 204) { 61function removeUserSubscription (url: string, token: string, uri: string, statusCodeExpected = HttpStatusCode.NO_CONTENT_204) {
61 const path = '/api/v1/users/me/subscriptions/' + uri 62 const path = '/api/v1/users/me/subscriptions/' + uri
62 63
63 return makeDeleteRequest({ 64 return makeDeleteRequest({
@@ -68,7 +69,7 @@ function removeUserSubscription (url: string, token: string, uri: string, status
68 }) 69 })
69} 70}
70 71
71function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = 200) { 72function areSubscriptionsExist (url: string, token: string, uris: string[], statusCodeExpected = HttpStatusCode.OK_200) {
72 const path = '/api/v1/users/me/subscriptions/exist' 73 const path = '/api/v1/users/me/subscriptions/exist'
73 74
74 return makeGetRequest({ 75 return makeGetRequest({
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts
index ebb8bc257..c683dcdd1 100644
--- a/shared/extra-utils/users/users.ts
+++ b/shared/extra-utils/users/users.ts
@@ -7,6 +7,7 @@ import { UserRole } from '../../models/users/user-role'
7import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests' 7import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '../requests/requests'
8import { ServerInfo } from '../server/servers' 8import { ServerInfo } from '../server/servers'
9import { userLogin } from './login' 9import { userLogin } from './login'
10import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
10 11
11type CreateUserArgs = { 12type CreateUserArgs = {
12 url: string 13 url: string
@@ -29,7 +30,7 @@ function createUser (parameters: CreateUserArgs) {
29 videoQuota = 1000000, 30 videoQuota = 1000000,
30 videoQuotaDaily = -1, 31 videoQuotaDaily = -1,
31 role = UserRole.USER, 32 role = UserRole.USER,
32 specialStatus = 200 33 specialStatus = HttpStatusCode.OK_200
33 } = parameters 34 } = parameters
34 35
35 const path = '/api/v1/users' 36 const path = '/api/v1/users'
@@ -58,7 +59,7 @@ async function generateUserAccessToken (server: ServerInfo, username: string) {
58 return userLogin(server, { username, password }) 59 return userLogin(server, { username, password })
59} 60}
60 61
61function registerUser (url: string, username: string, password: string, specialStatus = 204) { 62function registerUser (url: string, username: string, password: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
62 const path = '/api/v1/users/register' 63 const path = '/api/v1/users/register'
63 const body = { 64 const body = {
64 username, 65 username,
@@ -94,11 +95,11 @@ function registerUserWithChannel (options: {
94 url: options.url, 95 url: options.url,
95 path, 96 path,
96 fields: body, 97 fields: body,
97 statusCodeExpected: 204 98 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
98 }) 99 })
99} 100}
100 101
101function getMyUserInformation (url: string, accessToken: string, specialStatus = 200) { 102function getMyUserInformation (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
102 const path = '/api/v1/users/me' 103 const path = '/api/v1/users/me'
103 104
104 return request(url) 105 return request(url)
@@ -109,7 +110,7 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus =
109 .expect('Content-Type', /json/) 110 .expect('Content-Type', /json/)
110} 111}
111 112
112function getUserScopedTokens (url: string, token: string, statusCodeExpected = 200) { 113function getUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
113 const path = '/api/v1/users/scoped-tokens' 114 const path = '/api/v1/users/scoped-tokens'
114 115
115 return makeGetRequest({ 116 return makeGetRequest({
@@ -120,7 +121,7 @@ function getUserScopedTokens (url: string, token: string, statusCodeExpected = 2
120 }) 121 })
121} 122}
122 123
123function renewUserScopedTokens (url: string, token: string, statusCodeExpected = 200) { 124function renewUserScopedTokens (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
124 const path = '/api/v1/users/scoped-tokens' 125 const path = '/api/v1/users/scoped-tokens'
125 126
126 return makePostBodyRequest({ 127 return makePostBodyRequest({
@@ -131,7 +132,7 @@ function renewUserScopedTokens (url: string, token: string, statusCodeExpected =
131 }) 132 })
132} 133}
133 134
134function deleteMe (url: string, accessToken: string, specialStatus = 204) { 135function deleteMe (url: string, accessToken: string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
135 const path = '/api/v1/users/me' 136 const path = '/api/v1/users/me'
136 137
137 return request(url) 138 return request(url)
@@ -141,7 +142,7 @@ function deleteMe (url: string, accessToken: string, specialStatus = 204) {
141 .expect(specialStatus) 142 .expect(specialStatus)
142} 143}
143 144
144function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = 200) { 145function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = HttpStatusCode.OK_200) {
145 const path = '/api/v1/users/me/video-quota-used' 146 const path = '/api/v1/users/me/video-quota-used'
146 147
147 return request(url) 148 return request(url)
@@ -160,11 +161,11 @@ function getUserInformation (url: string, accessToken: string, userId: number, w
160 .query({ withStats }) 161 .query({ withStats })
161 .set('Accept', 'application/json') 162 .set('Accept', 'application/json')
162 .set('Authorization', 'Bearer ' + accessToken) 163 .set('Authorization', 'Bearer ' + accessToken)
163 .expect(200) 164 .expect(HttpStatusCode.OK_200)
164 .expect('Content-Type', /json/) 165 .expect('Content-Type', /json/)
165} 166}
166 167
167function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = 200) { 168function getMyUserVideoRating (url: string, accessToken: string, videoId: number | string, specialStatus = HttpStatusCode.OK_200) {
168 const path = '/api/v1/users/me/videos/' + videoId + '/rating' 169 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
169 170
170 return request(url) 171 return request(url)
@@ -182,7 +183,7 @@ function getUsersList (url: string, accessToken: string) {
182 .get(path) 183 .get(path)
183 .set('Accept', 'application/json') 184 .set('Accept', 'application/json')
184 .set('Authorization', 'Bearer ' + accessToken) 185 .set('Authorization', 'Bearer ' + accessToken)
185 .expect(200) 186 .expect(HttpStatusCode.OK_200)
186 .expect('Content-Type', /json/) 187 .expect('Content-Type', /json/)
187} 188}
188 189
@@ -210,11 +211,11 @@ function getUsersListPaginationAndSort (
210 .query(query) 211 .query(query)
211 .set('Accept', 'application/json') 212 .set('Accept', 'application/json')
212 .set('Authorization', 'Bearer ' + accessToken) 213 .set('Authorization', 'Bearer ' + accessToken)
213 .expect(200) 214 .expect(HttpStatusCode.OK_200)
214 .expect('Content-Type', /json/) 215 .expect('Content-Type', /json/)
215} 216}
216 217
217function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { 218function removeUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
218 const path = '/api/v1/users' 219 const path = '/api/v1/users'
219 220
220 return request(url) 221 return request(url)
@@ -224,7 +225,13 @@ function removeUser (url: string, userId: number | string, accessToken: string,
224 .expect(expectedStatus) 225 .expect(expectedStatus)
225} 226}
226 227
227function blockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204, reason?: string) { 228function blockUser (
229 url: string,
230 userId: number | string,
231 accessToken: string,
232 expectedStatus = HttpStatusCode.NO_CONTENT_204,
233 reason?: string
234) {
228 const path = '/api/v1/users' 235 const path = '/api/v1/users'
229 let body: any 236 let body: any
230 if (reason) body = { reason } 237 if (reason) body = { reason }
@@ -237,7 +244,7 @@ function blockUser (url: string, userId: number | string, accessToken: string, e
237 .expect(expectedStatus) 244 .expect(expectedStatus)
238} 245}
239 246
240function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = 204) { 247function unblockUser (url: string, userId: number | string, accessToken: string, expectedStatus = HttpStatusCode.NO_CONTENT_204) {
241 const path = '/api/v1/users' 248 const path = '/api/v1/users'
242 249
243 return request(url) 250 return request(url)
@@ -247,7 +254,7 @@ function unblockUser (url: string, userId: number | string, accessToken: string,
247 .expect(expectedStatus) 254 .expect(expectedStatus)
248} 255}
249 256
250function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: number } & UserUpdateMe) { 257function updateMyUser (options: { url: string, accessToken: string, statusCodeExpected?: HttpStatusCode } & UserUpdateMe) {
251 const path = '/api/v1/users/me' 258 const path = '/api/v1/users/me'
252 259
253 const toSend: UserUpdateMe = omit(options, 'url', 'accessToken') 260 const toSend: UserUpdateMe = omit(options, 'url', 'accessToken')
@@ -257,7 +264,7 @@ function updateMyUser (options: { url: string, accessToken: string, statusCodeEx
257 path, 264 path,
258 token: options.accessToken, 265 token: options.accessToken,
259 fields: toSend, 266 fields: toSend,
260 statusCodeExpected: options.statusCodeExpected || 204 267 statusCodeExpected: options.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
261 }) 268 })
262} 269}
263 270
@@ -299,7 +306,7 @@ function updateUser (options: {
299 path, 306 path,
300 token: options.accessToken, 307 token: options.accessToken,
301 fields: toSend, 308 fields: toSend,
302 statusCodeExpected: 204 309 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
303 }) 310 })
304} 311}
305 312
@@ -310,11 +317,17 @@ function askResetPassword (url: string, email: string) {
310 url, 317 url,
311 path, 318 path,
312 fields: { email }, 319 fields: { email },
313 statusCodeExpected: 204 320 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
314 }) 321 })
315} 322}
316 323
317function resetPassword (url: string, userId: number, verificationString: string, password: string, statusCodeExpected = 204) { 324function resetPassword (
325 url: string,
326 userId: number,
327 verificationString: string,
328 password: string,
329 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
330) {
318 const path = '/api/v1/users/' + userId + '/reset-password' 331 const path = '/api/v1/users/' + userId + '/reset-password'
319 332
320 return makePostBodyRequest({ 333 return makePostBodyRequest({
@@ -332,11 +345,17 @@ function askSendVerifyEmail (url: string, email: string) {
332 url, 345 url,
333 path, 346 path,
334 fields: { email }, 347 fields: { email },
335 statusCodeExpected: 204 348 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
336 }) 349 })
337} 350}
338 351
339function verifyEmail (url: string, userId: number, verificationString: string, isPendingEmail = false, statusCodeExpected = 204) { 352function verifyEmail (
353 url: string,
354 userId: number,
355 verificationString: string,
356 isPendingEmail = false,
357 statusCodeExpected = HttpStatusCode.NO_CONTENT_204
358) {
340 const path = '/api/v1/users/' + userId + '/verify-email' 359 const path = '/api/v1/users/' + userId + '/verify-email'
341 360
342 return makePostBodyRequest({ 361 return makePostBodyRequest({