ActivityPub-federated video streaming platform using P2P directly in your web browser
Introduce accounts command
Chocobozzz9fff08cf83f3
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.tsindex c717f1a307..0d5452ea43 100644--- a/server/tests/api/activitypub/refresher.ts+++ b/server/tests/api/activitypub/refresher.ts@@ -1,8 +1,10 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'+import { HttpStatusCode } from '@shared/core-utils'import {- cleanupTests, closeAllSequelize,+ cleanupTests,+ closeAllSequelize,createVideoPlaylist,doubleFollow,flushAndRunMultipleServers,@@ -21,10 +23,8 @@ import {uploadVideoAndGetId,wait,waitJobs-} from '../../../../shared/extra-utils'-import { getAccount } from '../../../../shared/extra-utils/users/accounts'-import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'+} from '@shared/extra-utils'+import { VideoPlaylistPrivacy } from '@shared/models'describe('Test AP refresher', function () {let servers: ServerInfo[] = []@@ -116,19 +116,21 @@ describe('Test AP refresher', function () {it('Should remove a deleted actor', async function () {this.timeout(60000)+ const command = servers[0].accountsCommand+await wait(10000)// Change actor name so the remote server returns a 404const to = 'http://localhost:' + servers[1].port + '/accounts/user2'await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')- await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port)- await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port)+ await command.get({ accountName: 'user1@localhost:' + servers[1].port })+ await command.get({ accountName: 'user2@localhost:' + servers[1].port })await waitJobs(servers)- await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200)- await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404)+ await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })+ await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })})})diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.tsindex d1712cff61..45d440c477 100644--- a/server/tests/api/check-params/accounts.ts+++ b/server/tests/api/check-params/accounts.ts@@ -1,15 +1,15 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'--import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'+import { HttpStatusCode } from '@shared/core-utils'import {checkBadCountPagination,checkBadSortPagination,- checkBadStartPagination-} from '../../../../shared/extra-utils/requests/check-api-params'-import { getAccount } from '../../../../shared/extra-utils/users/accounts'-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'+ checkBadStartPagination,+ cleanupTests,+ flushAndRunServer,+ ServerInfo+} from '@shared/extra-utils'describe('Test accounts API validators', function () {const path = '/api/v1/accounts/'@@ -38,8 +38,9 @@ describe('Test accounts API validators', function () {})describe('When getting an account', function () {+it('Should return 404 with a non existing name', async function () {- await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404)+ await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 })})})diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.tsindex a9f5332ce7..124833cf60 100644--- a/server/tests/api/moderation/abuses.ts+++ b/server/tests/api/moderation/abuses.ts@@ -13,7 +13,6 @@ import {doubleFollow,flushAndRunMultipleServers,generateUserAccessToken,- getAccount,getVideoCommentThreads,getVideoIdFromUUID,getVideosList,@@ -606,10 +605,8 @@ describe('Test abuses', function () {describe('Account abuses', function () {- async function getAccountFromServer (url: string, name: string, server: ServerInfo) {- const res = await getAccount(url, name + '@' + server.host)-- return res.body as Account+ function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {+ return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })}before(async function () {@@ -626,7 +623,7 @@ describe('Test abuses', function () {it('Should report abuse on an account', async function () {this.timeout(15000)- const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])+ const account = await getAccountFromServer(servers[0], 'user_1', servers[0])const reason = 'it is a bad account'await commands[0].report({ accountId: account.id, reason })@@ -664,7 +661,7 @@ describe('Test abuses', function () {it('Should report abuse on a remote account', async function () {this.timeout(10000)- const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])+ const account = await getAccountFromServer(servers[0], 'user_2', servers[1])const reason = 'it is a really bad account'await commands[0].report({ accountId: account.id, reason })@@ -718,7 +715,7 @@ describe('Test abuses', function () {it('Should keep the account abuse when deleting the account', async function () {this.timeout(10000)- const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1])+ const account = await getAccountFromServer(servers[1], 'user_2', servers[1])await removeUser(servers[1].url, account.userId, servers[1].accessToken)await waitJobs(servers)diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.tsindex 3e66e7517e..e90640ad65 100644--- a/server/tests/api/notifications/moderation-notifications.ts+++ b/server/tests/api/notifications/moderation-notifications.ts@@ -22,7 +22,6 @@ import {cleanupTests,createUser,generateUserAccessToken,- getAccount,getVideoCommentThreads,getVideoIdFromUUID,immutableAssign,@@ -157,8 +156,8 @@ describe('Test moderation notifications', function () {await waitJobs(servers)- const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host)- await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' })+ const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host })+ await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' })await waitJobs(servers)await checkNewAccountAbuseForModerators(baseParams, username, 'presence')diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.tsindex c8fcca02cd..466932d631 100644--- a/server/tests/api/server/follows.ts+++ b/server/tests/api/server/follows.ts@@ -242,16 +242,16 @@ describe('Test follows', function () {})it('Should have the correct follows counts', async function () {- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2)- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0)- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0)+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })// Server 2 and 3 does not know server 1 follow another server (there was not a refresh)- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0)+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0)+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })})it('Should unfollow server 3 on server 1', async function () {@@ -283,14 +283,14 @@ describe('Test follows', function () {})it('Should have the correct follows counts 2', async function () {- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0)+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0)+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0)- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0)+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 })+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 })})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 () {})it('Should have the correct follows counts 3', async function () {- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2)- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0)- await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0)+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })+ await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0)+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1)- await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0)+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })+ await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })})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.tsindex f60c66e4bd..03fbfabebd 100644--- a/server/tests/api/users/users-multiple-servers.ts+++ b/server/tests/api/users/users-multiple-servers.ts@@ -1,9 +1,9 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import * as chai from 'chai'import 'mocha'-import { Account } from '../../../../shared/models/actors'+import * as chai from 'chai'import {+ checkActorFilesWereRemoved,checkTmpIsEmpty,checkVideoFilesWereRemoved,cleanupTests,@@ -11,17 +11,19 @@ import {doubleFollow,flushAndRunMultipleServers,getAccountVideos,+ getMyUserInformation,getVideoChannelsList,removeUser,+ ServerInfo,+ setAccessTokensToServers,+ testImage,+ updateMyAvatar,updateMyUser,- userLogin-} from '../../../../shared/extra-utils'-import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index'-import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts'-import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'-import { User } from '../../../../shared/models/users'-import { VideoChannel } from '../../../../shared/models/videos'-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'+ uploadVideo,+ userLogin,+ waitJobs+} from '@shared/extra-utils'+import { User, VideoChannel } from '@shared/models'const expect = chai.expect@@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () {let createdAt: string | Datefor (const server of servers) {- const resAccounts = await getAccountsList(server.url, '-createdAt')+ const body = await server.accountsCommand.list({ sort: '-createdAt' })- const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account+ const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)expect(resList).not.to.be.undefined- const resAccount = await getAccount(server.url, resList.name + '@' + resList.host)- const account = resAccount.body as Account+ const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })if (!createdAt) createdAt = account.createdAt@@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () {this.timeout(10_000)for (const server of servers) {- const resAccounts = await getAccountsList(server.url, '-createdAt')+ const body = await server.accountsCommand.list({ sort: '-createdAt' })- const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account+ const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)expect(accountDeleted).not.to.be.undefinedconst resVideoChannels = await getVideoChannelsList(server.url, 0, 10)@@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () {await waitJobs(servers)for (const server of servers) {- const resAccounts = await getAccountsList(server.url, '-createdAt')+ const body = await server.accountsCommand.list({ sort: '-createdAt' })- const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account+ const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)expect(accountDeleted).to.be.undefinedconst resVideoChannels = await getVideoChannelsList(server.url, 0, 10)diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.tsindex 33bcc8701e..3beea5d501 100644--- a/server/tests/api/users/users.ts+++ b/server/tests/api/users/users.ts@@ -11,7 +11,6 @@ import {createUser,deleteMe,flushAndRunServer,- getAccountRatings,getBlacklistedVideosList,getMyUserInformation,getMyUserVideoQuotaUsed,@@ -194,25 +193,22 @@ describe('Test users', function () {it('Should retrieve ratings list', async function () {await rateVideo(server.url, accessToken, videoId, 'like')- const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)- const ratings = res.body+ const body = await server.accountsCommand.listRatings({ accountName: server.user.username })- expect(ratings.total).to.equal(1)- expect(ratings.data[0].video.id).to.equal(videoId)- expect(ratings.data[0].rating).to.equal('like')+ expect(body.total).to.equal(1)+ expect(body.data[0].video.id).to.equal(videoId)+ expect(body.data[0].rating).to.equal('like')})it('Should retrieve ratings list by rating type', async function () {{- const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')- const ratings = res.body- expect(ratings.data.length).to.equal(1)+ const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })+ expect(body.data.length).to.equal(1)}{- const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')- const ratings = res.body- expect(ratings.data.length).to.equal(0)+ const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })+ expect(body.data.length).to.equal(0)}})})diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.tsindex 81f91105c7..95f573e504 100644--- a/server/tests/cli/prune-storage.ts+++ b/server/tests/cli/prune-storage.ts@@ -5,7 +5,7 @@ import * as chai from 'chai'import { createFile, readdir } from 'fs-extra'import { join } from 'path'import { buildUUID } from '@server/helpers/uuid'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'+import { HttpStatusCode } from '@shared/core-utils'import {buildServerDirectory,cleanupTests,@@ -13,7 +13,6 @@ import {createVideoPlaylist,doubleFollow,flushAndRunMultipleServers,- getAccount,killallServers,makeGetRequest,ServerInfo,@@ -21,10 +20,10 @@ import {setDefaultVideoChannel,updateMyAvatar,uploadVideo,- wait-} from '../../../shared/extra-utils'-import { waitJobs } from '../../../shared/extra-utils/server/jobs'-import { Account, VideoPlaylistPrivacy } from '../../../shared/models'+ wait,+ waitJobs+} from '@shared/extra-utils'+import { VideoPlaylistPrivacy } from '@shared/models'const expect = chai.expect@@ -94,8 +93,7 @@ describe('Test prune storage scripts', function () {// Lazy load the remote avatar{- const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port)- const account: Account = res.body+ const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port })await makeGetRequest({url: servers[0].url,path: account.avatar.path,@@ -104,8 +102,7 @@ describe('Test prune storage scripts', function () {}{- const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port)- const account: Account = res.body+ const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port })await makeGetRequest({url: servers[1].url,path: account.avatar.path,diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.tsindex 1b1a76aef6..f6131a99f0 100644--- a/server/tests/cli/update-host.ts+++ b/server/tests/cli/update-host.ts@@ -1,9 +1,9 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */import 'mocha'-import * as chai from 'chai'import {addVideoChannel,+ addVideoCommentThread,cleanupTests,createUser,flushAndRunServer,@@ -16,12 +16,10 @@ import {reRunServer,ServerInfo,setAccessTokensToServers,- uploadVideo-} from '../../../shared/extra-utils'-import { waitJobs } from '../../../shared/extra-utils/server/jobs'-import { getAccountsList } from '../../../shared/extra-utils/users/accounts'-import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'-import { VideoDetails } from '../../../shared/models/videos'+ uploadVideo,+ waitJobs+} from '@shared/extra-utils'+import { VideoDetails } from '@shared/models'const expect = chai.expect@@ -104,10 +102,10 @@ describe('Test update host scripts', function () {})it('Should have updated accounts url', async function () {- const res = await getAccountsList(server.url)- expect(res.body.total).to.equal(3)+ const body = await server.accountsCommand.list()+ expect(body.total).to.equal(3)- for (const account of res.body.data) {+ for (const account of body.data) {const usernameWithDomain = account.nameconst { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)diff --git a/server/tests/client.ts b/server/tests/client.tsindex be7ce18b4b..60df878d7f 100644--- a/server/tests/client.ts+++ b/server/tests/client.ts@@ -11,7 +11,6 @@ import {createVideoPlaylist,doubleFollow,flushAndRunMultipleServers,- getAccount,getVideosList,makeGetRequest,makeHTMLRequest,@@ -105,8 +104,7 @@ describe('Test a client controllers', function () {await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' })- const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`)- account = resAccountRequest.body+ account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` })await waitJobs(servers)})diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.tsindex ed7d7ab04d..68900af264 100644--- a/shared/extra-utils/index.ts+++ b/shared/extra-utils/index.ts@@ -10,17 +10,11 @@ export * from './overviews'export * from './search'export * from './server'export * from './socket'+export * from './users'export * from './requests/check-api-params'export * from './requests/requests'-export * from './users/accounts'-export * from './users/blocklist'-export * from './users/login'-export * from './users/user-notifications'-export * from './users/user-subscriptions'-export * from './users/users'-export * from './videos/live'export * from './videos/services'export * from './videos/video-blacklist'diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.tsindex 8bd4446be1..c2cab98182 100644--- a/shared/extra-utils/server/servers.ts+++ b/shared/extra-utils/server/servers.ts@@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews'import { makeGetRequest } from '../requests/requests'import { SearchCommand } from '../search'import { SocketIOCommand } from '../socket'+import { AccountsCommand } from '../users'import { ConfigCommand } from './config-command'import { ContactFormCommand } from './contact-form-command'import { DebugCommand } from './debug-command'@@ -95,6 +96,7 @@ interface ServerInfo {statsCommand?: StatsCommandconfigCommand?: ConfigCommandsocketIOCommand?: SocketIOCommand+ accountsCommand?: AccountsCommand}function parallelTests () {@@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []server.statsCommand = new StatsCommand(server)server.configCommand = new ConfigCommand(server)server.socketIOCommand = new SocketIOCommand(server)+ server.accountsCommand = new AccountsCommand(server)res(server)})diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.tsnew file mode 100644index 0000000000..89c080e933--- /dev/null+++ b/shared/extra-utils/users/accounts-command.ts@@ -0,0 +1,54 @@+import { ResultList } from '@shared/models'+import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'+import { Account } from '../../models/actors'+import { AccountVideoRate, VideoRateType } from '../../models/videos'+import { AbstractCommand, OverrideCommandOptions } from '../shared'++export class AccountsCommand extends AbstractCommand {++ list (options: OverrideCommandOptions & {+ sort?: string // default -createdAt+ } = {}) {+ const { sort = '-createdAt' } = options+ const path = '/api/v1/accounts'++ return this.getRequestBody<ResultList<Account>>({+ ...options,++ path,+ query: { sort },+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ get (options: OverrideCommandOptions & {+ accountName: string+ }) {+ const path = '/api/v1/accounts/' + options.accountName++ return this.getRequestBody<Account>({+ ...options,++ path,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }++ listRatings (options: OverrideCommandOptions & {+ accountName: string+ rating?: VideoRateType+ }) {+ const { rating, accountName } = options+ const path = '/api/v1/accounts/' + accountName + '/ratings'++ const query = { rating }++ return this.getRequestBody<ResultList<AccountVideoRate>>({+ ...options,++ path,+ query,+ defaultExpectedStatus: HttpStatusCode.OK_200+ })+ }+}diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.tsindex 4ea7f1402c..ee94351e8d 100644--- a/shared/extra-utils/users/accounts.ts+++ b/shared/extra-utils/users/accounts.ts@@ -1,43 +1,25 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */-import * as request from 'supertest'import { expect } from 'chai'-import { existsSync, readdir } from 'fs-extra'+import { pathExists, readdir } from 'fs-extra'import { join } from 'path'-import { Account } from '../../models/actors'-import { root } from '../miscs/miscs'-import { makeGetRequest } from '../requests/requests'-import { VideoRateType } from '../../models/videos'-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'--function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) {- const path = '/api/v1/accounts'-- return makeGetRequest({- url,- query: { sort },- path,- statusCodeExpected- })-}--function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) {- const path = '/api/v1/accounts/' + accountName-- return makeGetRequest({- url,- path,- statusCodeExpected- })-}--async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) {- const res = await getAccountsList(url)- const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain)-- const message = `${nameWithDomain} on ${url}`- expect(account.followersCount).to.equal(followersCount, message)- expect(account.followingCount).to.equal(followingCount, message)+import { root } from '@server/helpers/core-utils'+import { ServerInfo } from '../server'++async function expectAccountFollows (options: {+ server: ServerInfo+ handle: string+ followers: number+ following: number+}) {+ const { server, handle, followers, following } = options++ const body = await server.accountsCommand.list()+ const account = body.data.find(a => a.name + '@' + a.host === handle)++ const message = `${handle} on ${server.url}`+ expect(account.followersCount).to.equal(followers, message)+ expect(account.followingCount).to.equal(following, message)}async function checkActorFilesWereRemoved (filename: string, serverNumber: number) {@@ -46,7 +28,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbefor (const directory of [ 'avatars' ]) {const directoryPath = join(root(), testDirectory, directory)- const directoryExists = existsSync(directoryPath)+ const directoryExists = await pathExists(directoryPath)expect(directoryExists).to.be.trueconst files = await readdir(directoryPath)@@ -56,32 +38,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe}}-function getAccountRatings (- url: string,- accountName: string,- accessToken: string,- rating?: VideoRateType,- statusCodeExpected = HttpStatusCode.OK_200-) {- const path = '/api/v1/accounts/' + accountName + '/ratings'-- const query = rating ? { rating } : {}-- return request(url)- .get(path)- .query(query)- .set('Accept', 'application/json')- .set('Authorization', 'Bearer ' + accessToken)- .expect(statusCodeExpected)- .expect('Content-Type', /json/)-}--// ----------------------------------------------------------------------------export {- getAccount,expectAccountFollows,- getAccountsList,- checkActorFilesWereRemoved,- getAccountRatings+ checkActorFilesWereRemoved}diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.tsnew file mode 100644index 0000000000..b3387ed8a3--- /dev/null+++ b/shared/extra-utils/users/index.ts@@ -0,0 +1,8 @@+export * from './accounts'+export * from './accounts-command'++export * from './blocklist'+export * from './login'+export * from './user-notifications'+export * from './user-subscriptions'+export * from './users'