diff options
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/user-subscriptions.ts | 56 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 34 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 166 |
3 files changed, 116 insertions, 140 deletions
diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c09a85a32..622cddb7d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts | |||
@@ -6,12 +6,9 @@ import { | |||
6 | cleanupTests, | 6 | cleanupTests, |
7 | doubleFollow, | 7 | doubleFollow, |
8 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
9 | getVideosList, | ||
10 | ServerInfo, | 9 | ServerInfo, |
11 | setAccessTokensToServers, | 10 | setAccessTokensToServers, |
12 | SubscriptionsCommand, | 11 | SubscriptionsCommand, |
13 | updateVideo, | ||
14 | uploadVideo, | ||
15 | waitJobs | 12 | waitJobs |
16 | } from '@shared/extra-utils' | 13 | } from '@shared/extra-utils' |
17 | 14 | ||
@@ -44,10 +41,10 @@ describe('Test users subscriptions', function () { | |||
44 | users.push({ accessToken }) | 41 | users.push({ accessToken }) |
45 | 42 | ||
46 | const videoName1 = 'video 1-' + server.serverNumber | 43 | const videoName1 = 'video 1-' + server.serverNumber |
47 | await uploadVideo(server.url, accessToken, { name: videoName1 }) | 44 | await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) |
48 | 45 | ||
49 | const videoName2 = 'video 2-' + server.serverNumber | 46 | const videoName2 = 'video 2-' + server.serverNumber |
50 | await uploadVideo(server.url, accessToken, { name: videoName2 }) | 47 | await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) |
51 | } | 48 | } |
52 | } | 49 | } |
53 | 50 | ||
@@ -57,9 +54,9 @@ describe('Test users subscriptions', function () { | |||
57 | }) | 54 | }) |
58 | 55 | ||
59 | it('Should display videos of server 2 on server 1', async function () { | 56 | it('Should display videos of server 2 on server 1', async function () { |
60 | const res = await getVideosList(servers[0].url) | 57 | const { total } = await servers[0].videosCommand.list() |
61 | 58 | ||
62 | expect(res.body.total).to.equal(4) | 59 | expect(total).to.equal(4) |
63 | }) | 60 | }) |
64 | 61 | ||
65 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { | 62 | it('User of server 1 should follow user of server 3 and root of server 1', async function () { |
@@ -70,17 +67,17 @@ describe('Test users subscriptions', function () { | |||
70 | 67 | ||
71 | await waitJobs(servers) | 68 | await waitJobs(servers) |
72 | 69 | ||
73 | const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) | 70 | const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) |
74 | video3UUID = res.body.video.uuid | 71 | video3UUID = uuid |
75 | 72 | ||
76 | await waitJobs(servers) | 73 | await waitJobs(servers) |
77 | }) | 74 | }) |
78 | 75 | ||
79 | it('Should not display videos of server 3 on server 1', async function () { | 76 | it('Should not display videos of server 3 on server 1', async function () { |
80 | const res = await getVideosList(servers[0].url) | 77 | const { total, data } = await servers[0].videosCommand.list() |
78 | expect(total).to.equal(4) | ||
81 | 79 | ||
82 | expect(res.body.total).to.equal(4) | 80 | for (const video of data) { |
83 | for (const video of res.body.data) { | ||
84 | expect(video.name).to.not.contain('1-3') | 81 | expect(video.name).to.not.contain('1-3') |
85 | expect(video.name).to.not.contain('2-3') | 82 | expect(video.name).to.not.contain('2-3') |
86 | expect(video.name).to.not.contain('video server 3 added after follow') | 83 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -186,7 +183,7 @@ describe('Test users subscriptions', function () { | |||
186 | this.timeout(60000) | 183 | this.timeout(60000) |
187 | 184 | ||
188 | const videoName = 'video server 1 added after follow' | 185 | const videoName = 'video server 1 added after follow' |
189 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) | 186 | await servers[0].videosCommand.upload({ attributes: { name: videoName } }) |
190 | 187 | ||
191 | await waitJobs(servers) | 188 | await waitJobs(servers) |
192 | 189 | ||
@@ -212,10 +209,10 @@ describe('Test users subscriptions', function () { | |||
212 | } | 209 | } |
213 | 210 | ||
214 | { | 211 | { |
215 | const res = await getVideosList(servers[0].url) | 212 | const { data, total } = await servers[0].videosCommand.list() |
213 | expect(total).to.equal(5) | ||
216 | 214 | ||
217 | expect(res.body.total).to.equal(5) | 215 | for (const video of data) { |
218 | for (const video of res.body.data) { | ||
219 | expect(video.name).to.not.contain('1-3') | 216 | expect(video.name).to.not.contain('1-3') |
220 | expect(video.name).to.not.contain('2-3') | 217 | expect(video.name).to.not.contain('2-3') |
221 | expect(video.name).to.not.contain('video server 3 added after follow') | 218 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -230,13 +227,12 @@ describe('Test users subscriptions', function () { | |||
230 | 227 | ||
231 | await waitJobs(servers) | 228 | await waitJobs(servers) |
232 | 229 | ||
233 | const res = await getVideosList(servers[0].url) | 230 | const { data, total } = await servers[0].videosCommand.list() |
234 | 231 | expect(total).to.equal(8) | |
235 | expect(res.body.total).to.equal(8) | ||
236 | 232 | ||
237 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] | 233 | const names = [ '1-3', '2-3', 'video server 3 added after follow' ] |
238 | for (const name of names) { | 234 | for (const name of names) { |
239 | const video = res.body.data.find(v => v.name.indexOf(name) === -1) | 235 | const video = data.find(v => v.name.includes(name)) |
240 | expect(video).to.not.be.undefined | 236 | expect(video).to.not.be.undefined |
241 | } | 237 | } |
242 | }) | 238 | }) |
@@ -248,10 +244,10 @@ describe('Test users subscriptions', function () { | |||
248 | 244 | ||
249 | await waitJobs(servers) | 245 | await waitJobs(servers) |
250 | 246 | ||
251 | const res = await getVideosList(servers[0].url) | 247 | const { total, data } = await servers[0].videosCommand.list() |
248 | expect(total).to.equal(5) | ||
252 | 249 | ||
253 | expect(res.body.total).to.equal(5) | 250 | for (const video of data) { |
254 | for (const video of res.body.data) { | ||
255 | expect(video.name).to.not.contain('1-3') | 251 | expect(video.name).to.not.contain('1-3') |
256 | expect(video.name).to.not.contain('2-3') | 252 | expect(video.name).to.not.contain('2-3') |
257 | expect(video.name).to.not.contain('video server 3 added after follow') | 253 | expect(video.name).to.not.contain('video server 3 added after follow') |
@@ -284,7 +280,7 @@ describe('Test users subscriptions', function () { | |||
284 | it('Should update a video of server 3 and see the updated video on server 1', async function () { | 280 | it('Should update a video of server 3 and see the updated video on server 1', async function () { |
285 | this.timeout(30000) | 281 | this.timeout(30000) |
286 | 282 | ||
287 | await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) | 283 | await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) |
288 | 284 | ||
289 | await waitJobs(servers) | 285 | await waitJobs(servers) |
290 | 286 | ||
@@ -329,10 +325,10 @@ describe('Test users subscriptions', function () { | |||
329 | }) | 325 | }) |
330 | 326 | ||
331 | it('Should correctly display public videos on server 1', async function () { | 327 | it('Should correctly display public videos on server 1', async function () { |
332 | const res = await getVideosList(servers[0].url) | 328 | const { total, data } = await servers[0].videosCommand.list() |
329 | expect(total).to.equal(5) | ||
333 | 330 | ||
334 | expect(res.body.total).to.equal(5) | 331 | for (const video of data) { |
335 | for (const video of res.body.data) { | ||
336 | expect(video.name).to.not.contain('1-3') | 332 | expect(video.name).to.not.contain('1-3') |
337 | expect(video.name).to.not.contain('2-3') | 333 | expect(video.name).to.not.contain('2-3') |
338 | expect(video.name).to.not.contain('video server 3 added after follow updated') | 334 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
@@ -360,10 +356,10 @@ describe('Test users subscriptions', function () { | |||
360 | } | 356 | } |
361 | 357 | ||
362 | { | 358 | { |
363 | const res = await getVideosList(servers[0].url) | 359 | const { total, data } = await servers[0].videosCommand.list() |
360 | expect(total).to.equal(5) | ||
364 | 361 | ||
365 | expect(res.body.total).to.equal(5) | 362 | for (const video of data) { |
366 | for (const video of res.body.data) { | ||
367 | expect(video.name).to.not.contain('1-3') | 363 | expect(video.name).to.not.contain('1-3') |
368 | expect(video.name).to.not.contain('2-3') | 364 | expect(video.name).to.not.contain('2-3') |
369 | expect(video.name).to.not.contain('video server 3 added after follow updated') | 365 | expect(video.name).to.not.contain('video server 3 added after follow updated') |
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 43e67ee60..3ae105008 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts | |||
@@ -9,11 +9,9 @@ import { | |||
9 | cleanupTests, | 9 | cleanupTests, |
10 | doubleFollow, | 10 | doubleFollow, |
11 | flushAndRunMultipleServers, | 11 | flushAndRunMultipleServers, |
12 | getAccountVideos, | ||
13 | ServerInfo, | 12 | ServerInfo, |
14 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
15 | testImage, | 14 | testImage, |
16 | uploadVideo, | ||
17 | waitJobs | 15 | waitJobs |
18 | } from '@shared/extra-utils' | 16 | } from '@shared/extra-utils' |
19 | import { User } from '@shared/models' | 17 | import { User } from '@shared/models' |
@@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () { | |||
44 | await doubleFollow(servers[1], servers[2]) | 42 | await doubleFollow(servers[1], servers[2]) |
45 | 43 | ||
46 | // The root user of server 1 is propagated to servers 2 and 3 | 44 | // The root user of server 1 is propagated to servers 2 and 3 |
47 | await uploadVideo(servers[0].url, servers[0].accessToken, {}) | 45 | await servers[0].videosCommand.upload() |
48 | 46 | ||
49 | { | 47 | { |
50 | const user = { | 48 | const user = { |
@@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () { | |||
57 | } | 55 | } |
58 | 56 | ||
59 | { | 57 | { |
60 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) | 58 | const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) |
61 | videoUUID = resVideo.body.video.uuid | 59 | videoUUID = uuid |
62 | } | 60 | } |
63 | 61 | ||
64 | await waitJobs(servers) | 62 | await waitJobs(servers) |
@@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () { | |||
133 | 131 | ||
134 | it('Should list account videos', async function () { | 132 | it('Should list account videos', async function () { |
135 | for (const server of servers) { | 133 | for (const server of servers) { |
136 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) | 134 | const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) |
137 | 135 | ||
138 | expect(res.body.total).to.equal(1) | 136 | expect(total).to.equal(1) |
139 | expect(res.body.data).to.be.an('array') | 137 | expect(data).to.be.an('array') |
140 | expect(res.body.data).to.have.lengthOf(1) | 138 | expect(data).to.have.lengthOf(1) |
141 | expect(res.body.data[0].uuid).to.equal(videoUUID) | 139 | expect(data[0].uuid).to.equal(videoUUID) |
142 | } | 140 | } |
143 | }) | 141 | }) |
144 | 142 | ||
145 | it('Should search through account videos', async function () { | 143 | it('Should search through account videos', async function () { |
146 | this.timeout(10_000) | 144 | this.timeout(10_000) |
147 | 145 | ||
148 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) | 146 | const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) |
149 | 147 | ||
150 | await waitJobs(servers) | 148 | await waitJobs(servers) |
151 | 149 | ||
152 | for (const server of servers) { | 150 | for (const server of servers) { |
153 | const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { | 151 | const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) |
154 | search: 'Kami' | 152 | |
155 | }) | 153 | expect(total).to.equal(1) |
156 | 154 | expect(data).to.be.an('array') | |
157 | expect(res.body.total).to.equal(1) | 155 | expect(data).to.have.lengthOf(1) |
158 | expect(res.body.data).to.be.an('array') | 156 | expect(data[0].uuid).to.equal(created.uuid) |
159 | expect(res.body.data).to.have.lengthOf(1) | ||
160 | expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) | ||
161 | } | 157 | } |
162 | }) | 158 | }) |
163 | 159 | ||
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 30d7e850d..6f3873939 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils' | |||
6 | import { | 6 | import { |
7 | cleanupTests, | 7 | cleanupTests, |
8 | flushAndRunServer, | 8 | flushAndRunServer, |
9 | getMyVideos, | ||
10 | getVideosList, | ||
11 | killallServers, | 9 | killallServers, |
12 | makePutBodyRequest, | 10 | makePutBodyRequest, |
13 | rateVideo, | ||
14 | removeVideo, | ||
15 | reRunServer, | 11 | reRunServer, |
16 | ServerInfo, | 12 | ServerInfo, |
17 | setAccessTokensToServers, | 13 | setAccessTokensToServers, |
18 | testImage, | 14 | testImage, |
19 | uploadVideo, | ||
20 | waitJobs | 15 | waitJobs |
21 | } from '@shared/extra-utils' | 16 | } from '@shared/extra-utils' |
22 | import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' | 17 | import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' |
@@ -25,8 +20,8 @@ const expect = chai.expect | |||
25 | 20 | ||
26 | describe('Test users', function () { | 21 | describe('Test users', function () { |
27 | let server: ServerInfo | 22 | let server: ServerInfo |
28 | let accessToken: string | 23 | let token: string |
29 | let accessTokenUser: string | 24 | let userToken: string |
30 | let videoId: number | 25 | let videoId: number |
31 | let userId: number | 26 | let userId: number |
32 | const user = { | 27 | const user = { |
@@ -101,18 +96,17 @@ describe('Test users', function () { | |||
101 | }) | 96 | }) |
102 | 97 | ||
103 | it('Should not be able to upload a video', async function () { | 98 | it('Should not be able to upload a video', async function () { |
104 | accessToken = 'my_super_token' | 99 | token = 'my_super_token' |
105 | 100 | ||
106 | const videoAttributes = {} | 101 | await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
107 | await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) | ||
108 | }) | 102 | }) |
109 | 103 | ||
110 | it('Should not be able to follow', async function () { | 104 | it('Should not be able to follow', async function () { |
111 | accessToken = 'my_super_token' | 105 | token = 'my_super_token' |
112 | 106 | ||
113 | await server.followsCommand.follow({ | 107 | await server.followsCommand.follow({ |
114 | targets: [ 'http://example.com' ], | 108 | targets: [ 'http://example.com' ], |
115 | token: accessToken, | 109 | token, |
116 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | 110 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
117 | }) | 111 | }) |
118 | }) | 112 | }) |
@@ -122,7 +116,7 @@ describe('Test users', function () { | |||
122 | it('Should be able to login', async function () { | 116 | it('Should be able to login', async function () { |
123 | const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) | 117 | const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) |
124 | 118 | ||
125 | accessToken = body.access_token | 119 | token = body.access_token |
126 | }) | 120 | }) |
127 | 121 | ||
128 | it('Should be able to login with an insensitive username', async function () { | 122 | it('Should be able to login with an insensitive username', async function () { |
@@ -140,33 +134,31 @@ describe('Test users', function () { | |||
140 | describe('Upload', function () { | 134 | describe('Upload', function () { |
141 | 135 | ||
142 | it('Should upload the video with the correct token', async function () { | 136 | it('Should upload the video with the correct token', async function () { |
143 | const videoAttributes = {} | 137 | await server.videosCommand.upload({ token }) |
144 | await uploadVideo(server.url, accessToken, videoAttributes) | 138 | const { data } = await server.videosCommand.list() |
145 | const res = await getVideosList(server.url) | 139 | const video = data[0] |
146 | const video = res.body.data[0] | ||
147 | 140 | ||
148 | expect(video.account.name).to.equal('root') | 141 | expect(video.account.name).to.equal('root') |
149 | videoId = video.id | 142 | videoId = video.id |
150 | }) | 143 | }) |
151 | 144 | ||
152 | it('Should upload the video again with the correct token', async function () { | 145 | it('Should upload the video again with the correct token', async function () { |
153 | const videoAttributes = {} | 146 | await server.videosCommand.upload({ token }) |
154 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
155 | }) | 147 | }) |
156 | }) | 148 | }) |
157 | 149 | ||
158 | describe('Ratings', function () { | 150 | describe('Ratings', function () { |
159 | 151 | ||
160 | it('Should retrieve a video rating', async function () { | 152 | it('Should retrieve a video rating', async function () { |
161 | await rateVideo(server.url, accessToken, videoId, 'like') | 153 | await server.videosCommand.rate({ id: videoId, rating: 'like' }) |
162 | const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) | 154 | const rating = await server.usersCommand.getMyRating({ token, videoId }) |
163 | 155 | ||
164 | expect(rating.videoId).to.equal(videoId) | 156 | expect(rating.videoId).to.equal(videoId) |
165 | expect(rating.rating).to.equal('like') | 157 | expect(rating.rating).to.equal('like') |
166 | }) | 158 | }) |
167 | 159 | ||
168 | it('Should retrieve ratings list', async function () { | 160 | it('Should retrieve ratings list', async function () { |
169 | await rateVideo(server.url, accessToken, videoId, 'like') | 161 | await server.videosCommand.rate({ id: videoId, rating: 'like' }) |
170 | 162 | ||
171 | const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) | 163 | const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) |
172 | 164 | ||
@@ -190,13 +182,13 @@ describe('Test users', function () { | |||
190 | 182 | ||
191 | describe('Remove video', function () { | 183 | describe('Remove video', function () { |
192 | it('Should not be able to remove the video with an incorrect token', async function () { | 184 | it('Should not be able to remove the video with an incorrect token', async function () { |
193 | await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) | 185 | await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
194 | }) | 186 | }) |
195 | 187 | ||
196 | it('Should not be able to remove the video with the token of another account') | 188 | it('Should not be able to remove the video with the token of another account') |
197 | 189 | ||
198 | it('Should be able to remove the video with the correct token', async function () { | 190 | it('Should be able to remove the video with the correct token', async function () { |
199 | await removeVideo(server.url, accessToken, videoId) | 191 | await server.videosCommand.remove({ token, id: videoId }) |
200 | }) | 192 | }) |
201 | }) | 193 | }) |
202 | 194 | ||
@@ -210,7 +202,7 @@ describe('Test users', function () { | |||
210 | }) | 202 | }) |
211 | 203 | ||
212 | it('Should not be able to upload a video', async function () { | 204 | it('Should not be able to upload a video', async function () { |
213 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) | 205 | await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
214 | }) | 206 | }) |
215 | 207 | ||
216 | it('Should not be able to rate a video', async function () { | 208 | it('Should not be able to rate a video', async function () { |
@@ -281,11 +273,11 @@ describe('Test users', function () { | |||
281 | }) | 273 | }) |
282 | 274 | ||
283 | it('Should be able to login with this user', async function () { | 275 | it('Should be able to login with this user', async function () { |
284 | accessTokenUser = await server.loginCommand.getAccessToken(user) | 276 | userToken = await server.loginCommand.getAccessToken(user) |
285 | }) | 277 | }) |
286 | 278 | ||
287 | it('Should be able to get user information', async function () { | 279 | it('Should be able to get user information', async function () { |
288 | const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 280 | const userMe = await server.usersCommand.getMyInfo({ token: userToken }) |
289 | 281 | ||
290 | const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) | 282 | const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) |
291 | 283 | ||
@@ -323,15 +315,15 @@ describe('Test users', function () { | |||
323 | it('Should be able to upload a video with this user', async function () { | 315 | it('Should be able to upload a video with this user', async function () { |
324 | this.timeout(10000) | 316 | this.timeout(10000) |
325 | 317 | ||
326 | const videoAttributes = { | 318 | const attributes = { |
327 | name: 'super user video', | 319 | name: 'super user video', |
328 | fixture: 'video_short.webm' | 320 | fixture: 'video_short.webm' |
329 | } | 321 | } |
330 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 322 | await server.videosCommand.upload({ token: userToken, attributes }) |
331 | }) | 323 | }) |
332 | 324 | ||
333 | it('Should have video quota updated', async function () { | 325 | it('Should have video quota updated', async function () { |
334 | const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) | 326 | const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) |
335 | expect(quota.videoQuotaUsed).to.equal(218910) | 327 | expect(quota.videoQuotaUsed).to.equal(218910) |
336 | 328 | ||
337 | const { data } = await server.usersCommand.list() | 329 | const { data } = await server.usersCommand.list() |
@@ -340,13 +332,11 @@ describe('Test users', function () { | |||
340 | }) | 332 | }) |
341 | 333 | ||
342 | it('Should be able to list my videos', async function () { | 334 | it('Should be able to list my videos', async function () { |
343 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | 335 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) |
344 | expect(res.body.total).to.equal(1) | 336 | expect(total).to.equal(1) |
345 | 337 | expect(data).to.have.lengthOf(1) | |
346 | const videos = res.body.data | ||
347 | expect(videos).to.have.lengthOf(1) | ||
348 | 338 | ||
349 | const video: Video = videos[0] | 339 | const video: Video = data[0] |
350 | expect(video.name).to.equal('super user video') | 340 | expect(video.name).to.equal('super user video') |
351 | expect(video.thumbnailPath).to.not.be.null | 341 | expect(video.thumbnailPath).to.not.be.null |
352 | expect(video.previewPath).to.not.be.null | 342 | expect(video.previewPath).to.not.be.null |
@@ -354,19 +344,15 @@ describe('Test users', function () { | |||
354 | 344 | ||
355 | it('Should be able to search in my videos', async function () { | 345 | it('Should be able to search in my videos', async function () { |
356 | { | 346 | { |
357 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') | 347 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) |
358 | expect(res.body.total).to.equal(1) | 348 | expect(total).to.equal(1) |
359 | 349 | expect(data).to.have.lengthOf(1) | |
360 | const videos = res.body.data | ||
361 | expect(videos).to.have.lengthOf(1) | ||
362 | } | 350 | } |
363 | 351 | ||
364 | { | 352 | { |
365 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') | 353 | const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) |
366 | expect(res.body.total).to.equal(0) | 354 | expect(total).to.equal(0) |
367 | 355 | expect(data).to.have.lengthOf(0) | |
368 | const videos = res.body.data | ||
369 | expect(videos).to.have.lengthOf(0) | ||
370 | } | 356 | } |
371 | }) | 357 | }) |
372 | 358 | ||
@@ -382,17 +368,17 @@ describe('Test users', function () { | |||
382 | } | 368 | } |
383 | 369 | ||
384 | { | 370 | { |
385 | const videoAttributes = { | 371 | const attributes = { |
386 | name: 'super user video 2', | 372 | name: 'super user video 2', |
387 | fixture: 'video_short.webm' | 373 | fixture: 'video_short.webm' |
388 | } | 374 | } |
389 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | 375 | await server.videosCommand.upload({ token: userToken, attributes }) |
390 | 376 | ||
391 | await waitJobs([ server ]) | 377 | await waitJobs([ server ]) |
392 | } | 378 | } |
393 | 379 | ||
394 | { | 380 | { |
395 | const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) | 381 | const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) |
396 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | 382 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) |
397 | } | 383 | } |
398 | }) | 384 | }) |
@@ -505,7 +491,7 @@ describe('Test users', function () { | |||
505 | 491 | ||
506 | it('Should update my password', async function () { | 492 | it('Should update my password', async function () { |
507 | await server.usersCommand.updateMe({ | 493 | await server.usersCommand.updateMe({ |
508 | token: accessTokenUser, | 494 | token: userToken, |
509 | currentPassword: 'super password', | 495 | currentPassword: 'super password', |
510 | password: 'new password' | 496 | password: 'new password' |
511 | }) | 497 | }) |
@@ -516,11 +502,11 @@ describe('Test users', function () { | |||
516 | 502 | ||
517 | it('Should be able to change the NSFW display attribute', async function () { | 503 | it('Should be able to change the NSFW display attribute', async function () { |
518 | await server.usersCommand.updateMe({ | 504 | await server.usersCommand.updateMe({ |
519 | token: accessTokenUser, | 505 | token: userToken, |
520 | nsfwPolicy: 'do_not_list' | 506 | nsfwPolicy: 'do_not_list' |
521 | }) | 507 | }) |
522 | 508 | ||
523 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 509 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
524 | expect(user.username).to.equal('user_1') | 510 | expect(user.username).to.equal('user_1') |
525 | expect(user.email).to.equal('user_1@example.com') | 511 | expect(user.email).to.equal('user_1@example.com') |
526 | expect(user.nsfwPolicy).to.equal('do_not_list') | 512 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -532,32 +518,32 @@ describe('Test users', function () { | |||
532 | 518 | ||
533 | it('Should be able to change the autoPlayVideo attribute', async function () { | 519 | it('Should be able to change the autoPlayVideo attribute', async function () { |
534 | await server.usersCommand.updateMe({ | 520 | await server.usersCommand.updateMe({ |
535 | token: accessTokenUser, | 521 | token: userToken, |
536 | autoPlayVideo: false | 522 | autoPlayVideo: false |
537 | }) | 523 | }) |
538 | 524 | ||
539 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 525 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
540 | expect(user.autoPlayVideo).to.be.false | 526 | expect(user.autoPlayVideo).to.be.false |
541 | }) | 527 | }) |
542 | 528 | ||
543 | it('Should be able to change the autoPlayNextVideo attribute', async function () { | 529 | it('Should be able to change the autoPlayNextVideo attribute', async function () { |
544 | await server.usersCommand.updateMe({ | 530 | await server.usersCommand.updateMe({ |
545 | token: accessTokenUser, | 531 | token: userToken, |
546 | autoPlayNextVideo: true | 532 | autoPlayNextVideo: true |
547 | }) | 533 | }) |
548 | 534 | ||
549 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 535 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
550 | expect(user.autoPlayNextVideo).to.be.true | 536 | expect(user.autoPlayNextVideo).to.be.true |
551 | }) | 537 | }) |
552 | 538 | ||
553 | it('Should be able to change the email attribute', async function () { | 539 | it('Should be able to change the email attribute', async function () { |
554 | await server.usersCommand.updateMe({ | 540 | await server.usersCommand.updateMe({ |
555 | token: accessTokenUser, | 541 | token: userToken, |
556 | currentPassword: 'new password', | 542 | currentPassword: 'new password', |
557 | email: 'updated@example.com' | 543 | email: 'updated@example.com' |
558 | }) | 544 | }) |
559 | 545 | ||
560 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 546 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
561 | expect(user.username).to.equal('user_1') | 547 | expect(user.username).to.equal('user_1') |
562 | expect(user.email).to.equal('updated@example.com') | 548 | expect(user.email).to.equal('updated@example.com') |
563 | expect(user.nsfwPolicy).to.equal('do_not_list') | 549 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -570,9 +556,9 @@ describe('Test users', function () { | |||
570 | it('Should be able to update my avatar with a gif', async function () { | 556 | it('Should be able to update my avatar with a gif', async function () { |
571 | const fixture = 'avatar.gif' | 557 | const fixture = 'avatar.gif' |
572 | 558 | ||
573 | await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) | 559 | await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) |
574 | 560 | ||
575 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 561 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
576 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') | 562 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') |
577 | }) | 563 | }) |
578 | 564 | ||
@@ -580,17 +566,17 @@ describe('Test users', function () { | |||
580 | for (const extension of [ '.png', '.gif' ]) { | 566 | for (const extension of [ '.png', '.gif' ]) { |
581 | const fixture = 'avatar' + extension | 567 | const fixture = 'avatar' + extension |
582 | 568 | ||
583 | await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) | 569 | await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) |
584 | 570 | ||
585 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 571 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
586 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) | 572 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) |
587 | } | 573 | } |
588 | }) | 574 | }) |
589 | 575 | ||
590 | it('Should be able to update my display name', async function () { | 576 | it('Should be able to update my display name', async function () { |
591 | await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) | 577 | await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) |
592 | 578 | ||
593 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 579 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
594 | expect(user.username).to.equal('user_1') | 580 | expect(user.username).to.equal('user_1') |
595 | expect(user.email).to.equal('updated@example.com') | 581 | expect(user.email).to.equal('updated@example.com') |
596 | expect(user.nsfwPolicy).to.equal('do_not_list') | 582 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -601,9 +587,9 @@ describe('Test users', function () { | |||
601 | }) | 587 | }) |
602 | 588 | ||
603 | it('Should be able to update my description', async function () { | 589 | it('Should be able to update my description', async function () { |
604 | await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) | 590 | await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) |
605 | 591 | ||
606 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 592 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
607 | expect(user.username).to.equal('user_1') | 593 | expect(user.username).to.equal('user_1') |
608 | expect(user.email).to.equal('updated@example.com') | 594 | expect(user.email).to.equal('updated@example.com') |
609 | expect(user.nsfwPolicy).to.equal('do_not_list') | 595 | expect(user.nsfwPolicy).to.equal('do_not_list') |
@@ -617,21 +603,21 @@ describe('Test users', function () { | |||
617 | 603 | ||
618 | it('Should be able to update my theme', async function () { | 604 | it('Should be able to update my theme', async function () { |
619 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { | 605 | for (const theme of [ 'background-red', 'default', 'instance-default' ]) { |
620 | await server.usersCommand.updateMe({ token: accessTokenUser, theme }) | 606 | await server.usersCommand.updateMe({ token: userToken, theme }) |
621 | 607 | ||
622 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 608 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
623 | expect(user.theme).to.equal(theme) | 609 | expect(user.theme).to.equal(theme) |
624 | } | 610 | } |
625 | }) | 611 | }) |
626 | 612 | ||
627 | it('Should be able to update my modal preferences', async function () { | 613 | it('Should be able to update my modal preferences', async function () { |
628 | await server.usersCommand.updateMe({ | 614 | await server.usersCommand.updateMe({ |
629 | token: accessTokenUser, | 615 | token: userToken, |
630 | noInstanceConfigWarningModal: true, | 616 | noInstanceConfigWarningModal: true, |
631 | noWelcomeModal: true | 617 | noWelcomeModal: true |
632 | }) | 618 | }) |
633 | 619 | ||
634 | const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) | 620 | const user = await server.usersCommand.getMyInfo({ token: userToken }) |
635 | expect(user.noWelcomeModal).to.be.true | 621 | expect(user.noWelcomeModal).to.be.true |
636 | expect(user.noInstanceConfigWarningModal).to.be.true | 622 | expect(user.noInstanceConfigWarningModal).to.be.true |
637 | }) | 623 | }) |
@@ -641,7 +627,7 @@ describe('Test users', function () { | |||
641 | it('Should be able to update another user', async function () { | 627 | it('Should be able to update another user', async function () { |
642 | await server.usersCommand.update({ | 628 | await server.usersCommand.update({ |
643 | userId, | 629 | userId, |
644 | token: accessToken, | 630 | token, |
645 | email: 'updated2@example.com', | 631 | email: 'updated2@example.com', |
646 | emailVerified: true, | 632 | emailVerified: true, |
647 | videoQuota: 42, | 633 | videoQuota: 42, |
@@ -650,7 +636,7 @@ describe('Test users', function () { | |||
650 | pluginAuth: 'toto' | 636 | pluginAuth: 'toto' |
651 | }) | 637 | }) |
652 | 638 | ||
653 | const user = await server.usersCommand.get({ token: accessToken, userId }) | 639 | const user = await server.usersCommand.get({ token, userId }) |
654 | 640 | ||
655 | expect(user.username).to.equal('user_1') | 641 | expect(user.username).to.equal('user_1') |
656 | expect(user.email).to.equal('updated2@example.com') | 642 | expect(user.email).to.equal('updated2@example.com') |
@@ -664,39 +650,39 @@ describe('Test users', function () { | |||
664 | }) | 650 | }) |
665 | 651 | ||
666 | it('Should reset the auth plugin', async function () { | 652 | it('Should reset the auth plugin', async function () { |
667 | await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) | 653 | await server.usersCommand.update({ userId, token, pluginAuth: null }) |
668 | 654 | ||
669 | const user = await server.usersCommand.get({ token: accessToken, userId }) | 655 | const user = await server.usersCommand.get({ token, userId }) |
670 | expect(user.pluginAuth).to.be.null | 656 | expect(user.pluginAuth).to.be.null |
671 | }) | 657 | }) |
672 | 658 | ||
673 | it('Should have removed the user token', async function () { | 659 | it('Should have removed the user token', async function () { |
674 | await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 660 | await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
675 | 661 | ||
676 | accessTokenUser = await server.loginCommand.getAccessToken(user) | 662 | userToken = await server.loginCommand.getAccessToken(user) |
677 | }) | 663 | }) |
678 | 664 | ||
679 | it('Should be able to update another user password', async function () { | 665 | it('Should be able to update another user password', async function () { |
680 | await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) | 666 | await server.usersCommand.update({ userId, token, password: 'password updated' }) |
681 | 667 | ||
682 | await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 668 | await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
683 | 669 | ||
684 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | 670 | await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
685 | 671 | ||
686 | user.password = 'password updated' | 672 | user.password = 'password updated' |
687 | accessTokenUser = await server.loginCommand.getAccessToken(user) | 673 | userToken = await server.loginCommand.getAccessToken(user) |
688 | }) | 674 | }) |
689 | }) | 675 | }) |
690 | 676 | ||
691 | describe('Video blacklists', function () { | 677 | describe('Video blacklists', function () { |
692 | it('Should be able to list video blacklist by a moderator', async function () { | 678 | it('Should be able to list video blacklist by a moderator', async function () { |
693 | await server.blacklistCommand.list({ token: accessTokenUser }) | 679 | await server.blacklistCommand.list({ token: userToken }) |
694 | }) | 680 | }) |
695 | }) | 681 | }) |
696 | 682 | ||
697 | describe('Remove a user', function () { | 683 | describe('Remove a user', function () { |
698 | it('Should be able to remove this user', async function () { | 684 | it('Should be able to remove this user', async function () { |
699 | await server.usersCommand.remove({ userId, token: accessToken }) | 685 | await server.usersCommand.remove({ userId, token }) |
700 | }) | 686 | }) |
701 | 687 | ||
702 | it('Should not be able to login with this user', async function () { | 688 | it('Should not be able to login with this user', async function () { |
@@ -704,11 +690,10 @@ describe('Test users', function () { | |||
704 | }) | 690 | }) |
705 | 691 | ||
706 | it('Should not have videos of this user', async function () { | 692 | it('Should not have videos of this user', async function () { |
707 | const res = await getVideosList(server.url) | 693 | const { data, total } = await server.videosCommand.list() |
708 | 694 | expect(total).to.equal(1) | |
709 | expect(res.body.total).to.equal(1) | ||
710 | 695 | ||
711 | const video = res.body.data[0] | 696 | const video = data[0] |
712 | expect(video.account.name).to.equal('root') | 697 | expect(video.account.name).to.equal('root') |
713 | }) | 698 | }) |
714 | }) | 699 | }) |
@@ -832,12 +817,11 @@ describe('Test users', function () { | |||
832 | }) | 817 | }) |
833 | 818 | ||
834 | it('Should report correct videos count', async function () { | 819 | it('Should report correct videos count', async function () { |
835 | const videoAttributes = { | 820 | const attributes = { name: 'video to test user stats' } |
836 | name: 'video to test user stats' | 821 | await server.videosCommand.upload({ token: user17AccessToken, attributes }) |
837 | } | 822 | |
838 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | 823 | const { data } = await server.videosCommand.list() |
839 | const res1 = await getVideosList(server.url) | 824 | videoId = data.find(video => video.name === attributes.name).id |
840 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | ||
841 | 825 | ||
842 | const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) | 826 | const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) |
843 | expect(user.videosCount).to.equal(1) | 827 | expect(user.videosCount).to.equal(1) |