aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/tests/api/activitypub/refresher.ts20
-rw-r--r--server/tests/api/check-params/accounts.ts15
-rw-r--r--server/tests/api/moderation/abuses.ts13
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts5
-rw-r--r--server/tests/api/server/follows.ts40
-rw-r--r--server/tests/api/users/users-multiple-servers.ts37
-rw-r--r--server/tests/api/users/users.ts20
-rw-r--r--server/tests/cli/prune-storage.ts17
-rw-r--r--server/tests/cli/update-host.ts18
-rw-r--r--server/tests/client.ts4
-rw-r--r--shared/extra-utils/index.ts8
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/users/accounts-command.ts54
-rw-r--r--shared/extra-utils/users/accounts.ts83
-rw-r--r--shared/extra-utils/users/index.ts8
15 files changed, 175 insertions, 170 deletions
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index c717f1a30..0d5452ea4 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -1,8 +1,10 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
4import { 5import {
5 cleanupTests, closeAllSequelize, 6 cleanupTests,
7 closeAllSequelize,
6 createVideoPlaylist, 8 createVideoPlaylist,
7 doubleFollow, 9 doubleFollow,
8 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -21,10 +23,8 @@ import {
21 uploadVideoAndGetId, 23 uploadVideoAndGetId,
22 wait, 24 wait,
23 waitJobs 25 waitJobs
24} from '../../../../shared/extra-utils' 26} from '@shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts' 27import { VideoPlaylistPrivacy } from '@shared/models'
26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 28
29describe('Test AP refresher', function () { 29describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = [] 30 let servers: ServerInfo[] = []
@@ -116,19 +116,21 @@ describe('Test AP refresher', function () {
116 it('Should remove a deleted actor', async function () { 116 it('Should remove a deleted actor', async function () {
117 this.timeout(60000) 117 this.timeout(60000)
118 118
119 const command = servers[0].accountsCommand
120
119 await wait(10000) 121 await wait(10000)
120 122
121 // Change actor name so the remote server returns a 404 123 // Change actor name so the remote server returns a 404
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' 124 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') 125 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
124 126
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) 127 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) 128 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
127 129
128 await waitJobs(servers) 130 await waitJobs(servers)
129 131
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) 132 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) 133 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
132 }) 134 })
133 }) 135 })
134 136
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index d1712cff6..45d440c47 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -1,15 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { HttpStatusCode } from '@shared/core-utils'
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
6import { 5import {
7 checkBadCountPagination, 6 checkBadCountPagination,
8 checkBadSortPagination, 7 checkBadSortPagination,
9 checkBadStartPagination 8 checkBadStartPagination,
10} from '../../../../shared/extra-utils/requests/check-api-params' 9 cleanupTests,
11import { getAccount } from '../../../../shared/extra-utils/users/accounts' 10 flushAndRunServer,
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 11 ServerInfo
12} from '@shared/extra-utils'
13 13
14describe('Test accounts API validators', function () { 14describe('Test accounts API validators', function () {
15 const path = '/api/v1/accounts/' 15 const path = '/api/v1/accounts/'
@@ -38,8 +38,9 @@ describe('Test accounts API validators', function () {
38 }) 38 })
39 39
40 describe('When getting an account', function () { 40 describe('When getting an account', function () {
41
41 it('Should return 404 with a non existing name', async function () { 42 it('Should return 404 with a non existing name', async function () {
42 await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) 43 await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
43 }) 44 })
44 }) 45 })
45 46
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index a9f5332ce..124833cf6 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -13,7 +13,6 @@ import {
13 doubleFollow, 13 doubleFollow,
14 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
15 generateUserAccessToken, 15 generateUserAccessToken,
16 getAccount,
17 getVideoCommentThreads, 16 getVideoCommentThreads,
18 getVideoIdFromUUID, 17 getVideoIdFromUUID,
19 getVideosList, 18 getVideosList,
@@ -606,10 +605,8 @@ describe('Test abuses', function () {
606 605
607 describe('Account abuses', function () { 606 describe('Account abuses', function () {
608 607
609 async function getAccountFromServer (url: string, name: string, server: ServerInfo) { 608 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
610 const res = await getAccount(url, name + '@' + server.host) 609 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
611
612 return res.body as Account
613 } 610 }
614 611
615 before(async function () { 612 before(async function () {
@@ -626,7 +623,7 @@ describe('Test abuses', function () {
626 it('Should report abuse on an account', async function () { 623 it('Should report abuse on an account', async function () {
627 this.timeout(15000) 624 this.timeout(15000)
628 625
629 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) 626 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
630 627
631 const reason = 'it is a bad account' 628 const reason = 'it is a bad account'
632 await commands[0].report({ accountId: account.id, reason }) 629 await commands[0].report({ accountId: account.id, reason })
@@ -664,7 +661,7 @@ describe('Test abuses', function () {
664 it('Should report abuse on a remote account', async function () { 661 it('Should report abuse on a remote account', async function () {
665 this.timeout(10000) 662 this.timeout(10000)
666 663
667 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) 664 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
668 665
669 const reason = 'it is a really bad account' 666 const reason = 'it is a really bad account'
670 await commands[0].report({ accountId: account.id, reason }) 667 await commands[0].report({ accountId: account.id, reason })
@@ -718,7 +715,7 @@ describe('Test abuses', function () {
718 it('Should keep the account abuse when deleting the account', async function () { 715 it('Should keep the account abuse when deleting the account', async function () {
719 this.timeout(10000) 716 this.timeout(10000)
720 717
721 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) 718 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
722 await removeUser(servers[1].url, account.userId, servers[1].accessToken) 719 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
723 720
724 await waitJobs(servers) 721 await waitJobs(servers)
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 3e66e7517..e90640ad6 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -22,7 +22,6 @@ import {
22 cleanupTests, 22 cleanupTests,
23 createUser, 23 createUser,
24 generateUserAccessToken, 24 generateUserAccessToken,
25 getAccount,
26 getVideoCommentThreads, 25 getVideoCommentThreads,
27 getVideoIdFromUUID, 26 getVideoIdFromUUID,
28 immutableAssign, 27 immutableAssign,
@@ -157,8 +156,8 @@ describe('Test moderation notifications', function () {
157 156
158 await waitJobs(servers) 157 await waitJobs(servers)
159 158
160 const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) 159 const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host })
161 await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) 160 await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' })
162 161
163 await waitJobs(servers) 162 await waitJobs(servers)
164 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 163 await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index c8fcca02c..466932d63 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -242,16 +242,16 @@ describe('Test follows', function () {
242 }) 242 })
243 243
244 it('Should have the correct follows counts', async function () { 244 it('Should have the correct follows counts', async function () {
245 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) 245 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
246 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 246 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
247 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) 247 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
248 248
249 // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) 249 // Server 2 and 3 does not know server 1 follow another server (there was not a refresh)
250 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 250 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
251 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 251 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
252 252
253 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) 253 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
254 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) 254 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
255 }) 255 })
256 256
257 it('Should unfollow server 3 on server 1', async function () { 257 it('Should unfollow server 3 on server 1', async function () {
@@ -283,14 +283,14 @@ describe('Test follows', function () {
283 }) 283 })
284 284
285 it('Should have the correct follows counts 2', async function () { 285 it('Should have the correct follows counts 2', async function () {
286 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) 286 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
287 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 287 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
288 288
289 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 289 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
290 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 290 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
291 291
292 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) 292 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 })
293 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) 293 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 })
294 }) 294 })
295 295
296 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { 296 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
@@ -404,15 +404,15 @@ describe('Test follows', function () {
404 }) 404 })
405 405
406 it('Should have the correct follows counts 3', async function () { 406 it('Should have the correct follows counts 3', async function () {
407 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) 407 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
408 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 408 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
409 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) 409 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
410 410
411 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 411 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
412 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 412 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
413 413
414 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) 414 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
415 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) 415 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
416 }) 416 })
417 417
418 it('Should have propagated videos', async function () { 418 it('Should have propagated videos', async function () {
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index f60c66e4b..03fbfabeb 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -1,9 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { Account } from '../../../../shared/models/actors' 4import * as chai from 'chai'
6import { 5import {
6 checkActorFilesWereRemoved,
7 checkTmpIsEmpty, 7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 cleanupTests, 9 cleanupTests,
@@ -11,17 +11,19 @@ import {
11 doubleFollow, 11 doubleFollow,
12 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
13 getAccountVideos, 13 getAccountVideos,
14 getMyUserInformation,
14 getVideoChannelsList, 15 getVideoChannelsList,
15 removeUser, 16 removeUser,
17 ServerInfo,
18 setAccessTokensToServers,
19 testImage,
20 updateMyAvatar,
16 updateMyUser, 21 updateMyUser,
17 userLogin 22 uploadVideo,
18} from '../../../../shared/extra-utils' 23 userLogin,
19import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' 24 waitJobs
20import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' 25} from '@shared/extra-utils'
21import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 26import { User, VideoChannel } from '@shared/models'
22import { User } from '../../../../shared/models/users'
23import { VideoChannel } from '../../../../shared/models/videos'
24import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25 27
26const expect = chai.expect 28const expect = chai.expect
27 29
@@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () {
133 let createdAt: string | Date 135 let createdAt: string | Date
134 136
135 for (const server of servers) { 137 for (const server of servers) {
136 const resAccounts = await getAccountsList(server.url, '-createdAt') 138 const body = await server.accountsCommand.list({ sort: '-createdAt' })
137 139
138 const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account 140 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
139 expect(resList).not.to.be.undefined 141 expect(resList).not.to.be.undefined
140 142
141 const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) 143 const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
142 const account = resAccount.body as Account
143 144
144 if (!createdAt) createdAt = account.createdAt 145 if (!createdAt) createdAt = account.createdAt
145 146
@@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () {
193 this.timeout(10_000) 194 this.timeout(10_000)
194 195
195 for (const server of servers) { 196 for (const server of servers) {
196 const resAccounts = await getAccountsList(server.url, '-createdAt') 197 const body = await server.accountsCommand.list({ sort: '-createdAt' })
197 198
198 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account 199 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
199 expect(accountDeleted).not.to.be.undefined 200 expect(accountDeleted).not.to.be.undefined
200 201
201 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) 202 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
@@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () {
210 await waitJobs(servers) 211 await waitJobs(servers)
211 212
212 for (const server of servers) { 213 for (const server of servers) {
213 const resAccounts = await getAccountsList(server.url, '-createdAt') 214 const body = await server.accountsCommand.list({ sort: '-createdAt' })
214 215
215 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account 216 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
216 expect(accountDeleted).to.be.undefined 217 expect(accountDeleted).to.be.undefined
217 218
218 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) 219 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 33bcc8701..3beea5d50 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -11,7 +11,6 @@ import {
11 createUser, 11 createUser,
12 deleteMe, 12 deleteMe,
13 flushAndRunServer, 13 flushAndRunServer,
14 getAccountRatings,
15 getBlacklistedVideosList, 14 getBlacklistedVideosList,
16 getMyUserInformation, 15 getMyUserInformation,
17 getMyUserVideoQuotaUsed, 16 getMyUserVideoQuotaUsed,
@@ -194,25 +193,22 @@ describe('Test users', function () {
194 it('Should retrieve ratings list', async function () { 193 it('Should retrieve ratings list', async function () {
195 await rateVideo(server.url, accessToken, videoId, 'like') 194 await rateVideo(server.url, accessToken, videoId, 'like')
196 195
197 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) 196 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
198 const ratings = res.body
199 197
200 expect(ratings.total).to.equal(1) 198 expect(body.total).to.equal(1)
201 expect(ratings.data[0].video.id).to.equal(videoId) 199 expect(body.data[0].video.id).to.equal(videoId)
202 expect(ratings.data[0].rating).to.equal('like') 200 expect(body.data[0].rating).to.equal('like')
203 }) 201 })
204 202
205 it('Should retrieve ratings list by rating type', async function () { 203 it('Should retrieve ratings list by rating type', async function () {
206 { 204 {
207 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') 205 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })
208 const ratings = res.body 206 expect(body.data.length).to.equal(1)
209 expect(ratings.data.length).to.equal(1)
210 } 207 }
211 208
212 { 209 {
213 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') 210 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })
214 const ratings = res.body 211 expect(body.data.length).to.equal(0)
215 expect(ratings.data.length).to.equal(0)
216 } 212 }
217 }) 213 })
218 }) 214 })
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 81f91105c..95f573e50 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -5,7 +5,7 @@ import * as chai from 'chai'
5import { createFile, readdir } from 'fs-extra' 5import { createFile, readdir } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildUUID } from '@server/helpers/uuid' 7import { buildUUID } from '@server/helpers/uuid'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 8import { HttpStatusCode } from '@shared/core-utils'
9import { 9import {
10 buildServerDirectory, 10 buildServerDirectory,
11 cleanupTests, 11 cleanupTests,
@@ -13,7 +13,6 @@ import {
13 createVideoPlaylist, 13 createVideoPlaylist,
14 doubleFollow, 14 doubleFollow,
15 flushAndRunMultipleServers, 15 flushAndRunMultipleServers,
16 getAccount,
17 killallServers, 16 killallServers,
18 makeGetRequest, 17 makeGetRequest,
19 ServerInfo, 18 ServerInfo,
@@ -21,10 +20,10 @@ import {
21 setDefaultVideoChannel, 20 setDefaultVideoChannel,
22 updateMyAvatar, 21 updateMyAvatar,
23 uploadVideo, 22 uploadVideo,
24 wait 23 wait,
25} from '../../../shared/extra-utils' 24 waitJobs
26import { waitJobs } from '../../../shared/extra-utils/server/jobs' 25} from '@shared/extra-utils'
27import { Account, VideoPlaylistPrivacy } from '../../../shared/models' 26import { VideoPlaylistPrivacy } from '@shared/models'
28 27
29const expect = chai.expect 28const expect = chai.expect
30 29
@@ -94,8 +93,7 @@ describe('Test prune storage scripts', function () {
94 93
95 // Lazy load the remote avatar 94 // Lazy load the remote avatar
96 { 95 {
97 const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port) 96 const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port })
98 const account: Account = res.body
99 await makeGetRequest({ 97 await makeGetRequest({
100 url: servers[0].url, 98 url: servers[0].url,
101 path: account.avatar.path, 99 path: account.avatar.path,
@@ -104,8 +102,7 @@ describe('Test prune storage scripts', function () {
104 } 102 }
105 103
106 { 104 {
107 const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port) 105 const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port })
108 const account: Account = res.body
109 await makeGetRequest({ 106 await makeGetRequest({
110 url: servers[1].url, 107 url: servers[1].url,
111 path: account.avatar.path, 108 path: account.avatar.path,
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index 1b1a76aef..f6131a99f 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -1,9 +1,9 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai'
5import { 4import {
6 addVideoChannel, 5 addVideoChannel,
6 addVideoCommentThread,
7 cleanupTests, 7 cleanupTests,
8 createUser, 8 createUser,
9 flushAndRunServer, 9 flushAndRunServer,
@@ -16,12 +16,10 @@ import {
16 reRunServer, 16 reRunServer,
17 ServerInfo, 17 ServerInfo,
18 setAccessTokensToServers, 18 setAccessTokensToServers,
19 uploadVideo 19 uploadVideo,
20} from '../../../shared/extra-utils' 20 waitJobs
21import { waitJobs } from '../../../shared/extra-utils/server/jobs' 21} from '@shared/extra-utils'
22import { getAccountsList } from '../../../shared/extra-utils/users/accounts' 22import { VideoDetails } from '@shared/models'
23import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
24import { VideoDetails } from '../../../shared/models/videos'
25 23
26const expect = chai.expect 24const expect = chai.expect
27 25
@@ -104,10 +102,10 @@ describe('Test update host scripts', function () {
104 }) 102 })
105 103
106 it('Should have updated accounts url', async function () { 104 it('Should have updated accounts url', async function () {
107 const res = await getAccountsList(server.url) 105 const body = await server.accountsCommand.list()
108 expect(res.body.total).to.equal(3) 106 expect(body.total).to.equal(3)
109 107
110 for (const account of res.body.data) { 108 for (const account of body.data) {
111 const usernameWithDomain = account.name 109 const usernameWithDomain = account.name
112 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) 110 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
113 111
diff --git a/server/tests/client.ts b/server/tests/client.ts
index be7ce18b4..60df878d7 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -11,7 +11,6 @@ import {
11 createVideoPlaylist, 11 createVideoPlaylist,
12 doubleFollow, 12 doubleFollow,
13 flushAndRunMultipleServers, 13 flushAndRunMultipleServers,
14 getAccount,
15 getVideosList, 14 getVideosList,
16 makeGetRequest, 15 makeGetRequest,
17 makeHTMLRequest, 16 makeHTMLRequest,
@@ -105,8 +104,7 @@ describe('Test a client controllers', function () {
105 104
106 await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' }) 105 await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })
107 106
108 const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`) 107 account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })
109 account = resAccountRequest.body
110 108
111 await waitJobs(servers) 109 await waitJobs(servers)
112 }) 110 })
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index ed7d7ab04..68900af26 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -10,17 +10,11 @@ export * from './overviews'
10export * from './search' 10export * from './search'
11export * from './server' 11export * from './server'
12export * from './socket' 12export * from './socket'
13export * from './users'
13 14
14export * from './requests/check-api-params' 15export * from './requests/check-api-params'
15export * from './requests/requests' 16export * from './requests/requests'
16 17
17export * from './users/accounts'
18export * from './users/blocklist'
19export * from './users/login'
20export * from './users/user-notifications'
21export * from './users/user-subscriptions'
22export * from './users/users'
23
24export * from './videos/live' 18export * from './videos/live'
25export * from './videos/services' 19export * from './videos/services'
26export * from './videos/video-blacklist' 20export * from './videos/video-blacklist'
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index 8bd4446be..c2cab9818 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 19import { SocketIOCommand } from '../socket'
20import { AccountsCommand } from '../users'
20import { ConfigCommand } from './config-command' 21import { ConfigCommand } from './config-command'
21import { ContactFormCommand } from './contact-form-command' 22import { ContactFormCommand } from './contact-form-command'
22import { DebugCommand } from './debug-command' 23import { DebugCommand } from './debug-command'
@@ -95,6 +96,7 @@ interface ServerInfo {
95 statsCommand?: StatsCommand 96 statsCommand?: StatsCommand
96 configCommand?: ConfigCommand 97 configCommand?: ConfigCommand
97 socketIOCommand?: SocketIOCommand 98 socketIOCommand?: SocketIOCommand
99 accountsCommand?: AccountsCommand
98} 100}
99 101
100function parallelTests () { 102function parallelTests () {
@@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
317 server.statsCommand = new StatsCommand(server) 319 server.statsCommand = new StatsCommand(server)
318 server.configCommand = new ConfigCommand(server) 320 server.configCommand = new ConfigCommand(server)
319 server.socketIOCommand = new SocketIOCommand(server) 321 server.socketIOCommand = new SocketIOCommand(server)
322 server.accountsCommand = new AccountsCommand(server)
320 323
321 res(server) 324 res(server)
322 }) 325 })
diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.ts
new file mode 100644
index 000000000..89c080e93
--- /dev/null
+++ b/shared/extra-utils/users/accounts-command.ts
@@ -0,0 +1,54 @@
1import { ResultList } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { Account } from '../../models/actors'
4import { AccountVideoRate, VideoRateType } from '../../models/videos'
5import { AbstractCommand, OverrideCommandOptions } from '../shared'
6
7export class AccountsCommand extends AbstractCommand {
8
9 list (options: OverrideCommandOptions & {
10 sort?: string // default -createdAt
11 } = {}) {
12 const { sort = '-createdAt' } = options
13 const path = '/api/v1/accounts'
14
15 return this.getRequestBody<ResultList<Account>>({
16 ...options,
17
18 path,
19 query: { sort },
20 defaultExpectedStatus: HttpStatusCode.OK_200
21 })
22 }
23
24 get (options: OverrideCommandOptions & {
25 accountName: string
26 }) {
27 const path = '/api/v1/accounts/' + options.accountName
28
29 return this.getRequestBody<Account>({
30 ...options,
31
32 path,
33 defaultExpectedStatus: HttpStatusCode.OK_200
34 })
35 }
36
37 listRatings (options: OverrideCommandOptions & {
38 accountName: string
39 rating?: VideoRateType
40 }) {
41 const { rating, accountName } = options
42 const path = '/api/v1/accounts/' + accountName + '/ratings'
43
44 const query = { rating }
45
46 return this.getRequestBody<ResultList<AccountVideoRate>>({
47 ...options,
48
49 path,
50 query,
51 defaultExpectedStatus: HttpStatusCode.OK_200
52 })
53 }
54}
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts
index 4ea7f1402..ee94351e8 100644
--- a/shared/extra-utils/users/accounts.ts
+++ b/shared/extra-utils/users/accounts.ts
@@ -1,43 +1,25 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as request from 'supertest'
4import { expect } from 'chai' 3import { expect } from 'chai'
5import { existsSync, readdir } from 'fs-extra' 4import { pathExists, readdir } from 'fs-extra'
6import { join } from 'path' 5import { join } from 'path'
7import { Account } from '../../models/actors' 6import { root } from '@server/helpers/core-utils'
8import { root } from '../miscs/miscs' 7import { ServerInfo } from '../server'
9import { makeGetRequest } from '../requests/requests' 8
10import { VideoRateType } from '../../models/videos' 9async function expectAccountFollows (options: {
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 10 server: ServerInfo
12 11 handle: string
13function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { 12 followers: number
14 const path = '/api/v1/accounts' 13 following: number
15 14}) {
16 return makeGetRequest({ 15 const { server, handle, followers, following } = options
17 url, 16
18 query: { sort }, 17 const body = await server.accountsCommand.list()
19 path, 18 const account = body.data.find(a => a.name + '@' + a.host === handle)
20 statusCodeExpected 19
21 }) 20 const message = `${handle} on ${server.url}`
22} 21 expect(account.followersCount).to.equal(followers, message)
23 22 expect(account.followingCount).to.equal(following, message)
24function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) {
25 const path = '/api/v1/accounts/' + accountName
26
27 return makeGetRequest({
28 url,
29 path,
30 statusCodeExpected
31 })
32}
33
34async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {
35 const res = await getAccountsList(url)
36 const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)
37
38 const message = `${nameWithDomain} on ${url}`
39 expect(account.followersCount).to.equal(followersCount, message)
40 expect(account.followingCount).to.equal(followingCount, message)
41} 23}
42 24
43async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { 25async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {
@@ -46,7 +28,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
46 for (const directory of [ 'avatars' ]) { 28 for (const directory of [ 'avatars' ]) {
47 const directoryPath = join(root(), testDirectory, directory) 29 const directoryPath = join(root(), testDirectory, directory)
48 30
49 const directoryExists = existsSync(directoryPath) 31 const directoryExists = await pathExists(directoryPath)
50 expect(directoryExists).to.be.true 32 expect(directoryExists).to.be.true
51 33
52 const files = await readdir(directoryPath) 34 const files = await readdir(directoryPath)
@@ -56,32 +38,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe
56 } 38 }
57} 39}
58 40
59function getAccountRatings (
60 url: string,
61 accountName: string,
62 accessToken: string,
63 rating?: VideoRateType,
64 statusCodeExpected = HttpStatusCode.OK_200
65) {
66 const path = '/api/v1/accounts/' + accountName + '/ratings'
67
68 const query = rating ? { rating } : {}
69
70 return request(url)
71 .get(path)
72 .query(query)
73 .set('Accept', 'application/json')
74 .set('Authorization', 'Bearer ' + accessToken)
75 .expect(statusCodeExpected)
76 .expect('Content-Type', /json/)
77}
78
79// ---------------------------------------------------------------------------
80
81export { 41export {
82 getAccount,
83 expectAccountFollows, 42 expectAccountFollows,
84 getAccountsList, 43 checkActorFilesWereRemoved
85 checkActorFilesWereRemoved,
86 getAccountRatings
87} 44}
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts
new file mode 100644
index 000000000..b3387ed8a
--- /dev/null
+++ b/shared/extra-utils/users/index.ts
@@ -0,0 +1,8 @@
1export * from './accounts'
2export * from './accounts-command'
3
4export * from './blocklist'
5export * from './login'
6export * from './user-notifications'
7export * from './user-subscriptions'
8export * from './users'