diff options
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 657 |
1 files changed, 242 insertions, 415 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 87ba775f6..1419ae820 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -2,63 +2,24 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' | ||
6 | import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' | ||
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
8 | import { | 5 | import { |
9 | addVideoCommentThread, | ||
10 | blockUser, | ||
11 | cleanupTests, | 6 | cleanupTests, |
12 | closeAllSequelize, | 7 | createSingleServer, |
13 | createUser, | ||
14 | deleteMe, | ||
15 | flushAndRunServer, | ||
16 | getAccountRatings, | ||
17 | getAdminAbusesList, | ||
18 | getBlacklistedVideosList, | ||
19 | getCustomConfig, | ||
20 | getMyUserInformation, | ||
21 | getMyUserVideoQuotaUsed, | ||
22 | getMyUserVideoRating, | ||
23 | getUserInformation, | ||
24 | getUsersList, | ||
25 | getUsersListPaginationAndSort, | ||
26 | getVideoChannel, | ||
27 | getVideosList, | ||
28 | installPlugin, | ||
29 | killallServers, | 8 | killallServers, |
30 | login, | ||
31 | makePutBodyRequest, | 9 | makePutBodyRequest, |
32 | rateVideo, | 10 | PeerTubeServer, |
33 | registerUserWithChannel, | 11 | setAccessTokensToServers, |
34 | removeUser, | ||
35 | removeVideo, | ||
36 | reportAbuse, | ||
37 | reRunServer, | ||
38 | ServerInfo, | ||
39 | setTokenField, | ||
40 | testImage, | 12 | testImage, |
41 | unblockUser, | ||
42 | updateAbuse, | ||
43 | updateCustomSubConfig, | ||
44 | updateMyAvatar, | ||
45 | updateMyUser, | ||
46 | updateUser, | ||
47 | uploadVideo, | ||
48 | userLogin, | ||
49 | waitJobs | 13 | waitJobs |
50 | } from '../../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
51 | import { follow } from '../../../../shared/extra-utils/server/follows' | 15 | import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' |
52 | import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | ||
53 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | ||
54 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
55 | 16 | ||
56 | const expect = chai.expect | 17 | const expect = chai.expect |
57 | 18 | ||
58 | describe('Test users', function () { | 19 | describe('Test users', function () { |
59 | let server: ServerInfo | 20 | let server: PeerTubeServer |
60 | let accessToken: string | 21 | let token: string |
61 | let accessTokenUser: string | 22 | let userToken: string |
62 | let videoId: number | 23 | let videoId: number |
63 | let userId: number | 24 | let userId: number |
64 | const user = { | 25 | const user = { |
@@ -69,7 +30,7 @@ describe('Test users', function () { | |||
69 | before(async function () { | 30 | before(async function () { |
70 | this.timeout(30000) | 31 | this.timeout(30000) |
71 | 32 | ||
72 | server = await flushAndRunServer(1, { | 33 | server = await createSingleServer(1, { |
73 | rates_limit: { | 34 | rates_limit: { |
74 | login: { | 35 | login: { |
75 | max: 30 | 36 | max: 30 |
@@ -79,7 +40,7 @@ describe('Test users', function () { | |||
79 | 40 | ||
80 | await setAccessTokensToServers([ server ]) | 41 | await setAccessTokensToServers([ server ]) |
81 | 42 | ||
82 | await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) | 43 | await server.plugins.install({ npmName: 'peertube-theme-background-red' }) |
83 | }) | 44 | }) |
84 | 45 | ||
85 | describe('OAuth client', function () { | 46 | describe('OAuth client', function () { |
@@ -90,158 +51,156 @@ describe('Test users', function () { | |||
90 | it('Should remove the last client') | 51 | it('Should remove the last client') |
91 | 52 | ||
92 | it('Should not login with an invalid client id', async function () { | 53 | it('Should not login with an invalid client id', async function () { |
93 | const client = { id: 'client', secret: server.client.secret } | 54 | const client = { id: 'client', secret: server.store.client.secret } |
94 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 55 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
95 | 56 | ||
96 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 57 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
97 | expect(res.body.error).to.contain('client is invalid') | 58 | expect(body.error).to.contain('client is invalid') |
98 | expect(res.body.type.startsWith('https://')).to.be.true | 59 | expect(body.type.startsWith('https://')).to.be.true |
99 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 60 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
100 | }) | 61 | }) |
101 | 62 | ||
102 | it('Should not login with an invalid client secret', async function () { | 63 | it('Should not login with an invalid client secret', async function () { |
103 | const client = { id: server.client.id, secret: 'coucou' } | 64 | const client = { id: server.store.client.id, secret: 'coucou' } |
104 | const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) | 65 | const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
105 | 66 | ||
106 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) | 67 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) |
107 | expect(res.body.error).to.contain('client is invalid') | 68 | expect(body.error).to.contain('client is invalid') |
108 | expect(res.body.type.startsWith('https://')).to.be.true | 69 | expect(body.type.startsWith('https://')).to.be.true |
109 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) | 70 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) |
110 | }) | 71 | }) |
111 | }) | 72 | }) |
112 | 73 | ||
113 | describe('Login', function () { | 74 | describe('Login', function () { |
114 | 75 | ||
115 | it('Should not login with an invalid username', async function () { | 76 | it('Should not login with an invalid username', async function () { |
116 | const user = { username: 'captain crochet', password: server.user.password } | 77 | const user = { username: 'captain crochet', password: server.store.user.password } |
117 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 78 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
118 | 79 | ||
119 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 80 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
120 | expect(res.body.error).to.contain('credentials are invalid') | 81 | expect(body.error).to.contain('credentials are invalid') |
121 | expect(res.body.type.startsWith('https://')).to.be.true | 82 | expect(body.type.startsWith('https://')).to.be.true |
122 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 83 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
123 | }) | 84 | }) |
124 | 85 | ||
125 | it('Should not login with an invalid password', async function () { | 86 | it('Should not login with an invalid password', async function () { |
126 | const user = { username: server.user.username, password: 'mew_three' } | 87 | const user = { username: server.store.user.username, password: 'mew_three' } |
127 | const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) | 88 | const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
128 | 89 | ||
129 | expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) | 90 | expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) |
130 | expect(res.body.error).to.contain('credentials are invalid') | 91 | expect(body.error).to.contain('credentials are invalid') |
131 | expect(res.body.type.startsWith('https://')).to.be.true | 92 | expect(body.type.startsWith('https://')).to.be.true |
132 | expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) | 93 | expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) |
133 | }) | 94 | }) |
134 | 95 | ||
135 | it('Should not be able to upload a video', async function () { | 96 | it('Should not be able to upload a video', async function () { |
136 | accessToken = 'my_super_token' | 97 | token = 'my_super_token' |
137 | 98 | ||
138 | const videoAttributes = {} | 99 | await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
139 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) | ||
140 | }) | 100 | }) |
141 | 101 | ||
142 | it('Should not be able to follow', async function () { | 102 | it('Should not be able to follow', async function () { |
143 | accessToken = 'my_super_token' | 103 | token = 'my_super_token' |
144 | await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) | 104 | |
105 | await server.follows.follow({ | ||
106 | hosts: [ 'http://example.com' ], | ||
107 | token, | ||
108 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
109 | }) | ||
145 | }) | 110 | }) |
146 | 111 | ||
147 | it('Should not be able to unfollow') | 112 | it('Should not be able to unfollow') |
148 | 113 | ||
149 | it('Should be able to login', async function () { | 114 | it('Should be able to login', async function () { |
150 | const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) | 115 | const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 }) |
151 | 116 | ||
152 | accessToken = res.body.access_token | 117 | token = body.access_token |
153 | }) | 118 | }) |
154 | 119 | ||
155 | it('Should be able to login with an insensitive username', async function () { | 120 | it('Should be able to login with an insensitive username', async function () { |
156 | const user = { username: 'RoOt', password: server.user.password } | 121 | const user = { username: 'RoOt', password: server.store.user.password } |
157 | await login(server.url, server.client, user, HttpStatusCode.OK_200) | 122 | await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 }) |
158 | 123 | ||
159 | const user2 = { username: 'rOoT', password: server.user.password } | 124 | const user2 = { username: 'rOoT', password: server.store.user.password } |
160 | await login(server.url, server.client, user2, HttpStatusCode.OK_200) | 125 | await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) |
161 | 126 | ||
162 | const user3 = { username: 'ROOt', password: server.user.password } | 127 | const user3 = { username: 'ROOt', password: server.store.user.password } |
163 | await login(server.url, server.client, user3, HttpStatusCode.OK_200) | 128 | await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) |
164 | }) | 129 | }) |
165 | }) | 130 | }) |
166 | 131 | ||
167 | describe('Upload', function () { | 132 | describe('Upload', function () { |
168 | 133 | ||
169 | it('Should upload the video with the correct token', async function () { | 134 | it('Should upload the video with the correct token', async function () { |
170 | const videoAttributes = {} | 135 | await server.videos.upload({ token }) |
171 | await uploadVideo(server.url, accessToken, videoAttributes) | 136 | const { data } = await server.videos.list() |
172 | const res = await getVideosList(server.url) | 137 | const video = data[0] |
173 | const video = res.body.data[0] | ||
174 | 138 | ||
175 | expect(video.account.name).to.equal('root') | 139 | expect(video.account.name).to.equal('root') |
176 | videoId = video.id | 140 | videoId = video.id |
177 | }) | 141 | }) |
178 | 142 | ||
179 | it('Should upload the video again with the correct token', async function () { | 143 | it('Should upload the video again with the correct token', async function () { |
180 | const videoAttributes = {} | 144 | await server.videos.upload({ token }) |
181 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
182 | }) | 145 | }) |
183 | }) | 146 | }) |
184 | 147 | ||
185 | describe('Ratings', function () { | 148 | describe('Ratings', function () { |
186 | 149 | ||
187 | it('Should retrieve a video rating', async function () { | 150 | it('Should retrieve a video rating', async function () { |
188 | await rateVideo(server.url, accessToken, videoId, 'like') | 151 | await server.videos.rate({ id: videoId, rating: 'like' }) |
189 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | 152 | const rating = await server.users.getMyRating({ token, videoId }) |
190 | const rating = res.body | ||
191 | 153 | ||
192 | expect(rating.videoId).to.equal(videoId) | 154 | expect(rating.videoId).to.equal(videoId) |
193 | expect(rating.rating).to.equal('like') | 155 | expect(rating.rating).to.equal('like') |
194 | }) | 156 | }) |
195 | 157 | ||
196 | it('Should retrieve ratings list', async function () { | 158 | it('Should retrieve ratings list', async function () { |
197 | await rateVideo(server.url, accessToken, videoId, 'like') | 159 | await server.videos.rate({ id: videoId, rating: 'like' }) |
198 | 160 | ||
199 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) | 161 | const body = await server.accounts.listRatings({ accountName: server.store.user.username }) |
200 | const ratings = res.body | ||
201 | 162 | ||
202 | expect(ratings.total).to.equal(1) | 163 | expect(body.total).to.equal(1) |
203 | expect(ratings.data[0].video.id).to.equal(videoId) | 164 | expect(body.data[0].video.id).to.equal(videoId) |
204 | expect(ratings.data[0].rating).to.equal('like') | 165 | expect(body.data[0].rating).to.equal('like') |
205 | }) | 166 | }) |
206 | 167 | ||
207 | it('Should retrieve ratings list by rating type', async function () { | 168 | it('Should retrieve ratings list by rating type', async function () { |
208 | { | 169 | { |
209 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | 170 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' }) |
210 | const ratings = res.body | 171 | expect(body.data.length).to.equal(1) |
211 | expect(ratings.data.length).to.equal(1) | ||
212 | } | 172 | } |
213 | 173 | ||
214 | { | 174 | { |
215 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | 175 | const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' }) |
216 | const ratings = res.body | 176 | expect(body.data.length).to.equal(0) |
217 | expect(ratings.data.length).to.equal(0) | ||
218 | } | 177 | } |
219 | }) | 178 | }) |
220 | }) | 179 | }) |
221 | 180 | ||
222 | describe('Remove video', function () { | 181 | describe('Remove video', function () { |
223 | it('Should not be able to remove the video with an incorrect token', async function () { | 182 | it('Should not be able to remove the video with an incorrect token', async function () { |
224 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) | 183 | await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
225 | }) | 184 | }) |
226 | 185 | ||
227 | it('Should not be able to remove the video with the token of another account') | 186 | it('Should not be able to remove the video with the token of another account') |
228 | 187 | ||
229 | it('Should be able to remove the video with the correct token', async function () { | 188 | it('Should be able to remove the video with the correct token', async function () { |
230 | await removeVideo(server.url, accessToken, videoId) | 189 | await server.videos.remove({ token, id: videoId }) |
231 | }) | 190 | }) |
232 | }) | 191 | }) |
233 | 192 | ||
234 | describe('Logout', function () { | 193 | describe('Logout', function () { |
235 | it('Should logout (revoke token)', async function () { | 194 | it('Should logout (revoke token)', async function () { |
236 | await logout(server.url, server.accessToken) | 195 | await server.login.logout({ token: server.accessToken }) |
237 | }) | 196 | }) |
238 | 197 | ||
239 | it('Should not be able to get the user information', async function () { | 198 | it('Should not be able to get the user information', async function () { |
240 | await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) | 199 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
241 | }) | 200 | }) |
242 | 201 | ||
243 | it('Should not be able to upload a video', async function () { | 202 | it('Should not be able to upload a video', async function () { |
244 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) | 203 | await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
245 | }) | 204 | }) |
246 | 205 | ||
247 | it('Should not be able to rate a video', async function () { | 206 | it('Should not be able to rate a video', async function () { |
@@ -255,79 +214,70 @@ describe('Test users', function () { | |||
255 | path: path + videoId, | 214 | path: path + videoId, |
256 | token: 'wrong token', | 215 | token: 'wrong token', |
257 | fields: data, | 216 | fields: data, |
258 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | 217 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
259 | } | 218 | } |
260 | await makePutBodyRequest(options) | 219 | await makePutBodyRequest(options) |
261 | }) | 220 | }) |
262 | 221 | ||
263 | it('Should be able to login again', async function () { | 222 | it('Should be able to login again', async function () { |
264 | const res = await login(server.url, server.client, server.user) | 223 | const body = await server.login.login() |
265 | server.accessToken = res.body.access_token | 224 | server.accessToken = body.access_token |
266 | server.refreshToken = res.body.refresh_token | 225 | server.refreshToken = body.refresh_token |
267 | }) | 226 | }) |
268 | 227 | ||
269 | it('Should be able to get my user information again', async function () { | 228 | it('Should be able to get my user information again', async function () { |
270 | await getMyUserInformation(server.url, server.accessToken) | 229 | await server.users.getMyInfo() |
271 | }) | 230 | }) |
272 | 231 | ||
273 | it('Should have an expired access token', async function () { | 232 | it('Should have an expired access token', async function () { |
274 | this.timeout(15000) | 233 | this.timeout(15000) |
275 | 234 | ||
276 | await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) | 235 | await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) |
277 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) | 236 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) |
278 | 237 | ||
279 | killallServers([ server ]) | 238 | await killallServers([ server ]) |
280 | await reRunServer(server) | 239 | await server.run() |
281 | 240 | ||
282 | await getMyUserInformation(server.url, server.accessToken, 401) | 241 | await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
283 | }) | 242 | }) |
284 | 243 | ||
285 | it('Should not be able to refresh an access token with an expired refresh token', async function () { | 244 | it('Should not be able to refresh an access token with an expired refresh token', async function () { |
286 | await refreshToken(server, server.refreshToken, 400) | 245 | await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
287 | }) | 246 | }) |
288 | 247 | ||
289 | it('Should refresh the token', async function () { | 248 | it('Should refresh the token', async function () { |
290 | this.timeout(15000) | 249 | this.timeout(15000) |
291 | 250 | ||
292 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() | 251 | const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() |
293 | await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate) | 252 | await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) |
294 | 253 | ||
295 | killallServers([ server ]) | 254 | await killallServers([ server ]) |
296 | await reRunServer(server) | 255 | await server.run() |
297 | 256 | ||
298 | const res = await refreshToken(server, server.refreshToken) | 257 | const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) |
299 | server.accessToken = res.body.access_token | 258 | server.accessToken = res.body.access_token |
300 | server.refreshToken = res.body.refresh_token | 259 | server.refreshToken = res.body.refresh_token |
301 | }) | 260 | }) |
302 | 261 | ||
303 | it('Should be able to get my user information again', async function () { | 262 | it('Should be able to get my user information again', async function () { |
304 | await getMyUserInformation(server.url, server.accessToken) | 263 | await server.users.getMyInfo() |
305 | }) | 264 | }) |
306 | }) | 265 | }) |
307 | 266 | ||
308 | describe('Creating a user', function () { | 267 | describe('Creating a user', function () { |
309 | 268 | ||
310 | it('Should be able to create a new user', async function () { | 269 | it('Should be able to create a new user', async function () { |
311 | await createUser({ | 270 | await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) |
312 | url: server.url, | ||
313 | accessToken: accessToken, | ||
314 | username: user.username, | ||
315 | password: user.password, | ||
316 | videoQuota: 2 * 1024 * 1024, | ||
317 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST | ||
318 | }) | ||
319 | }) | 271 | }) |
320 | 272 | ||
321 | it('Should be able to login with this user', async function () { | 273 | it('Should be able to login with this user', async function () { |
322 | accessTokenUser = await userLogin(server, user) | 274 | userToken = await server.login.getAccessToken(user) |
323 | }) | 275 | }) |
324 | 276 | ||
325 | it('Should be able to get user information', async function () { | 277 | it('Should be able to get user information', async function () { |
326 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | 278 | const userMe = await server.users.getMyInfo({ token: userToken }) |
327 | const userMe: MyUser = res1.body | ||
328 | 279 | ||
329 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) | 280 | const userGet = await server.users.get({ userId: userMe.id, withStats: true }) |
330 | const userGet: User = res2.body | ||
331 | 281 | ||
332 | for (const user of [ userMe, userGet ]) { | 282 | for (const user of [ userMe, userGet ]) { |
333 | expect(user.username).to.equal('user_1') | 283 | expect(user.username).to.equal('user_1') |
@@ -363,34 +313,28 @@ describe('Test users', function () { | |||
363 | it('Should be able to upload a video with this user', async function () { | 313 | it('Should be able to upload a video with this user', async function () { |
364 | this.timeout(10000) | 314 | this.timeout(10000) |
365 | 315 | ||
366 | const videoAttributes = { | 316 | const attributes = { |
367 | name: 'super user video', | 317 | name: 'super user video', |
368 | fixture: 'video_short.webm' | 318 | fixture: 'video_short.webm' |
369 | } | 319 | } |
370 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 320 | await server.videos.upload({ token: userToken, attributes }) |
371 | }) | 321 | }) |
372 | 322 | ||
373 | it('Should have video quota updated', async function () { | 323 | it('Should have video quota updated', async function () { |
374 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | 324 | const quota = await server.users.getMyQuotaUsed({ token: userToken }) |
375 | const data = res.body | 325 | expect(quota.videoQuotaUsed).to.equal(218910) |
376 | |||
377 | expect(data.videoQuotaUsed).to.equal(218910) | ||
378 | |||
379 | const resUsers = await getUsersList(server.url, server.accessToken) | ||
380 | 326 | ||
381 | const users: User[] = resUsers.body.data | 327 | const { data } = await server.users.list() |
382 | const tmpUser = users.find(u => u.username === user.username) | 328 | const tmpUser = data.find(u => u.username === user.username) |
383 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | 329 | expect(tmpUser.videoQuotaUsed).to.equal(218910) |
384 | }) | 330 | }) |
385 | 331 | ||
386 | it('Should be able to list my videos', async function () { | 332 | it('Should be able to list my videos', async function () { |
387 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | 333 | const { total, data } = await server.videos.listMyVideos({ token: userToken }) |
388 | expect(res.body.total).to.equal(1) | 334 | expect(total).to.equal(1) |
335 | expect(data).to.have.lengthOf(1) | ||
389 | 336 | ||
390 | const videos = res.body.data | 337 | const video: Video = data[0] |
391 | expect(videos).to.have.lengthOf(1) | ||
392 | |||
393 | const video: Video = videos[0] | ||
394 | expect(video.name).to.equal('super user video') | 338 | expect(video.name).to.equal('super user video') |
395 | expect(video.thumbnailPath).to.not.be.null | 339 | expect(video.thumbnailPath).to.not.be.null |
396 | expect(video.previewPath).to.not.be.null | 340 | expect(video.previewPath).to.not.be.null |
@@ -398,19 +342,15 @@ describe('Test users', function () { | |||
398 | 342 | ||
399 | it('Should be able to search in my videos', async function () { | 343 | it('Should be able to search in my videos', async function () { |
400 | { | 344 | { |
401 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') | 345 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) |
402 | expect(res.body.total).to.equal(1) | 346 | expect(total).to.equal(1) |
403 | 347 | expect(data).to.have.lengthOf(1) | |
404 | const videos = res.body.data | ||
405 | expect(videos).to.have.lengthOf(1) | ||
406 | } | 348 | } |
407 | 349 | ||
408 | { | 350 | { |
409 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') | 351 | const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) |
410 | expect(res.body.total).to.equal(0) | 352 | expect(total).to.equal(0) |
411 | 353 | expect(data).to.have.lengthOf(0) | |
412 | const videos = res.body.data | ||
413 | expect(videos).to.have.lengthOf(0) | ||
414 | } | 354 | } |
415 | }) | 355 | }) |
416 | 356 | ||
@@ -418,28 +358,25 @@ describe('Test users', function () { | |||
418 | this.timeout(60000) | 358 | this.timeout(60000) |
419 | 359 | ||
420 | { | 360 | { |
421 | const res = await getCustomConfig(server.url, server.accessToken) | 361 | const config = await server.config.getCustomConfig() |
422 | const config = res.body as CustomConfig | ||
423 | config.transcoding.webtorrent.enabled = false | 362 | config.transcoding.webtorrent.enabled = false |
424 | config.transcoding.hls.enabled = true | 363 | config.transcoding.hls.enabled = true |
425 | config.transcoding.enabled = true | 364 | config.transcoding.enabled = true |
426 | await updateCustomSubConfig(server.url, server.accessToken, config) | 365 | await server.config.updateCustomSubConfig({ newConfig: config }) |
427 | } | 366 | } |
428 | 367 | ||
429 | { | 368 | { |
430 | const videoAttributes = { | 369 | const attributes = { |
431 | name: 'super user video 2', | 370 | name: 'super user video 2', |
432 | fixture: 'video_short.webm' | 371 | fixture: 'video_short.webm' |
433 | } | 372 | } |
434 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 373 | await server.videos.upload({ token: userToken, attributes }) |
435 | 374 | ||
436 | await waitJobs([ server ]) | 375 | await waitJobs([ server ]) |
437 | } | 376 | } |
438 | 377 | ||
439 | { | 378 | { |
440 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | 379 | const data = await server.users.getMyQuotaUsed({ token: userToken }) |
441 | const data = res.body | ||
442 | |||
443 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | 380 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) |
444 | } | 381 | } |
445 | }) | 382 | }) |
@@ -448,21 +385,18 @@ describe('Test users', function () { | |||
448 | describe('Users listing', function () { | 385 | describe('Users listing', function () { |
449 | 386 | ||
450 | it('Should list all the users', async function () { | 387 | it('Should list all the users', async function () { |
451 | const res = await getUsersList(server.url, server.accessToken) | 388 | const { data, total } = await server.users.list() |
452 | const result = res.body | ||
453 | const total = result.total | ||
454 | const users = result.data | ||
455 | 389 | ||
456 | expect(total).to.equal(2) | 390 | expect(total).to.equal(2) |
457 | expect(users).to.be.an('array') | 391 | expect(data).to.be.an('array') |
458 | expect(users.length).to.equal(2) | 392 | expect(data.length).to.equal(2) |
459 | 393 | ||
460 | const user = users[0] | 394 | const user = data[0] |
461 | expect(user.username).to.equal('user_1') | 395 | expect(user.username).to.equal('user_1') |
462 | expect(user.email).to.equal('user_1@example.com') | 396 | expect(user.email).to.equal('user_1@example.com') |
463 | expect(user.nsfwPolicy).to.equal('display') | 397 | expect(user.nsfwPolicy).to.equal('display') |
464 | 398 | ||
465 | const rootUser = users[1] | 399 | const rootUser = data[1] |
466 | expect(rootUser.username).to.equal('root') | 400 | expect(rootUser.username).to.equal('root') |
467 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 401 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
468 | expect(user.nsfwPolicy).to.equal('display') | 402 | expect(user.nsfwPolicy).to.equal('display') |
@@ -474,16 +408,12 @@ describe('Test users', function () { | |||
474 | }) | 408 | }) |
475 | 409 | ||
476 | it('Should list only the first user by username asc', async function () { | 410 | it('Should list only the first user by username asc', async function () { |
477 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | 411 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' }) |
478 | |||
479 | const result = res.body | ||
480 | const total = result.total | ||
481 | const users = result.data | ||
482 | 412 | ||
483 | expect(total).to.equal(2) | 413 | expect(total).to.equal(2) |
484 | expect(users.length).to.equal(1) | 414 | expect(data.length).to.equal(1) |
485 | 415 | ||
486 | const user = users[0] | 416 | const user = data[0] |
487 | expect(user.username).to.equal('root') | 417 | expect(user.username).to.equal('root') |
488 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 418 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
489 | expect(user.roleLabel).to.equal('Administrator') | 419 | expect(user.roleLabel).to.equal('Administrator') |
@@ -491,111 +421,90 @@ describe('Test users', function () { | |||
491 | }) | 421 | }) |
492 | 422 | ||
493 | it('Should list only the first user by username desc', async function () { | 423 | it('Should list only the first user by username desc', async function () { |
494 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | 424 | const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' }) |
495 | const result = res.body | ||
496 | const total = result.total | ||
497 | const users = result.data | ||
498 | 425 | ||
499 | expect(total).to.equal(2) | 426 | expect(total).to.equal(2) |
500 | expect(users.length).to.equal(1) | 427 | expect(data.length).to.equal(1) |
501 | 428 | ||
502 | const user = users[0] | 429 | const user = data[0] |
503 | expect(user.username).to.equal('user_1') | 430 | expect(user.username).to.equal('user_1') |
504 | expect(user.email).to.equal('user_1@example.com') | 431 | expect(user.email).to.equal('user_1@example.com') |
505 | expect(user.nsfwPolicy).to.equal('display') | 432 | expect(user.nsfwPolicy).to.equal('display') |
506 | }) | 433 | }) |
507 | 434 | ||
508 | it('Should list only the second user by createdAt desc', async function () { | 435 | it('Should list only the second user by createdAt desc', async function () { |
509 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | 436 | const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' }) |
510 | const result = res.body | ||
511 | const total = result.total | ||
512 | const users = result.data | ||
513 | |||
514 | expect(total).to.equal(2) | 437 | expect(total).to.equal(2) |
515 | expect(users.length).to.equal(1) | ||
516 | 438 | ||
517 | const user = users[0] | 439 | expect(data.length).to.equal(1) |
440 | |||
441 | const user = data[0] | ||
518 | expect(user.username).to.equal('user_1') | 442 | expect(user.username).to.equal('user_1') |
519 | expect(user.email).to.equal('user_1@example.com') | 443 | expect(user.email).to.equal('user_1@example.com') |
520 | expect(user.nsfwPolicy).to.equal('display') | 444 | expect(user.nsfwPolicy).to.equal('display') |
521 | }) | 445 | }) |
522 | 446 | ||
523 | it('Should list all the users by createdAt asc', async function () { | 447 | it('Should list all the users by createdAt asc', async function () { |
524 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | 448 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' }) |
525 | const result = res.body | ||
526 | const total = result.total | ||
527 | const users = result.data | ||
528 | 449 | ||
529 | expect(total).to.equal(2) | 450 | expect(total).to.equal(2) |
530 | expect(users.length).to.equal(2) | 451 | expect(data.length).to.equal(2) |
531 | 452 | ||
532 | expect(users[0].username).to.equal('root') | 453 | expect(data[0].username).to.equal('root') |
533 | expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') | 454 | expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') |
534 | expect(users[0].nsfwPolicy).to.equal('display') | 455 | expect(data[0].nsfwPolicy).to.equal('display') |
535 | 456 | ||
536 | expect(users[1].username).to.equal('user_1') | 457 | expect(data[1].username).to.equal('user_1') |
537 | expect(users[1].email).to.equal('user_1@example.com') | 458 | expect(data[1].email).to.equal('user_1@example.com') |
538 | expect(users[1].nsfwPolicy).to.equal('display') | 459 | expect(data[1].nsfwPolicy).to.equal('display') |
539 | }) | 460 | }) |
540 | 461 | ||
541 | it('Should search user by username', async function () { | 462 | it('Should search user by username', async function () { |
542 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | 463 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) |
543 | const users = res.body.data as User[] | 464 | expect(total).to.equal(1) |
544 | 465 | expect(data.length).to.equal(1) | |
545 | expect(res.body.total).to.equal(1) | 466 | expect(data[0].username).to.equal('root') |
546 | expect(users.length).to.equal(1) | ||
547 | |||
548 | expect(users[0].username).to.equal('root') | ||
549 | }) | 467 | }) |
550 | 468 | ||
551 | it('Should search user by email', async function () { | 469 | it('Should search user by email', async function () { |
552 | { | 470 | { |
553 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | 471 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) |
554 | const users = res.body.data as User[] | 472 | expect(total).to.equal(1) |
555 | 473 | expect(data.length).to.equal(1) | |
556 | expect(res.body.total).to.equal(1) | 474 | expect(data[0].username).to.equal('user_1') |
557 | expect(users.length).to.equal(1) | 475 | expect(data[0].email).to.equal('user_1@example.com') |
558 | |||
559 | expect(users[0].username).to.equal('user_1') | ||
560 | expect(users[0].email).to.equal('user_1@example.com') | ||
561 | } | 476 | } |
562 | 477 | ||
563 | { | 478 | { |
564 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | 479 | const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) |
565 | const users = res.body.data as User[] | 480 | expect(total).to.equal(2) |
566 | 481 | expect(data.length).to.equal(2) | |
567 | expect(res.body.total).to.equal(2) | 482 | expect(data[0].username).to.equal('root') |
568 | expect(users.length).to.equal(2) | 483 | expect(data[1].username).to.equal('user_1') |
569 | |||
570 | expect(users[0].username).to.equal('root') | ||
571 | expect(users[1].username).to.equal('user_1') | ||
572 | } | 484 | } |
573 | }) | 485 | }) |
574 | }) | 486 | }) |
575 | 487 | ||
576 | describe('Update my account', function () { | 488 | describe('Update my account', function () { |
489 | |||
577 | it('Should update my password', async function () { | 490 | it('Should update my password', async function () { |
578 | await updateMyUser({ | 491 | await server.users.updateMe({ |
579 | url: server.url, | 492 | token: userToken, |
580 | accessToken: accessTokenUser, | ||
581 | currentPassword: 'super password', | 493 | currentPassword: 'super password', |
582 | password: 'new password' | 494 | password: 'new password' |
583 | }) | 495 | }) |
584 | user.password = 'new password' | 496 | user.password = 'new password' |
585 | 497 | ||
586 | await userLogin(server, user, HttpStatusCode.OK_200) | 498 | await server.login.login({ user }) |
587 | }) | 499 | }) |
588 | 500 | ||
589 | it('Should be able to change the NSFW display attribute', async function () { | 501 | it('Should be able to change the NSFW display attribute', async function () { |
590 | await updateMyUser({ | 502 | await server.users.updateMe({ |
591 | url: server.url, | 503 | token: userToken, |
592 | accessToken: accessTokenUser, | ||
593 | nsfwPolicy: 'do_not_list' | 504 | nsfwPolicy: 'do_not_list' |
594 | }) | 505 | }) |
595 | 506 | ||
596 | const res = await getMyUserInformation(server.url, accessTokenUser) | 507 | const user = await server.users.getMyInfo({ token: userToken }) |
597 | const user = res.body | ||
598 | |||
599 | expect(user.username).to.equal('user_1') | 508 | expect(user.username).to.equal('user_1') |
600 | expect(user.email).to.equal('user_1@example.com') | 509 | expect(user.email).to.equal('user_1@example.com') |
601 | expect(user.nsfwPolicy).to.equal('do_not_list') | 510 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -606,42 +515,33 @@ describe('Test users', function () { | |||
606 | }) | 515 | }) |
607 | 516 | ||
608 | it('Should be able to change the autoPlayVideo attribute', async function () { | 517 | it('Should be able to change the autoPlayVideo attribute', async function () { |
609 | await updateMyUser({ | 518 | await server.users.updateMe({ |
610 | url: server.url, | 519 | token: userToken, |
611 | accessToken: accessTokenUser, | ||
612 | autoPlayVideo: false | 520 | autoPlayVideo: false |
613 | }) | 521 | }) |
614 | 522 | ||
615 | const res = await getMyUserInformation(server.url, accessTokenUser) | 523 | const user = await server.users.getMyInfo({ token: userToken }) |
616 | const user = res.body | ||
617 | |||
618 | expect(user.autoPlayVideo).to.be.false | 524 | expect(user.autoPlayVideo).to.be.false |
619 | }) | 525 | }) |
620 | 526 | ||
621 | it('Should be able to change the autoPlayNextVideo attribute', async function () { | 527 | it('Should be able to change the autoPlayNextVideo attribute', async function () { |
622 | await updateMyUser({ | 528 | await server.users.updateMe({ |
623 | url: server.url, | 529 | token: userToken, |
624 | accessToken: accessTokenUser, | ||
625 | autoPlayNextVideo: true | 530 | autoPlayNextVideo: true |
626 | }) | 531 | }) |
627 | 532 | ||
628 | const res = await getMyUserInformation(server.url, accessTokenUser) | 533 | const user = await server.users.getMyInfo({ token: userToken }) |
629 | const user = res.body | ||
630 | |||
631 | expect(user.autoPlayNextVideo).to.be.true | 534 | expect(user.autoPlayNextVideo).to.be.true |
632 | }) | 535 | }) |
633 | 536 | ||
634 | it('Should be able to change the email attribute', async function () { | 537 | it('Should be able to change the email attribute', async function () { |
635 | await updateMyUser({ | 538 | await server.users.updateMe({ |
636 | url: server.url, | 539 | token: userToken, |
637 | accessToken: accessTokenUser, | ||
638 | currentPassword: 'new password', | 540 | currentPassword: 'new password', |
639 | email: 'updated@example.com' | 541 | email: 'updated@example.com' |
640 | }) | 542 | }) |
641 | 543 | ||
642 | const res = await getMyUserInformation(server.url, accessTokenUser) | 544 | const user = await server.users.getMyInfo({ token: userToken }) |
643 | const user = res.body | ||
644 | |||
645 | expect(user.username).to.equal('user_1') | 545 | expect(user.username).to.equal('user_1') |
646 | expect(user.email).to.equal('updated@example.com') | 546 | expect(user.email).to.equal('updated@example.com') |
647 | expect(user.nsfwPolicy).to.equal('do_not_list') | 547 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -654,15 +554,9 @@ describe('Test users', function () { | |||
654 | it('Should be able to update my avatar with a gif', async function () { | 554 | it('Should be able to update my avatar with a gif', async function () { |
655 | const fixture = 'avatar.gif' | 555 | const fixture = 'avatar.gif' |
656 | 556 | ||
657 | await updateMyAvatar({ | 557 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
658 | url: server.url, | ||
659 | accessToken: accessTokenUser, | ||
660 | fixture | ||
661 | }) | ||
662 | |||
663 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
664 | const user = res.body | ||
665 | 558 | ||
559 | const user = await server.users.getMyInfo({ token: userToken }) | ||
666 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') | 560 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') |
667 | }) | 561 | }) |
668 | 562 | ||
@@ -670,29 +564,17 @@ describe('Test users', function () { | |||
670 | for (const extension of [ '.png', '.gif' ]) { | 564 | for (const extension of [ '.png', '.gif' ]) { |
671 | const fixture = 'avatar' + extension | 565 | const fixture = 'avatar' + extension |
672 | 566 | ||
673 | await updateMyAvatar({ | 567 | await server.users.updateMyAvatar({ token: userToken, fixture }) |
674 | url: server.url, | ||
675 | accessToken: accessTokenUser, | ||
676 | fixture | ||
677 | }) | ||
678 | |||
679 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
680 | const user = res.body | ||
681 | 568 | ||
569 | const user = await server.users.getMyInfo({ token: userToken }) | ||
682 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) | 570 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) |
683 | } | 571 | } |
684 | }) | 572 | }) |
685 | 573 | ||
686 | it('Should be able to update my display name', async function () { | 574 | it('Should be able to update my display name', async function () { |
687 | await updateMyUser({ | 575 | await server.users.updateMe({ token: userToken, displayName: 'new display name' }) |
688 | url: server.url, | ||
689 | accessToken: accessTokenUser, | ||
690 | displayName: 'new display name' | ||
691 | }) | ||
692 | |||
693 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
694 | const user = res.body | ||
695 | 576 | ||
577 | const user = await server.users.getMyInfo({ token: userToken }) | ||
696 | expect(user.username).to.equal('user_1') | 578 | expect(user.username).to.equal('user_1') |
697 | expect(user.email).to.equal('updated@example.com') | 579 | expect(user.email).to.equal('updated@example.com') |
698 | expect(user.nsfwPolicy).to.equal('do_not_list') | 580 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -703,15 +585,9 @@ describe('Test users', function () { | |||
703 | }) | 585 | }) |
704 | 586 | ||
705 | it('Should be able to update my description', async function () { | 587 | it('Should be able to update my description', async function () { |
706 | await updateMyUser({ | 588 | await server.users.updateMe({ token: userToken, description: 'my super description updated' }) |
707 | url: server.url, | ||
708 | accessToken: accessTokenUser, | ||
709 | description: 'my super description updated' | ||
710 | }) | ||
711 | |||
712 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
713 | const user: User = res.body | ||
714 | 589 | ||
590 | const user = await server.users.getMyInfo({ token: userToken }) | ||
715 | expect(user.username).to.equal('user_1') | 591 | expect(user.username).to.equal('user_1') |
716 | expect(user.email).to.equal('updated@example.com') | 592 | expect(user.email).to.equal('updated@example.com') |
717 | expect(user.nsfwPolicy).to.equal('do_not_list') | 593 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -725,30 +601,21 @@ describe('Test users', function () { | |||
725 | 601 | ||
726 | it('Should be able to update my theme', async function () { | 602 | it('Should be able to update my theme', async function () { |
727 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | 603 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { |
728 | await updateMyUser({ | 604 | await server.users.updateMe({ token: userToken, theme }) |
729 | url: server.url, | ||
730 | accessToken: accessTokenUser, | ||
731 | theme | ||
732 | }) | ||
733 | 605 | ||
734 | const res = await getMyUserInformation(server.url, accessTokenUser) | 606 | const user = await server.users.getMyInfo({ token: userToken }) |
735 | const body: User = res.body | 607 | expect(user.theme).to.equal(theme) |
736 | |||
737 | expect(body.theme).to.equal(theme) | ||
738 | } | 608 | } |
739 | }) | 609 | }) |
740 | 610 | ||
741 | it('Should be able to update my modal preferences', async function () { | 611 | it('Should be able to update my modal preferences', async function () { |
742 | await updateMyUser({ | 612 | await server.users.updateMe({ |
743 | url: server.url, | 613 | token: userToken, |
744 | accessToken: accessTokenUser, | ||
745 | noInstanceConfigWarningModal: true, | 614 | noInstanceConfigWarningModal: true, |
746 | noWelcomeModal: true | 615 | noWelcomeModal: true |
747 | }) | 616 | }) |
748 | 617 | ||
749 | const res = await getMyUserInformation(server.url, accessTokenUser) | 618 | const user = await server.users.getMyInfo({ token: userToken }) |
750 | const user: User = res.body | ||
751 | |||
752 | expect(user.noWelcomeModal).to.be.true | 619 | expect(user.noWelcomeModal).to.be.true |
753 | expect(user.noInstanceConfigWarningModal).to.be.true | 620 | expect(user.noInstanceConfigWarningModal).to.be.true |
754 | }) | 621 | }) |
@@ -756,10 +623,9 @@ describe('Test users', function () { | |||
756 | 623 | ||
757 | describe('Updating another user', function () { | 624 | describe('Updating another user', function () { |
758 | it('Should be able to update another user', async function () { | 625 | it('Should be able to update another user', async function () { |
759 | await updateUser({ | 626 | await server.users.update({ |
760 | url: server.url, | ||
761 | userId, | 627 | userId, |
762 | accessToken, | 628 | token, |
763 | email: 'updated2@example.com', | 629 | email: 'updated2@example.com', |
764 | emailVerified: true, | 630 | emailVerified: true, |
765 | videoQuota: 42, | 631 | videoQuota: 42, |
@@ -768,8 +634,7 @@ describe('Test users', function () { | |||
768 | pluginAuth: 'toto' | 634 | pluginAuth: 'toto' |
769 | }) | 635 | }) |
770 | 636 | ||
771 | const res = await getUserInformation(server.url, accessToken, userId) | 637 | const user = await server.users.get({ token, userId }) |
772 | const user = res.body as User | ||
773 | 638 | ||
774 | expect(user.username).to.equal('user_1') | 639 | expect(user.username).to.equal('user_1') |
775 | expect(user.email).to.equal('updated2@example.com') | 640 | expect(user.email).to.equal('updated2@example.com') |
@@ -783,57 +648,50 @@ describe('Test users', function () { | |||
783 | }) | 648 | }) |
784 | 649 | ||
785 | it('Should reset the auth plugin', async function () { | 650 | it('Should reset the auth plugin', async function () { |
786 | await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) | 651 | await server.users.update({ userId, token, pluginAuth: null }) |
787 | 652 | ||
788 | const res = await getUserInformation(server.url, accessToken, userId) | 653 | const user = await server.users.get({ token, userId }) |
789 | const user = res.body as User | ||
790 | expect(user.pluginAuth).to.be.null | 654 | expect(user.pluginAuth).to.be.null |
791 | }) | 655 | }) |
792 | 656 | ||
793 | it('Should have removed the user token', async function () { | 657 | it('Should have removed the user token', async function () { |
794 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 658 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
795 | 659 | ||
796 | accessTokenUser = await userLogin(server, user) | 660 | userToken = await server.login.getAccessToken(user) |
797 | }) | 661 | }) |
798 | 662 | ||
799 | it('Should be able to update another user password', async function () { | 663 | it('Should be able to update another user password', async function () { |
800 | await updateUser({ | 664 | await server.users.update({ userId, token, password: 'password updated' }) |
801 | url: server.url, | ||
802 | userId, | ||
803 | accessToken, | ||
804 | password: 'password updated' | ||
805 | }) | ||
806 | 665 | ||
807 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) | 666 | await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
808 | 667 | ||
809 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 668 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
810 | 669 | ||
811 | user.password = 'password updated' | 670 | user.password = 'password updated' |
812 | accessTokenUser = await userLogin(server, user) | 671 | userToken = await server.login.getAccessToken(user) |
813 | }) | 672 | }) |
814 | }) | 673 | }) |
815 | 674 | ||
816 | describe('Video blacklists', function () { | 675 | describe('Video blacklists', function () { |
817 | it('Should be able to list video blacklist by a moderator', async function () { | 676 | it('Should be able to list video blacklist by a moderator', async function () { |
818 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | 677 | await server.blacklist.list({ token: userToken }) |
819 | }) | 678 | }) |
820 | }) | 679 | }) |
821 | 680 | ||
822 | describe('Remove a user', function () { | 681 | describe('Remove a user', function () { |
823 | it('Should be able to remove this user', async function () { | 682 | it('Should be able to remove this user', async function () { |
824 | await removeUser(server.url, userId, accessToken) | 683 | await server.users.remove({ userId, token }) |
825 | }) | 684 | }) |
826 | 685 | ||
827 | it('Should not be able to login with this user', async function () { | 686 | it('Should not be able to login with this user', async function () { |
828 | await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) | 687 | await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
829 | }) | 688 | }) |
830 | 689 | ||
831 | it('Should not have videos of this user', async function () { | 690 | it('Should not have videos of this user', async function () { |
832 | const res = await getVideosList(server.url) | 691 | const { data, total } = await server.videos.list() |
833 | 692 | expect(total).to.equal(1) | |
834 | expect(res.body.total).to.equal(1) | ||
835 | 693 | ||
836 | const video = res.body.data[0] | 694 | const video = data[0] |
837 | expect(video.account.name).to.equal('root') | 695 | expect(video.account.name).to.equal('root') |
838 | }) | 696 | }) |
839 | }) | 697 | }) |
@@ -845,7 +703,7 @@ describe('Test users', function () { | |||
845 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } | 703 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
846 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } | 704 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
847 | 705 | ||
848 | await registerUserWithChannel({ url: server.url, user, channel }) | 706 | await server.users.register({ ...user, channel }) |
849 | }) | 707 | }) |
850 | 708 | ||
851 | it('Should be able to login with this registered user', async function () { | 709 | it('Should be able to login with this registered user', async function () { |
@@ -854,40 +712,36 @@ describe('Test users', function () { | |||
854 | password: 'my super password' | 712 | password: 'my super password' |
855 | } | 713 | } |
856 | 714 | ||
857 | user15AccessToken = await userLogin(server, user15) | 715 | user15AccessToken = await server.login.getAccessToken(user15) |
858 | }) | 716 | }) |
859 | 717 | ||
860 | it('Should have the correct display name', async function () { | 718 | it('Should have the correct display name', async function () { |
861 | const res = await getMyUserInformation(server.url, user15AccessToken) | 719 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
862 | const user: User = res.body | ||
863 | |||
864 | expect(user.account.displayName).to.equal('super user 15') | 720 | expect(user.account.displayName).to.equal('super user 15') |
865 | }) | 721 | }) |
866 | 722 | ||
867 | it('Should have the correct video quota', async function () { | 723 | it('Should have the correct video quota', async function () { |
868 | const res = await getMyUserInformation(server.url, user15AccessToken) | 724 | const user = await server.users.getMyInfo({ token: user15AccessToken }) |
869 | const user = res.body | ||
870 | |||
871 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 725 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
872 | }) | 726 | }) |
873 | 727 | ||
874 | it('Should have created the channel', async function () { | 728 | it('Should have created the channel', async function () { |
875 | const res = await getVideoChannel(server.url, 'my_user_15_channel') | 729 | const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' }) |
876 | 730 | ||
877 | expect(res.body.displayName).to.equal('my channel rocks') | 731 | expect(displayName).to.equal('my channel rocks') |
878 | }) | 732 | }) |
879 | 733 | ||
880 | it('Should remove me', async function () { | 734 | it('Should remove me', async function () { |
881 | { | 735 | { |
882 | const res = await getUsersList(server.url, server.accessToken) | 736 | const { data } = await server.users.list() |
883 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | 737 | expect(data.find(u => u.username === 'user_15')).to.not.be.undefined |
884 | } | 738 | } |
885 | 739 | ||
886 | await deleteMe(server.url, user15AccessToken) | 740 | await server.users.deleteMe({ token: user15AccessToken }) |
887 | 741 | ||
888 | { | 742 | { |
889 | const res = await getUsersList(server.url, server.accessToken) | 743 | const { data } = await server.users.list() |
890 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | 744 | expect(data.find(u => u.username === 'user_15')).to.be.undefined |
891 | } | 745 | } |
892 | }) | 746 | }) |
893 | }) | 747 | }) |
@@ -901,49 +755,40 @@ describe('Test users', function () { | |||
901 | } | 755 | } |
902 | 756 | ||
903 | it('Should block a user', async function () { | 757 | it('Should block a user', async function () { |
904 | const resUser = await createUser({ | 758 | const user = await server.users.create({ ...user16 }) |
905 | url: server.url, | 759 | user16Id = user.id |
906 | accessToken: server.accessToken, | ||
907 | username: user16.username, | ||
908 | password: user16.password | ||
909 | }) | ||
910 | user16Id = resUser.body.user.id | ||
911 | 760 | ||
912 | user16AccessToken = await userLogin(server, user16) | 761 | user16AccessToken = await server.login.getAccessToken(user16) |
913 | 762 | ||
914 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 763 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
915 | await blockUser(server.url, user16Id, server.accessToken) | 764 | await server.users.banUser({ userId: user16Id }) |
916 | 765 | ||
917 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) | 766 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
918 | await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) | 767 | await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
919 | }) | 768 | }) |
920 | 769 | ||
921 | it('Should search user by banned status', async function () { | 770 | it('Should search user by banned status', async function () { |
922 | { | 771 | { |
923 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) | 772 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) |
924 | const users = res.body.data as User[] | 773 | expect(total).to.equal(1) |
774 | expect(data.length).to.equal(1) | ||
925 | 775 | ||
926 | expect(res.body.total).to.equal(1) | 776 | expect(data[0].username).to.equal(user16.username) |
927 | expect(users.length).to.equal(1) | ||
928 | |||
929 | expect(users[0].username).to.equal(user16.username) | ||
930 | } | 777 | } |
931 | 778 | ||
932 | { | 779 | { |
933 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) | 780 | const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) |
934 | const users = res.body.data as User[] | 781 | expect(total).to.equal(1) |
935 | 782 | expect(data.length).to.equal(1) | |
936 | expect(res.body.total).to.equal(1) | ||
937 | expect(users.length).to.equal(1) | ||
938 | 783 | ||
939 | expect(users[0].username).to.not.equal(user16.username) | 784 | expect(data[0].username).to.not.equal(user16.username) |
940 | } | 785 | } |
941 | }) | 786 | }) |
942 | 787 | ||
943 | it('Should unblock a user', async function () { | 788 | it('Should unblock a user', async function () { |
944 | await unblockUser(server.url, user16Id, server.accessToken) | 789 | await server.users.unbanUser({ userId: user16Id }) |
945 | user16AccessToken = await userLogin(server, user16) | 790 | user16AccessToken = await server.login.getAccessToken(user16) |
946 | await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) | 791 | await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) |
947 | }) | 792 | }) |
948 | }) | 793 | }) |
949 | 794 | ||
@@ -956,19 +801,12 @@ describe('Test users', function () { | |||
956 | username: 'user_17', | 801 | username: 'user_17', |
957 | password: 'my super password' | 802 | password: 'my super password' |
958 | } | 803 | } |
959 | const resUser = await createUser({ | 804 | const created = await server.users.create({ ...user17 }) |
960 | url: server.url, | ||
961 | accessToken: server.accessToken, | ||
962 | username: user17.username, | ||
963 | password: user17.password | ||
964 | }) | ||
965 | 805 | ||
966 | user17Id = resUser.body.user.id | 806 | user17Id = created.id |
967 | user17AccessToken = await userLogin(server, user17) | 807 | user17AccessToken = await server.login.getAccessToken(user17) |
968 | |||
969 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
970 | const user: User = res.body | ||
971 | 808 | ||
809 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
972 | expect(user.videosCount).to.equal(0) | 810 | expect(user.videosCount).to.equal(0) |
973 | expect(user.videoCommentsCount).to.equal(0) | 811 | expect(user.videoCommentsCount).to.equal(0) |
974 | expect(user.abusesCount).to.equal(0) | 812 | expect(user.abusesCount).to.equal(0) |
@@ -977,54 +815,43 @@ describe('Test users', function () { | |||
977 | }) | 815 | }) |
978 | 816 | ||
979 | it('Should report correct videos count', async function () { | 817 | it('Should report correct videos count', async function () { |
980 | const videoAttributes = { | 818 | const attributes = { name: 'video to test user stats' } |
981 | name: 'video to test user stats' | 819 | await server.videos.upload({ token: user17AccessToken, attributes }) |
982 | } | ||
983 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | ||
984 | const res1 = await getVideosList(server.url) | ||
985 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | ||
986 | 820 | ||
987 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 821 | const { data } = await server.videos.list() |
988 | const user: User = res2.body | 822 | videoId = data.find(video => video.name === attributes.name).id |
989 | 823 | ||
824 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
990 | expect(user.videosCount).to.equal(1) | 825 | expect(user.videosCount).to.equal(1) |
991 | }) | 826 | }) |
992 | 827 | ||
993 | it('Should report correct video comments for user', async function () { | 828 | it('Should report correct video comments for user', async function () { |
994 | const text = 'super comment' | 829 | const text = 'super comment' |
995 | await addVideoCommentThread(server.url, user17AccessToken, videoId, text) | 830 | await server.comments.createThread({ token: user17AccessToken, videoId, text }) |
996 | |||
997 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
998 | const user: User = res.body | ||
999 | 831 | ||
832 | const user = await server.users.get({ userId: user17Id, withStats: true }) | ||
1000 | expect(user.videoCommentsCount).to.equal(1) | 833 | expect(user.videoCommentsCount).to.equal(1) |
1001 | }) | 834 | }) |
1002 | 835 | ||
1003 | it('Should report correct abuses counts', async function () { | 836 | it('Should report correct abuses counts', async function () { |
1004 | const reason = 'my super bad reason' | 837 | const reason = 'my super bad reason' |
1005 | await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) | 838 | await server.abuses.report({ token: user17AccessToken, videoId, reason }) |
1006 | |||
1007 | const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) | ||
1008 | const abuseId = res1.body.data[0].id | ||
1009 | 839 | ||
1010 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | 840 | const body1 = await server.abuses.getAdminList() |
1011 | const user2: User = res2.body | 841 | const abuseId = body1.data[0].id |
1012 | 842 | ||
843 | const user2 = await server.users.get({ userId: user17Id, withStats: true }) | ||
1013 | expect(user2.abusesCount).to.equal(1) // number of incriminations | 844 | expect(user2.abusesCount).to.equal(1) // number of incriminations |
1014 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created | 845 | expect(user2.abusesCreatedCount).to.equal(1) // number of reports created |
1015 | 846 | ||
1016 | const body: AbuseUpdate = { state: AbuseState.ACCEPTED } | 847 | await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) |
1017 | await updateAbuse(server.url, server.accessToken, abuseId, body) | ||
1018 | |||
1019 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
1020 | const user3: User = res3.body | ||
1021 | 848 | ||
849 | const user3 = await server.users.get({ userId: user17Id, withStats: true }) | ||
1022 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted | 850 | expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted |
1023 | }) | 851 | }) |
1024 | }) | 852 | }) |
1025 | 853 | ||
1026 | after(async function () { | 854 | after(async function () { |
1027 | await closeAllSequelize([ server ]) | ||
1028 | await cleanupTests([ server ]) | 855 | await cleanupTests([ server ]) |
1029 | }) | 856 | }) |
1030 | }) | 857 | }) |